UNPKG

@payfit/unity-components

Version:

50 lines (49 loc) • 2.01 kB
import { expect as e, screen as t, userEvent as n, waitFor as r, within as i } from "storybook/test"; //#region src/core/components/dialog/test-utils.ts var a = (e, t) => t ?? e.i18n.t((e) => e.unity.component.common.close.label), o = (o, s) => { let c = async ({ title: e }) => await r(() => { let n = t.queryByRole("dialog", { name: e }) ?? t.queryByRole("alertdialog", { name: e }); if (!n) throw Error(`Dialog with title: "${e}" not found in the page`); return n; }), l = async (e, t) => { await n.click(i(e).getByRole("button", { name: t }), { delay: 100 }); }; return { findDialog: c, closeDialog: async ({ title: e, closeButtonLabel: t }) => { await o.step("Close dialog", async () => { let n = await c({ title: e }); await l(n, t); }); }, closeDialogWithDismissButton: async ({ title: e, dismissButtonLabel: t = a(o, s) }) => { await o.step("Close dialog", async () => { let n = await c({ title: e }); await l(n, t); }); }, assertDialogIsClosed: async (t) => { await r(async () => { await e(t).not.toBeInTheDocument(); }, { timeout: 1e3 }); }, assertElementExistsInDialog: async ({ title: t, content: n, primaryActionLabel: r, secondaryActionLabel: a }) => { let s = await c({ title: t }); n && await o.step(`Check if "${n}" is in the dialog`, async () => { await e(i(s).getByText(n)).toBeInTheDocument(); }), r && await o.step(`Check if "${r}" is in the dialog`, async () => { await e(i(s).getByRole("button", { name: r })).toBeInTheDocument(); }), a && await o.step(`Check if "${a}" is in the dialog`, async () => { await e(i(s).getByRole("button", { name: a })).toBeInTheDocument(); }); }, triggerPrimaryAction: async ({ title: e, primaryActionLabel: t }) => { let r = await c({ title: e }); await o.step(`Trigger the primary action "${t}" of the dialog`, async () => { await n.click(i(r).getByRole("button", { name: t })); }); } }; }; //#endregion export { o as getTestingUtilsDialog };