From 900053a576221aa9c00096aa4336124af44b4e84 Mon Sep 17 00:00:00 2001 From: Johan Persson Date: Tue, 2 Dec 2025 15:59:44 +0100 Subject: [PATCH] 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 --- plugins/catalog/src/alpha/pages.test.tsx | 31 +++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/plugins/catalog/src/alpha/pages.test.tsx b/plugins/catalog/src/alpha/pages.test.tsx index cc83b9168b..0b35e63979 100644 --- a/plugins/catalog/src/alpha/pages.test.tsx +++ b/plugins/catalog/src/alpha/pages.test.tsx @@ -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([