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(switch): convert tests to RTL - FE-6634 #6965

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

DipperTheDan
Copy link
Contributor

Proposed behaviour

Unit tests should use RTL

Current behaviour

Unit tests use 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

N/A

Testing instructions

N/A

@Parsium Parsium self-requested a review September 19, 2024 08:40
Copy link
Contributor

@Parsium Parsium left a comment

Choose a reason for hiding this comment

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

Nice work on this @DipperTheDan! 👍🏼 Just so you are aware it appears the old switch.spec.tsx file still exists after these changes. Would you be able to remove it please?

src/components/switch/switch.test.tsx Outdated Show resolved Hide resolved
src/components/switch/switch.test.tsx Outdated Show resolved Hide resolved
src/components/switch/switch.test.tsx Outdated Show resolved Hide resolved
Parsium
Parsium previously approved these changes Sep 20, 2024
},
}}
>
<Switch checked onChange={jest.fn()} />
Copy link
Contributor

Choose a reason for hiding this comment

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

nit-pick: not sure if this was missed but we could also just use a no-op function here

Suggested change
<Switch checked onChange={jest.fn()} />
<Switch checked onChange={() => {}} />

},
}}
>
<Switch onChange={jest.fn()} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Suggested change
<Switch onChange={jest.fn()} />
<Switch onChange={() => {}} />

expect(hintTextWrapper).toHaveStyleRule("margin-bottom: var(--spacing000)");
});

test("the expected translations are correctly applied", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit-pick (non-blocking): think we could add a bit more detail to more easily differentiate this test from the next

Suggested change
test("the expected translations are correctly applied", () => {
test("the expected translations are correctly applied for on", () => {

expect(i18nText[0]).toBeVisible();
});

it("can use i18n for off", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit-pick (non-blocking): and also amend this description for consistency

Suggested change
it("can use i18n for off", () => {
test("the expected translations are correctly applied for off", () => {

Comment on lines 357 to 365
test("renders the expected hint text when `labelHelp` is a string value", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch label="foo" labelHelp="hint text" warning="this is a warning" />
</CarbonProvider>
);

expect(screen.getByTestId("hint-text")).toBeVisible();
});
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): Aware that this is for coverage so happy for this to be left as it is however, I think we could slightly amend the description to make it a bit more clear what is being tested. I also think we could also just assert that the text is visible instead of using the test-id here

Suggested change
test("renders the expected hint text when `labelHelp` is a string value", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch label="foo" labelHelp="hint text" warning="this is a warning" />
</CarbonProvider>
);
expect(screen.getByTestId("hint-text")).toBeVisible();
});
test("renders `labelHelp` as hint text when `validationRedesignOptIn` flag is true", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch label="foo" labelHelp="hint text" warning="this is a warning" />
</CarbonProvider>
);
expect(screen.getByText("hint text")).toBeVisible();
});

@Parsium Parsium marked this pull request as ready for review September 24, 2024 12:25
@Parsium Parsium requested a review from a team as a code owner September 24, 2024 12:25
@DipperTheDan DipperTheDan merged commit 83a5478 into master Sep 24, 2024
24 checks passed
@DipperTheDan DipperTheDan deleted the FE-6634_switch-to-RTL branch September 24, 2024 12:58
@carbonci
Copy link
Collaborator

🎉 This PR is included in version 142.11.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