-
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: fix linting errors in RTL-migrated test files #6709
Conversation
src/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.test.tsx
Outdated
Show resolved
Hide resolved
await user.tab(); | ||
const user = userEvent.setup({ | ||
advanceTimers: jest.advanceTimersByTime, | ||
delay: null, |
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.
We should be cautious about using the delay
option to userEvent.setup
.
By default, user-event
adds a small delay between subsequent inputs, like key presses, to simulate how a real user would provide input. Setting delay
to null
removes it entirely. While this may be useful in some cases, it could potentially mask issues related to timeouts or promises in our code.
I see some of the previous spec files that were more or less already RTL have had their filename changed so that RTL linting will occur on them but we should also make a note of these files that have been converted so they don't get missed when we sweep them for refactor. There's still quite a lot of bad practices in those files that we want to get on top of. |
406ad3d
to
27997f0
Compare
Adding DO NOT MERGE label - since this PR depends on the release of #6715 first |
Raised FE-6549 for this 👍🏼 |
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.
Great work @Parsium some comments from me but mainly non-blocking
}); | ||
|
||
it("refocuses the container within the trap when flag is set, if the wrapper has no tabindex", () => { | ||
const { rerender } = render( | ||
mockComponentToRender({ autoFocus: false, triggerRefocusFlag: false }) | ||
); | ||
// need to blur the wrapper to remove the tabindex | ||
fireEvent.blur(screen.getByTestId(WRAPPER_ID)); | ||
fireEvent.blur(screen.getByRole("dialog")); |
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): we could use user.tab()
here to mimic the user behaviour, happy for that to be done in a new ticket though as we're just addressing linting complaints here etc
@@ -25,7 +25,7 @@ import useLocale from "../../hooks/__internal__/useLocale"; | |||
export interface FileInputProps | |||
extends Pick<ValidationProps, "error">, | |||
Pick<InputProps, "id" | "name" | "required">, | |||
TagProps, | |||
Omit<TagProps, "data-component">, |
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.
Praise: good spot 👏
src/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.test.tsx
Outdated
Show resolved
Hide resolved
src/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.test.tsx
Outdated
Show resolved
Hide resolved
@@ -35,7 +35,7 @@ describe("FixedNavigationBarContextProvider", () => { | |||
<MockComponent position={position} orientation="top" offset="20px" /> | |||
); | |||
const result = screen.getByTestId("output"); | |||
expect(result.textContent).toBe(""); | |||
expect(result).toHaveTextContent(""); |
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.
Praise: nice 👏
return renderRTL( | ||
<Tooltip {...props} message={message || props.message}> | ||
{props.children || children} | ||
function renderTooltip(props: Partial<TooltipProps> = {}) { |
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.
comment (non-blocking): same comment about abstracting the render, happy to sort all this later though 👍
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.
Yeah, this file needs a good review due to the nested structure and styling rules, so I'll leave this for now.
let middleware; | ||
if (useFloatingSpy.mock.calls[0][0]?.middleware?.[0]) { | ||
middleware = useFloatingSpy.mock.calls[0][0]?.middleware?.[0]; | ||
describe.each(["top", "bottom", "left", "right"] as const)( |
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.
comment (non-blocking): this is the prime example of a test that we need to refactor 😆. Again happy for it to be part of future work
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.
Good work James. Can see a lot of very good improvements overall. A few things still don't sit right with me as previously mentioned/discussed but we'll get there!
await shiftTabPress(); | ||
expect(screen.getByText(BUTTON_TWO)).toHaveFocus(); | ||
}); | ||
it("loops focus to the last focusable element, when focus on first radio button shift-tab pressed", async () => { |
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.
praise: much improved language/description of the test
Applies to all of those changes
expect(hintText).toBeVisible(); | ||
}); | ||
|
||
it("accepts data tag props", () => { | ||
it("renders root container with correct data tag props", () => { |
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.
praise: much improved test description
Applies for the others you've made as well
src/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.test.tsx
Outdated
Show resolved
Hide resolved
a4e424b
to
3e8a87a
Compare
expect(screen.getByText("bar")).toBeVisible(); | ||
}); | ||
|
||
it("when the 'title' prop is passed, the correct element and text renders", () => { |
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): language still wrong on this test
Might be worth adding to the re-visit ticket rather than dealing with it now unless there were other changes to be made
} | ||
); | ||
|
||
it("when the 'showCloseIcon' prop is true, the correct element renders", () => { |
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): language still wrong on this test
Might be worth adding to the re-visit ticket rather than dealing with it now unless there were other changes to be made
3e8a87a
to
16cc1ac
Compare
🎉 This PR is included in version 135.1.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Proposed Behaviour
*.test.*
.Current Behaviour
*.spec.*
extension.Additional Context
This PR is the second part of a two-phased process to introduce linting support for RTL tests, following the first PR, #6715. This division has been implemented to streamline the code review process.
Checklist
d.ts
file added or updated if required