fix(catalog): fix flaky context menu test race condition
The "should render an onClick based context menu item" test was failing intermittently due to a race condition where the test would interact with the menu before the entity route parameters were fully resolved. Fix by adding explicit waits: - Wait for entity to load before clicking the menu button - Wait for menu to open before asserting on menu items Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
@@ -721,18 +721,27 @@ describe('Entity page', () => {
|
||||
);
|
||||
|
||||
const { disabled } = params.useProps();
|
||||
await waitFor(async () => {
|
||||
await userEvent.click(screen.getByTestId('menu-button'));
|
||||
expect(screen.getByText('Test Title')).toBeInTheDocument();
|
||||
expect(screen.getByText('Test Icon')).toBeInTheDocument();
|
||||
const listItem = screen.getByText('Test Title').closest('li');
|
||||
expect(listItem).toHaveAttribute('aria-disabled', disabled.toString());
|
||||
if (!disabled) {
|
||||
await userEvent.click(screen.getByText('Test Title'));
|
||||
}
|
||||
|
||||
expect(onClickMock).toHaveBeenCalledTimes(disabled ? 0 : 1);
|
||||
});
|
||||
// Wait for entity to load first
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(/artist-lookup/)).toBeInTheDocument(),
|
||||
);
|
||||
|
||||
await userEvent.click(screen.getByTestId('menu-button'));
|
||||
|
||||
// Wait for menu to open
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText('Test Title')).toBeInTheDocument(),
|
||||
);
|
||||
|
||||
expect(screen.getByText('Test Icon')).toBeInTheDocument();
|
||||
const listItem = screen.getByText('Test Title').closest('li');
|
||||
expect(listItem).toHaveAttribute('aria-disabled', disabled.toString());
|
||||
if (!disabled) {
|
||||
await userEvent.click(screen.getByText('Test Title'));
|
||||
}
|
||||
|
||||
expect(onClickMock).toHaveBeenCalledTimes(disabled ? 0 : 1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
Reference in New Issue
Block a user