@payfit/unity-components
Version:
49 lines (48 loc) • 2.12 kB
JavaScript
import { expect as e, screen as t, userEvent as n, waitFor as r, within as i } from "storybook/test";
//#region src/core/components/bottom-sheet/test-utils.ts
var a = (a) => {
let o = async ({ title: e }) => await r(() => {
let n = t.queryByRole("dialog", { name: e });
if (!n) throw Error(`BottomSheet with title: "${e}" not found in the page`);
return n;
});
return {
findBottomSheet: o,
closeBottomSheetWithDismissButton: async ({ title: e, dismissButtonLabel: t = a.i18n.t((e) => e.unity.component.common.close.label) }) => {
await a.step("Close BottomSheet with dismiss button", async () => {
let r = await o({ title: e });
await n.click(i(r).getByRole("button", { name: t }), { delay: 100 });
});
},
closeBottomSheetByClickingOutside: async ({ title: e }) => {
await a.step("Close BottomSheet by clicking outside", async () => {
let t = (await o({ title: e })).closest("[data-unity-component=\"BottomSheet\"]");
if (!t) throw Error("Bottom sheet overlay not found");
await n.click(t, { delay: 1e3 });
});
},
assertBottomSheetIsClosed: async (t) => {
await r(async () => {
await e(t).not.toBeInTheDocument();
}, { timeout: 3e3 });
},
assertElementExistsInBottomSheet: async ({ title: t, content: n, primaryActionLabel: r, secondaryActionLabel: s }) => {
let c = await o({ title: t });
n && await a.step(`Check if "${n}" is in the BottomSheet`, async () => {
await e(i(c).getByText(n)).toBeInTheDocument();
}), r && await a.step(`Check if "${r}" is in the BottomSheet`, async () => {
await e(i(c).getByRole("button", { name: r })).toBeInTheDocument();
}), s && await a.step(`Check if "${s}" is in the BottomSheet`, async () => {
await e(i(c).getByRole("button", { name: s })).toBeInTheDocument();
});
},
triggerFooterButtonAction: async ({ title: e, buttonLabel: t }) => {
let r = await o({ title: e });
await a.step(`Trigger the button "${t}" of the BottomSheet`, async () => {
await n.click(i(r).getByRole("button", { name: t }));
});
}
};
};
//#endregion
export { a as getTestingUtilsBottomSheet };