diff --git a/packages/guide-cue/src/GuideCue/GuideCue.spec.tsx b/packages/guide-cue/src/GuideCue/GuideCue.spec.tsx index 2d8a0d064e..6fbfa95415 100644 --- a/packages/guide-cue/src/GuideCue/GuideCue.spec.tsx +++ b/packages/guide-cue/src/GuideCue/GuideCue.spec.tsx @@ -186,18 +186,19 @@ describe('packages/guide-cue', () => { expect(body).toBeInTheDocument(); }); - test('primary button is focusable for focus trap targeting', async () => { + test('primary button is focused when opened', async () => { const { getByRole } = renderGuideCue({ open: true, }); - const primaryButton = getByRole('button', { name: buttonTextDefault }); - expect(primaryButton).toBeInTheDocument(); - - userEvent.tab(); await waitFor(() => { - expect(primaryButton).toHaveFocus(); + expect(getByRole('dialog')).toBeVisible(); // Checks visibility. If the dialog is visible, then the focus trap is in effect and the primary button is focused. }); + + const primaryButton = getByRole('button', { name: buttonTextDefault }); + expect(primaryButton).toBeInTheDocument(); + // This should automatically be in focus when the guidecue is opened. + expect(primaryButton).toHaveFocus(); }); }); @@ -367,23 +368,21 @@ describe('packages/guide-cue', () => { await waitFor(() => expect(numOfButtons).toEqual(2)); }); - test('primary button is focusable for focus trap targeting', async () => { + test('primary button is focused when opened', async () => { const { getByRole } = renderGuideCue({ open: true, numberOfSteps: 2, currentStep: 1, }); - await act(async () => { - await waitForTimeout(timeout1); + + await waitFor(() => { + expect(getByRole('dialog')).toBeVisible(); // Checks visibility. If the dialog is visible, then the focus trap is in effect and the primary button is focused. }); const primaryButton = getByRole('button', { name: buttonTextDefault }); expect(primaryButton).toBeInTheDocument(); - - userEvent.tab(); - await waitFor(() => { - expect(primaryButton).toHaveFocus(); - }); + // This should automatically be in focus when the guidecue is opened. + expect(primaryButton).toHaveFocus(); }); }); });