-
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(text-editor): covert tests to use react-testing-library #7016
base: master
Are you sure you want to change the base?
Conversation
8333ffd
to
3eab34b
Compare
3eab34b
to
df84249
Compare
); | ||
}); | ||
|
||
test("files a console warning when the `rows` prop is passed as a number less than 2", () => { |
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/question/nitpick: Is this a spelling mistake?
test("files a console warning when the `rows` prop is passed as a number less than 2", () => { | |
test("fires a console warning when the `rows` prop is passed as a number less than 2", () => { |
expect(screen.getByText("talic texti")).toBeVisible(); | ||
}, 10000); // allow to run for up to 10 seconds due to timeout issues | ||
|
||
// for coverage only - this behaviour doesn't work properly in jsdom (note incorrect order of text being entere). |
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.
nitpick:
// for coverage only - this behaviour doesn't work properly in jsdom (note incorrect order of text being entere). | |
// for coverage only - this behaviour doesn't work properly in jsdom (note incorrect order of text being entered). |
expect(screen.getByRole("listitem")).toHaveTextContent("ist iteml"); | ||
}, 10000); // allow to run for up to 10 seconds due to timeout issues | ||
|
||
// for coverage only - this behaviour doesn't work properly in jsdom (note incorrect order of text being entere). |
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.
nitpick:
// for coverage only - this behaviour doesn't work properly in jsdom (note incorrect order of text being entere). | |
// for coverage only - this behaviour doesn't work properly in jsdom (note incorrect order of text being entered). |
}); | ||
|
||
// the next several tests are for coverage only - due to an issue with React itself, dispatching the (deprecated) `keypress` event | ||
// with non-standard propertoes is the only way to trigger the `handleBeforeInput` handler in a test. See |
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.
nitpick:
// with non-standard propertoes is the only way to trigger the `handleBeforeInput` handler in a test. See | |
// with non-standard properties is the only way to trigger the `handleBeforeInput` handler in a test. See |
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.
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.
Really good work @robinzigmond, I really appreciate the detail you've gone to to explain why certain things have been added (has definitely limited the questions/comments from me) and the effort you've put into investigating the issues with JSDOM and DraftJS
|
||
await user.keyboard("{ArrowRight}"); | ||
expect(screen.getByRole("button", { name: "bold" })).toHaveFocus(); | ||
}, 40000); // allow to run for up to 40 seconds(!) due to timeout issues |
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): it might be worth splitting these tests up a bit so we can avoid large timeouts here, I think we can live with the 10 second ones but exceeding that seems too much. If that doesn't work I think it'd be better to move them to playwright until we can rewrite the component.
Update: had a little play around locally, I think if we use a combination of async
findBy
querying for the tooltips and await waitFor
we can remove the 10 second timeout tests (didn't work for the larger ones) so maybe we can break up the slower ones or move them to playwright
|
||
screen.getByRole("button", { name: buttonName }).focus(); | ||
|
||
expect(screen.getByTestId("tooltip")).toBeVisible(); |
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.
expect(screen.getByTestId("tooltip")).toBeVisible(); | |
expect(await screen.findByRole("tooltip")).toBeVisible(); |
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.
you can also probably combine them with:
expect(await screen.findByRole("tooltip", {name: tooltipText})).toBeVisible();
expect(screen.getByTestId("tooltip")).toHaveTextContent(tooltipText); | ||
|
||
screen.getByRole("button", { name: buttonName }).blur(); | ||
expect(screen.queryByTestId("tooltip")).not.toBeInTheDocument(); |
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.
expect(screen.queryByTestId("tooltip")).not.toBeInTheDocument(); | |
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument(); |
} | ||
); | ||
|
||
test("calls the `onClose` callback of an `LinkPreview` component if clicked", 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.
test("calls the `onClose` callback of an `LinkPreview` component if clicked", async () => { | |
test("calls the `onClose` callback of a `LinkPreview` component if clicked", async () => { |
}); | ||
|
||
// the next several tests are for coverage only - due to an issue with React itself, dispatching the (deprecated) `keypress` event | ||
// with non-standard propertoes is the only way to trigger the `handleBeforeInput` handler in a test. See |
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.
await expect(innerTextList(page, "ol", 3)).toHaveText("baz"); | ||
}); | ||
|
||
test("when a `list toolbar button is clicked, added text is rendered in an unordered list, with enter separating list items", 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.
test("when a `list toolbar button is clicked, added text is rendered in an unordered list, with enter separating list items", async ({ | |
test("when a `list` toolbar button is clicked, added text is rendered in an unordered list, with enter separating list items", async ({ |
await expect(innerTextList(page, "ul", 3)).toHaveText("baz"); | ||
}); | ||
|
||
test("when an list button is toggled on and off, new text is entered without the corresponding formatting, while the previously-entered text keeps the formatting", 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.
test("when an list button is toggled on and off, new text is entered without the corresponding formatting, while the previously-entered text keeps the formatting", async ({ | |
test("when a `list` button is toggled on and off, new text is entered without the corresponding formatting, while the previously-entered text keeps the formatting", async ({ |
Proposed behaviour
TextEditor component should have unit tests written in React Testing Library
NOTE: due to many issues with the drafjs library and jsdom/RTL, a lot of functionality was not possible to sensibly test, so these tests have been added to Playwright instead. Many unit tests have been added just for coverage that do not otherwise provide much value. When we eventually move away from draftjs (which is no longer supported) we should write RTL tests for what is being covered by the new Playwright tests, and remove both those playwright tests and as many as possible of the current "coverage only" unit tests.
Current behaviour
Unit tests use Enzyme
Checklist
d.ts
file added or updated if requiredQA
Additional context
Testing instructions