generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPage.stories.tsx
30 lines (24 loc) · 989 Bytes
/
Page.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { StoryFn, Meta } from "@storybook/react";
import { within, userEvent, expect } from "@storybook/test";
import { Page } from "./Page";
export default {
title: "Example/Page",
component: Page,
parameters: {
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
layout: "fullscreen",
},
} as Meta<typeof Page>;
const Template: StoryFn<typeof Page> = (args) => <Page {...args} />;
export const LoggedOut = Template.bind({});
export const LoggedIn = Template.bind({});
// More on interaction testing: https://storybook.js.org/docs/react/writing-tests/interaction-testing
LoggedIn.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole("button", { name: /Log in/i });
await userEvent.click(loginButton);
const coverage = (globalThis as any).__coverage__;
await expect(
Object.keys(coverage).find((cvg) => cvg.endsWith("Page.tsx"))
).toBeTruthy();
};