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(flat-table-checkbox): convert unit tests to RTL #6888

Merged
merged 6 commits into from
Aug 21, 2024

Conversation

edleeks87
Copy link
Contributor

Proposed behaviour

Converts FlatTableCheckbox, FlatTableHead, FlatTableBody, FlatTableBodyDraggable and Sort component unit tests to RTL

Current behaviour

FlatTableCheckbox, FlatTableHead, FlatTableBody, FlatTableBodyDraggable and Sort component unit tests are enzyme

Checklist

  • Commits follow our style guide
  • Unit tests added or updated if required
  • Typescript d.ts file added or 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

@edleeks87 edleeks87 self-assigned this Aug 8, 2024
@edleeks87 edleeks87 force-pushed the flat-table-rtl-1 branch 2 times, most recently from 3f41901 to ffe24ec Compare August 8, 2024 14:32
@edleeks87 edleeks87 changed the title refactor(flat-table-checkbox): covert unit tests to RTL refactor(flat-table-checkbox): convert unit tests to RTL Aug 8, 2024
@Parsium Parsium self-requested a review August 12, 2024 12:45
Comment on lines 163 to 164
const dropTarget = tableRows[2];
const elementToDrag = tableRows[0];
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): for improved readability, what do you think of querying these elements directly rather than indexing an array? Not essential though.

Suggested change
const dropTarget = tableRows[2];
const elementToDrag = tableRows[0];
const dropTarget = screen.getByRole("row", { name: "Row three" });
const elementToDrag = screen.getByRole("row", { name: "Row one" })

expect(parentOnKeyDown).toHaveBeenCalled();
});

test("should render a 'td' element by default and have the expected data-element attribute", () => {
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 just checking the cell has the correct data attributes here? If we use the cell role, this should eliminate the need to check the cell is a <td> tag:

test("should render cell with expected data-* attributes", () => {
  render(
    <table>
      <tbody>
        <tr>
          <FlatTableCheckbox onChange={() => {}} data-role="ft-checkbox" />
        </tr>
      </tbody>
    </table>
  );
  const checkboxCell = screen.getByRole("cell");

  expect(checkboxCell).toHaveAttribute("data-role", "ft-checkbox");
  expect(checkboxCell).toHaveAttribute(
    "data-element",
    "flat-table-checkbox-cell"
  );
});

);
});

test("should render an element to match the `as` prop value when it is set and have the expected data-element attribute", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: similarly to the cell test, what do you think of just testing that the data attributes are correct, if we utilise the columnheader role to find the <th> tag?:

@DipperTheDan DipperTheDan self-requested a review August 19, 2024 08:05
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 👍🏻

@edleeks87 edleeks87 marked this pull request as ready for review August 21, 2024 13:23
@edleeks87 edleeks87 requested a review from a team as a code owner August 21, 2024 13:23
@edleeks87 edleeks87 merged commit d999b98 into master Aug 21, 2024
22 checks passed
@edleeks87 edleeks87 deleted the flat-table-rtl-1 branch August 21, 2024 13:33
@carbonci
Copy link
Collaborator

🎉 This PR is included in version 142.3.0 🎉

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