Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/BannerBase to TS #20421

Merged
merged 15 commits into from
Aug 18, 2023
Merged

fix/BannerBase to TS #20421

merged 15 commits into from
Aug 18, 2023

Conversation

dhruvv173
Copy link
Contributor

Explanation

Screenshots/Screencaps

Before

before.mp4

After

after.mp4

image

Manual Testing Steps

  • Run yarn storybook on this branch
  • Check controls for BannerBase
  • yarn jest ui/components/ocmponent-library/banner-base

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@dhruvv173 dhruvv173 requested a review from a team as a code owner August 7, 2023 14:20
@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link

@Ameralameri Ameralameri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Merging #20421 (9c8e160) into develop (88212a7) will decrease coverage by 0.00%.
Report is 11 commits behind head on develop.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop   #20421      +/-   ##
===========================================
- Coverage    68.68%   68.68%   -0.00%     
===========================================
  Files          991      991              
  Lines        38451    38452       +1     
  Branches     10329    10330       +1     
===========================================
- Hits         26409    26408       -1     
- Misses       12042    12044       +2     
Files Changed Coverage Δ
...pages/swaps/prepare-swap-page/prepare-swap-page.js 69.35% <ø> (ø)
ui/pages/swaps/prepare-swap-page/review-quote.js 68.97% <ø> (ø)
...s/prepare-swap-page/view-quote-price-difference.js 100.00% <ø> (ø)
...ges/swaps/swaps-banner-alert/swaps-banner-alert.js 87.27% <ø> (ø)
...swaps/transaction-settings/transaction-settings.js 79.83% <ø> (ø)
...ents/component-library/banner-base/banner-base.tsx 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@georgewrmarshall georgewrmarshall added the team-design-system All issues relating to design system in Extension label Aug 10, 2023
Comment on lines +16 to +18
type MakePropsOptional<T> = {
[K in keyof T]?: T[K];
};
Copy link
Contributor

@georgewrmarshall georgewrmarshall Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type helper allows for us to use prop objects without needing to pass all required props through the prop object. @brad-decker do you have any suggestions on where a type like this should live? Should we create a types.ts file in the root of the ui/components/component-library/types.ts or maybe in shared/constants/component-library.ts?

typescript.after.mov

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* TypeScript is complaining about data- attributes which means we need to explicitly define this as a prop.
* TODO: Allow data- attributes.
*/
'data-testid'?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary fix to allow data-testids being passed to prop objects which is generally what they will be used for

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I made some small updates based on your suggestions while I had your branch checked out. Thanks for your contribution @dhruvv173

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dhruvv173, this PR should fix the linting error #20448 and looks like I missed some snapshots or they were updated in the last merge from develop. I was also thinking that because I added the childrenWrapperProps we should write a unit test for that. There should be some examples of this with titleProps in the unit tests. Would you mind updating it?

@dhruvv173
Copy link
Contributor Author

Hey @dhruvv173, this PR should fix the linting error #20448 and looks like I missed some snapshots or they were updated in the last merge from develop. I was also thinking that because I added the childrenWrapperProps we should write a unit test for that. There should be some examples of this with titleProps in the unit tests. Would you mind updating it?

I have updated the snapshot locally and lint error will be fixed once your PR is merged. About the latter part, I just want to confirm that we want to add a unit test which checks for childrenWrapperProps in the component, right? If yes, I will check for examples in unit tests and work on it. Thank you!

@georgewrmarshall
Copy link
Contributor

georgewrmarshall commented Aug 15, 2023

Hey @dhruvv173, this PR should fix the linting error #20448 and looks like I missed some snapshots or they were updated in the last merge from develop. I was also thinking that because I added the childrenWrapperProps we should write a unit test for that. There should be some examples of this with titleProps in the unit tests. Would you mind updating it?

I have updated the snapshot locally and lint error will be fixed once your PR is merged. About the latter part, I just want to confirm that we want to add a unit test which checks for childrenWrapperProps in the component, right? If yes, I will check for examples in unit tests and work on it. Thank you!

Yes, that's correct! I noticed that we aren't actually testing for titleProps or descriptionProps we can improve the coverage by adjusting each unit test for these props slightly

it('should render bannerbase title', () => {
  const { getByText, getByTestId } = render(
    <BannerBase
      title="Bannerbase title test"
      titleProps={{ 'data-testid': 'title' }}
    />,
  );
 
  expect(getByText('Bannerbase title test')).toHaveClass('mm-banner-base__title');
  expect(getByTestId('title')).toBeDefined();
});;

