Skip to content

Commit

Permalink
💚 - fix: Attempt fixing build
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed May 30, 2024
1 parent 2c4e423 commit 9020b4d
Showing 1 changed file with 56 additions and 57 deletions.
113 changes: 56 additions & 57 deletions src/components/dropdown/dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,15 @@ const meta: Meta<typeof Dropdown> = {
await waitFor(() => expect(canvas.queryByRole("dialog")).toBeNull());
await userEvent.click(button, { delay: 10 });

await waitFor(
async () => {
const _list = document.activeElement?.closest(
'[role="dialog"]',
) as HTMLElement;
const buttons = await within(_list).findAllByRole("button");
const lastButton = buttons[buttons.length - 1];
const lastButtonActive = document.activeElement === lastButton;

if (!lastButtonActive) {
await userEvent.tab({ delay: 10 });
throw new Error("Last button not selected");
}
},
{
interval: 100,
timeout: 2000,
},
);
for (let counter = 0; counter < 3; counter++) {
await userEvent.tab({ delay: 10 });
}

const dialog = await canvas.getByRole("dialog");
const buttons = await within(dialog).findAllByRole("button");
const lastButton = buttons[buttons.length - 1];

await expect(document.activeElement).toEqual(lastButton);

if (parameters.lastButtonText) {
await expect(document.activeElement?.textContent).toBe(
Expand Down Expand Up @@ -126,25 +116,16 @@ export const ActivateOnHover: Story = {
await waitFor(() => expect(canvas.queryByRole("dialog")).toBeNull());
await userEvent.hover(button, { delay: 10 });

await waitFor(
async () => {
const _list = document.activeElement?.closest(
'[role="dialog"]',
) as HTMLElement;
const buttons = await within(_list).findAllByRole("button");
const lastButton = buttons[buttons.length - 1];
const lastButtonActive = document.activeElement === lastButton;

if (!lastButtonActive) {
await userEvent.tab({ delay: 10 });
throw new Error("Last button not selected");
}
},
{
interval: 100,
timeout: 2000,
},
);
for (let counter = 0; counter < 3; counter++) {
await userEvent.tab({ delay: 10 });
}

const dialog = await canvas.getByRole("dialog");
const buttons = await within(dialog).findAllByRole("button");
const lastButton = buttons[buttons.length - 1];

await expect(document.activeElement).toEqual(lastButton);

if (parameters.lastButtonText) {
await expect(document.activeElement?.textContent).toBe(
parameters.lastButtonText,
Expand All @@ -168,25 +149,15 @@ export const ActivateOnFocus: Story = {
await userEvent.tab({ shift: true, delay: 10 });
await userEvent.tab({ delay: 10 });

await waitFor(
async () => {
const _list = document.activeElement?.closest(
'[role="dialog"]',
) as HTMLElement;
const buttons = await within(_list).findAllByRole("button");
const lastButton = buttons[buttons.length - 1];
const lastButtonActive = document.activeElement === lastButton;

if (!lastButtonActive) {
await userEvent.tab({ delay: 10 });
throw new Error("Last button not selected");
}
},
{
interval: 100,
timeout: 2000,
},
);
for (let counter = 0; counter < 3; counter++) {
await userEvent.tab({ delay: 10 });
}

const dialog = await canvas.getByRole("dialog");
const buttons = await within(dialog).findAllByRole("button");
const lastButton = buttons[buttons.length - 1];

await expect(document.activeElement).toEqual(lastButton);

if (parameters.lastButtonText) {
await expect(document.activeElement?.textContent).toBe(
Expand Down Expand Up @@ -341,6 +312,34 @@ export const NestedDropdown: Story = {
</>
),
},
play: async ({ canvasElement, parameters }) => {
const canvas = within(canvasElement);
const button = canvas.getByText("Click me!");

// Click opens, escape closes.
await userEvent.click(button, { delay: 10 });
await expect(await canvas.findByRole("dialog")).toBeVisible();
await userEvent.keyboard("{Escape}");
await waitFor(() => expect(canvas.queryByRole("dialog")).toBeNull());
await userEvent.click(button, { delay: 10 });

for (let counter = 0; counter < 3; counter++) {
await userEvent.tab({ delay: 10 });
}

const dialogs = await canvas.getAllByRole("dialog");
const dialog = dialogs[dialogs.length - 1];
const buttons = await within(dialog).findAllByRole("button");
const lastButton = buttons[buttons.length - 1];

await expect(document.activeElement).toEqual(lastButton);

if (parameters.lastButtonText) {
await expect(document.activeElement?.textContent).toBe(
parameters.lastButtonText,
);
}
},
};

export const DropdownWithItemsProp: Story = {
Expand Down

0 comments on commit 9020b4d

Please sign in to comment.