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(label): convert enzyme tests to RTL #6936

Merged
merged 3 commits into from
Sep 10, 2024
Merged

Conversation

nuria1110
Copy link
Contributor

Proposed behaviour

Convert tests to RTL
Remove unreachable branch

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

expect(screen.getByText("foo")).toHaveAttribute("id", "baz");
});

test("renders with provided `aria-label`", () => {
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): how about this small wording tweak to better describe both the intended behaviour and the specific prop being tested?

Suggested change
test("renders with provided `aria-label`", () => {
test("uses `aria-label` prop as its accessible name when passed", () => {

Comment on lines 133 to 147
const user = userEvent.setup();
const useFloatingSpy = jest.spyOn(floatingUi, "useFloating");
render(
<Label inline {...{ [validationProp]: "Message" }}>
foo
</Label>
);

await user.hover(screen.getByTestId(`icon-${validationProp}`));

expect(useFloatingSpy).toHaveBeenCalledWith(
expect.objectContaining({ placement: "top" })
);

useFloatingSpy.mockRestore();
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: what do you think of this modification to check the data-placement attribute on the tooltip? This would avoid the need to mock @floating-ui/react-dom:

Suggested change
const user = userEvent.setup();
const useFloatingSpy = jest.spyOn(floatingUi, "useFloating");
render(
<Label inline {...{ [validationProp]: "Message" }}>
foo
</Label>
);
await user.hover(screen.getByTestId(`icon-${validationProp}`));
expect(useFloatingSpy).toHaveBeenCalledWith(
expect.objectContaining({ placement: "top" })
);
useFloatingSpy.mockRestore();
const user = userEvent.setup();
render(
<Label inline {...{ [validationProp]: "Message" }}>
foo
</Label>
);
await user.hover(screen.getByTestId(`icon-${validationProp}`));
expect(await screen.findByRole("tooltip")).toHaveAttribute("data-placement", "top");

Comment on lines 155 to 164
const useFloatingSpy = jest.spyOn(floatingUi, "useFloating");
render(<Label {...{ [validationProp]: "Message" }}>foo</Label>);

await user.hover(screen.getByTestId(`icon-${validationProp}`));

expect(useFloatingSpy).toHaveBeenCalledWith(
expect.objectContaining({ placement: "right" })
);

useFloatingSpy.mockRestore();
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Similar to the previous test, what do you think about this change? It would avoid the need to mock @floating-ui/react-dom:

Suggested change
const useFloatingSpy = jest.spyOn(floatingUi, "useFloating");
render(<Label {...{ [validationProp]: "Message" }}>foo</Label>);
await user.hover(screen.getByTestId(`icon-${validationProp}`));
expect(useFloatingSpy).toHaveBeenCalledWith(
expect.objectContaining({ placement: "right" })
);
useFloatingSpy.mockRestore();
render(<Label {...{ [validationProp]: "Message" }}>foo</Label>);
await user.hover(screen.getByTestId(`icon-${validationProp}`));
expect(await screen.findByRole("tooltip")).toHaveAttribute("data-placement", "right");

@DipperTheDan DipperTheDan self-requested a review September 9, 2024 09:37
Copy link
Contributor

@DipperTheDan DipperTheDan left a comment

Choose a reason for hiding this comment

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

Nothing more to add from me. Just address the comments left by @Parsium 😄

@nuria1110 nuria1110 marked this pull request as ready for review September 10, 2024 11:00
@nuria1110 nuria1110 requested review from a team as code owners September 10, 2024 11:00
@nuria1110 nuria1110 merged commit c990068 into master Sep 10, 2024
24 checks passed
@nuria1110 nuria1110 deleted the FE-6783-label-rtl branch September 10, 2024 12:37
@carbonci
Copy link
Collaborator

🎉 This PR is included in version 142.9.1 🎉

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