Changing this element to a tag: 'p' instead of h5 tag should also help with the e2e tests

@dhruvv173
Copy link
Contributor Author

hi @georgewrmarshall, what do think about something like this?

  it('should render bannerbase children with props', () => {
    const { getByText, getByTestId } = render(
      <BannerBase
        childrenWrapperProps={{
          variant: TextVariant.bodyMd,
          'data-testid': 'childrenWrapper',
        }}
      >
        Bannerbase children test
      </BannerBase>,
    );
    expect(getByTestId('childrenWrapper')).toBeDefined();
    expect(getByText('Bannerbase children test')).toBeDefined();
  });

@dhruvv173 dhruvv173 mentioned this pull request Aug 16, 2023
8 tasks
@georgewrmarshall
Copy link
Contributor

hi @georgewrmarshall, what do think about something like this?

  it('should render bannerbase children with props', () => {
    const { getByText, getByTestId } = render(
      <BannerBase
        childrenWrapperProps={{
          variant: TextVariant.bodyMd,
          'data-testid': 'childrenWrapper',
        }}
      >
        Bannerbase children test
      </BannerBase>,
    );
    expect(getByTestId('childrenWrapper')).toBeDefined();
    expect(getByText('Bannerbase children test')).toBeDefined();
  });

Looks good!

@dhruvv173
Copy link
Contributor Author

Hey @dhruvv173, this PR should fix the linting error #20448 and looks like I missed some snapshots or they were updated in the last merge from develop. I was also thinking that because I added the childrenWrapperProps we should write a unit test for that. There should be some examples of this with titleProps in the unit tests. Would you mind updating it?

I have updated the snapshot locally and lint error will be fixed once your PR is merged. About the latter part, I just want to confirm that we want to add a unit test which checks for childrenWrapperProps in the component, right? If yes, I will check for examples in unit tests and work on it. Thank you!

Yes, that's correct! I noticed that we aren't actually testing for titleProps or descriptionProps we can improve the coverage by adjusting each unit test for these props slightly

it('should render bannerbase title', () => {
  const { getByText, getByTestId } = render(
    <BannerBase
      title="Bannerbase title test"
      titleProps={{ 'data-testid': 'title' }}
    />,
  );
 
  expect(getByText('Bannerbase title test')).toHaveClass('mm-banner-base__title');
  expect(getByTestId('title')).toBeDefined();
});;

Changing this element to a tag: 'p' instead of h5 tag should also help with the e2e tests

every instance of h5 should be replaced with p, right?

@dhruvv173
Copy link
Contributor Author

Looks good!

added here please check when possible, thank you!

…ng static data-testid in favor of using it at the instance, updating snapshots associated with those changes
@@ -157,7 +157,7 @@ const checkActivityTransaction = async (driver, options) => {

const checkNotification = async (driver, options) => {
const boxTitle = await driver.findElement(
'[data-testid="mm-banner-base-title"]',
'[data-testid="swap-token-verification-banner-title"]',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the static data-testid that was added to the component in favor of using descriptionProps and making the test id more specific"

{children && typeof children === 'object' ? (
children
) : (
<Text {...childrenWrapperProps}>{children}</Text>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adds childrenWrapperProps here


<div>
{title && (
<Text variant={TextVariant.bodyLgMedium} {...titleProps}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes static data-testid from title to enable specificity of test id during implementation

@@ -1036,6 +1036,9 @@ export default function PrepareSwapPage({
? t('swapTokenVerifiedOn1SourceTitle')
: t('swapTokenAddedManuallyTitle')
}
titleProps={{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are removing the static data-testid from the BannerBase component and utilizing titleProps to assign one at implementation

children: {
control: 'text',
},
childrenProps: {
control: 'object',
},
action: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be here remove

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I made some small updates to tests and updated the component to remove the static test id and a class name that I don't think we needed. Just need tests to pass. Thanks for your contribution @dhruvv173

Copy link
Contributor

@garrettbear garrettbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM. Just looks like we need to sort out some e2e tests that are failing

…se. Also updating snapshot of ConfirmTransaction page
garrettbear
garrettbear previously approved these changes Aug 17, 2023
@georgewrmarshall georgewrmarshall dismissed stale reviews from garrettbear and themself via 9c8e160 August 18, 2023 20:53
@garrettbear garrettbear merged commit 07abc53 into MetaMask:develop Aug 18, 2023
9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2023
@dhruvv173 dhruvv173 deleted the fix/19181 branch August 19, 2023 05:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external-contributor team-design-system All issues relating to design system in Extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate components to TS: BannerBase
4 participants