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

refactor(radio-button, radio-button-group): convert enzyme tests to RTL #6848

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

nuria1110
Copy link
Contributor

Proposed behaviour

Convert tests to RTL

Current behaviour

Tests are in enzyme

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Screenshots are included in the PR if useful
  • All themes are supported if required
  • Unit tests added or updated if required
  • Playwright automation tests added or updated if required
  • Storybook added or updated if required
  • Translations added or updated (including creating or amending translation keys table in storybook) if required
  • Typescript d.ts file added or updated if required
  • Related docs have been updated if required

QA

  • Tested in provided StackBlitz sandbox/Storybook
  • Add new Playwright test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Additional context

Testing instructions

</RadioButtonGroup>
);

const fieldset = screen.getByRole("group", { name: "Radio Group Legend" });
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: great job checking the ARIA roles! Your method of targeting elements mirrors how an assistive technology user would inspect the page 👍🏼

"Uncontrolled behaviour in `Radio Button` is deprecated and support will soon be removed. Please make sure all your inputs are controlled."
);
expect(loggerSpy).toHaveBeenCalledTimes(1);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: restoring the logger's original behavior should prevent the console from being accidentally masked in other tests:

Suggested change
});
loggerSpy.mockRestore();
});

@robinzigmond robinzigmond self-requested a review July 23, 2024 14:44
Copy link
Contributor

@robinzigmond robinzigmond left a comment

Choose a reason for hiding this comment

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

Really good job - just some very minor comments to add to those of @Parsium

<RadioButton value="radio1" label="Radio Button 1" onFocus={onFocus} />
);

await user.tab();
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (non-blocking): I'd prefer in these focus/blur tests to explicitly fetch a particular element to call .focus() (and then tab/click as necessary for the rest of the test) - this ensures we're focusing/blurring the correct thing and avoids any future test flakiness if we later introduce other tab stops etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The focus method seems to call the actual HTML focus() method but this isn't getting flagged by the linter (issue raised here). I do agree that using tab() might be a bit flakey, though I think using click() should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I wasn't aware there was any recommendation against using .focus() on an HTML element, I thought this was what you needed to do to ensure a particular element was focused at the start of a test (I agree that once into the actual sequence of steps you're testing you should do "user things" like click/tab). I've done it myself in plenty of RTL tests recently and never been suggested not to 😂

@nuria1110 nuria1110 force-pushed the FE-6627-radio-RTL branch from e9b1840 to 911654b Compare July 24, 2024 13:23
@nuria1110 nuria1110 marked this pull request as ready for review July 24, 2024 13:28
@nuria1110 nuria1110 requested a review from a team as a code owner July 24, 2024 13:28
@nuria1110 nuria1110 merged commit c63985f into master Jul 24, 2024
22 checks passed
@nuria1110 nuria1110 deleted the FE-6627-radio-RTL branch July 24, 2024 13:37
@carbonci
Copy link
Collaborator

🎉 This PR is included in version 141.0.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants