-
Notifications
You must be signed in to change notification settings - Fork 86
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
Conversation
3f41901
to
ffe24ec
Compare
const dropTarget = tableRows[2]; | ||
const elementToDrag = tableRows[0]; |
There was a problem hiding this comment.
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.
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", () => { |
There was a problem hiding this comment.
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", () => { |
There was a problem hiding this comment.
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?:
There was a problem hiding this 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 👍🏻
adds ignore to line of code in `flat-table.component` when no `tr` elements are passed
ffe24ec
to
7acfd20
Compare
🎉 This PR is included in version 142.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
d.ts
file added or updated if requiredQA
Additional context
Testing instructions