@payfit/unity-components
Version:
48 lines (47 loc) • 1.96 kB
JavaScript
import { expect as e, screen as t, userEvent as n, waitFor as r, within as i } from "storybook/test";
//#region src/components/dialog/test-utils.ts
var a = (a, o) => {
let s = 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;
}), c = async (e, t) => {
await n.click(i(e).getByRole("button", { name: t }), { delay: 100 });
};
return {
findDialog: s,
closeDialog: async ({ title: e, closeButtonLabel: t }) => {
await a.step("Close dialog", async () => {
await c(await s({ title: e }), t);
});
},
closeDialogWithDismissButton: async ({ title: e, dismissButtonLabel: t = o.formatMessage({ id: "unity:component:common:close:label" }) }) => {
await a.step("Close dialog", async () => {
await c(await s({ title: e }), t);
});
},
assertDialogIsClosed: async (t) => {
await r(async () => {
await e(t).not.toBeInTheDocument();
}, { timeout: 1e3 });
},
assertElementExistsInDialog: async ({ title: t, content: n, primaryActionLabel: r, secondaryActionLabel: o }) => {
let c = await s({ title: t });
n && await a.step(`Check if "${n}" is in the dialog`, async () => {
await e(i(c).getByText(n)).toBeInTheDocument();
}), r && await a.step(`Check if "${r}" is in the dialog`, async () => {
await e(i(c).getByRole("button", { name: r })).toBeInTheDocument();
}), o && await a.step(`Check if "${o}" is in the dialog`, async () => {
await e(i(c).getByRole("button", { name: o })).toBeInTheDocument();
});
},
triggerPrimaryAction: async ({ title: e, primaryActionLabel: t }) => {
let r = await s({ title: e });
await a.step(`Trigger the primary action "${t}" of the dialog`, async () => {
await n.click(i(r).getByRole("button", { name: t }));
});
}
};
};
//#endregion
export { a as getTestingUtilsDialog };