Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions packages/guide-cue/src/GuideCue/GuideCue.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down Expand Up @@ -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();
});
});
});
Loading