refactor(tests): use getByRole instead of getByText for interactive elements
- Refactor ~47 test cases across 7 test files to use getByRole - Improve accessibility testing coverage following Testing Library best practices - Make tests more robust against text changes (i18n, copy updates) - Test elements as users (especially screen readers) interact with them
This commit is contained in:
committed by
Benoit TELLIER
parent
4c18bf3a52
commit
b9905cbb7a
@@ -75,7 +75,7 @@ describe("EventDuplication", () => {
|
||||
preloadedState
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByText("Duplicate event"));
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: /Duplicate event/i }));
|
||||
|
||||
expect(screen.getAllByText(/Duplicate Event/i)[1]).toBeInTheDocument();
|
||||
});
|
||||
@@ -93,10 +93,10 @@ describe("EventDuplication", () => {
|
||||
preloadedState
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByText("Duplicate event"));
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: /Duplicate event/i }));
|
||||
|
||||
// Cancel button only appears in expanded mode
|
||||
fireEvent.click(screen.getByText("More options"));
|
||||
fireEvent.click(screen.getByRole("button", { name: /More options/i }));
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /Cancel/i }));
|
||||
|
||||
@@ -166,7 +166,7 @@ describe("EventDisplayModal", () => {
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByTestId("MoreVertIcon"));
|
||||
fireEvent.click(screen.getByText("Duplicate event"));
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: /Duplicate event/i }));
|
||||
expect(screen.getAllByText(/Duplicate Event/i)[1]).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByDisplayValue(
|
||||
|
||||
@@ -103,7 +103,7 @@ async function setupEventPopover(
|
||||
fireEvent.change(titleInput, { target: { value: "Meeting" } });
|
||||
|
||||
// Click More options to expand the dialog
|
||||
const showMoreButton = screen.getByText("More options");
|
||||
const showMoreButton = screen.getByRole("button", { name: /More options/i });
|
||||
fireEvent.click(showMoreButton);
|
||||
|
||||
// Check Repeat checkbox to show repeat options
|
||||
|
||||
Reference in New Issue
Block a user