diff --git a/src/components/context_menu/__snapshots__/context_menu.test.tsx.snap b/src/components/context_menu/__snapshots__/context_menu.test.tsx.snap index 52bf1735b16..87edd6a8653 100644 --- a/src/components/context_menu/__snapshots__/context_menu.test.tsx.snap +++ b/src/components/context_menu/__snapshots__/context_menu.test.tsx.snap @@ -28,139 +28,6 @@ exports[`EuiContextMenu can pass-through horizontal rule props 1`] = ` `; -exports[`EuiContextMenu props panels and initialPanelId navigates back to the previous panel when clicking the title button 1`] = ` -
-
- -
-
- 2 -
-
-
-
-`; - -exports[`EuiContextMenu props panels and initialPanelId navigates back to the previous panel when clicking the title button 2`] = ` -
-
- -
-
- 2 -
-
-
-
- -
- - - -
-
-
-`; - exports[`EuiContextMenu props panels and initialPanelId renders the referenced panel 1`] = `
- act(() => new Promise((resolve) => setTimeout(resolve, ms))); - describe('EuiContextMenu', () => { shouldRenderCustomStyles(); @@ -139,26 +136,36 @@ describe('EuiContextMenu', () => { expect(container.firstChild).toMatchSnapshot(); }); - it('navigates back to the previous panel when clicking the title button', async () => { + it('navigates to the next panel', async () => { const onPanelChange = jest.fn(); - const { container, getByTestSubject } = render( + const { getByText } = render( ); + fireEvent.click(getByText('2a')); + await waitForEuiContextMenuPanelTransition(); - await tick(20); - - expect(container.firstChild).toMatchSnapshot(); + expect(onPanelChange).toHaveBeenCalledWith({ + panelId: 2, + direction: 'next', + }); + }); - // Navigate to a different panel. + it('navigates back to the previous panel when clicking the title button', async () => { + const onPanelChange = jest.fn(); + const { getByTestSubject } = render( + + ); fireEvent.click(getByTestSubject('contextMenuPanelTitleButton')); + await waitForEuiContextMenuPanelTransition(); - await tick(20); - - expect(container.firstChild).toMatchSnapshot(); expect(onPanelChange).toHaveBeenCalledWith({ panelId: 1, direction: 'previous', diff --git a/src/test/rtl/component_helpers.d.ts b/src/test/rtl/component_helpers.d.ts index 13dc28dcb6c..1c984f5b14b 100644 --- a/src/test/rtl/component_helpers.d.ts +++ b/src/test/rtl/component_helpers.d.ts @@ -10,3 +10,5 @@ export declare const waitForEuiToolTipVisible: () => Promise; export declare const waitForEuiToolTipHidden: () => Promise; export declare const showEuiComboBoxOptions: () => Promise; + +export declare const waitForEuiContextMenuPanelTransition: () => Promise; diff --git a/src/test/rtl/component_helpers.ts b/src/test/rtl/component_helpers.ts index 66611572cd6..4351f43e2a6 100644 --- a/src/test/rtl/component_helpers.ts +++ b/src/test/rtl/component_helpers.ts @@ -46,8 +46,9 @@ export const waitForEuiToolTipHidden = async () => }); /** - * Doot doo + * EuiComboBox */ + export const showEuiComboBoxOptions = async () => { fireEvent.click(screen.getByTestSubject('comboBoxToggleListButton')); await waitForEuiPopoverOpen(); @@ -55,3 +56,26 @@ export const showEuiComboBoxOptions = async () => { expect(screen.getByRole('listbox')).toBeInTheDocument(); }); }; + +/** + * EuiContextMenu + */ + +export const waitForEuiContextMenuPanelTransition = async () => { + // Used document instead of container or screen due to context menus living in portals + const getPanels = () => document.querySelectorAll('.euiContextMenuPanel'); + + // 2 panels will appear for the transition animation + await waitFor(() => { + expect(getPanels().length).toEqual(2); + }); + + // Outgoing panel will be removed on animation end + fireEvent.animationEnd(getPanels()[0]); + if (getPanels().length > 1) { + fireEvent.animationEnd(getPanels()[1]); + } + + // Transition/animation is done once we're back to 1 panel + expect(getPanels().length).toEqual(1); +};