Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit 168bc9a

Browse files
committed
update example to use Storybook 7.0 and addon-interactions
1 parent 562ae08 commit 168bc9a

File tree

5 files changed

+8036
-10060
lines changed

5 files changed

+8036
-10060
lines changed

example/.storybook/main.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
import type { StorybookConfig } from '@storybook/react/types';
1+
import type { StorybookConfig } from '@storybook/react-webpack5';
22

33
const config: StorybookConfig = {
44
stories: ['../src/**/*.stories.tsx'],
55
logLevel: 'debug',
6-
addons: ['@storybook/preset-create-react-app', '@storybook/addon-essentials'],
6+
addons: [
7+
'@storybook/preset-create-react-app',
8+
'@storybook/addon-essentials',
9+
'@storybook/addon-interactions',
10+
],
11+
docs: {
12+
docsPage: 'automatic',
13+
},
14+
framework: {
15+
name: '@storybook/react-webpack5',
16+
options: {},
17+
},
718
features: {
8-
previewCsfV3: true,
19+
interactionsDebugger: true,
920
},
1021
};
1122

example/package.json

+21-17
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"private": true,
55
"scripts": {
66
"build": "react-scripts build",
7-
"build-storybook": "build-storybook -s public",
7+
"build-storybook": "storybook build -s public",
88
"eject": "react-scripts eject",
99
"start": "react-scripts start",
10-
"storybook": "start-storybook -p 9009 -s public",
10+
"storybook": "storybook dev -p 9009 -s public",
1111
"test": "SKIP_PREFLIGHT_CHECK=true react-scripts test --setupFiles ./setup.ts"
1212
},
1313
"browserslist": {
@@ -23,24 +23,28 @@
2323
]
2424
},
2525
"dependencies": {
26-
"@types/jest": "25.2.3",
26+
"@types/jest": "^27.0.0",
2727
"@types/node": "14.14.20",
28-
"@types/react": "^16.14.2",
29-
"@types/react-dom": "16.9.10",
28+
"@types/react": "^17.0.2",
29+
"@types/react-dom": "^17.0.2",
3030
"formik": "^2.2.9",
3131
"global": "^4.4.0",
32-
"react": "16.14.0",
33-
"react-dom": "16.14.0",
34-
"react-scripts": "3.4.4",
35-
"typescript": "^3.9.7"
32+
"react": "^17.0.2",
33+
"react-dom": "^17.0.2",
34+
"react-scripts": "5.0.1",
35+
"typescript": "^4.9.3"
3636
},
3737
"devDependencies": {
38-
"@storybook/addon-essentials": "^6.4.0-rc.2",
39-
"@storybook/react": "^6.4.0-rc.2",
40-
"@storybook/components": "^6.4.0-rc.2",
41-
"@storybook/theming": "^6.4.0-rc.2",
42-
"@storybook/preset-create-react-app": "^3.1.5",
43-
"@testing-library/react": "^11.2.5",
44-
"@testing-library/user-event": "^13.1.9"
38+
"@storybook/addon-essentials": "7.0.0-alpha.56",
39+
"@storybook/addon-interactions": "^6.5.14",
40+
"@storybook/components": "7.0.0-alpha.56",
41+
"@storybook/preset-create-react-app": "^4.1.2",
42+
"@storybook/react": "7.0.0-alpha.56",
43+
"@storybook/react-webpack5": "7.0.0-alpha.56",
44+
"@storybook/testing-library": "^0.0.13",
45+
"@storybook/theming": "7.0.0-alpha.56",
46+
"@testing-library/react": "^12.0.0",
47+
"@testing-library/user-event": "^13.1.9",
48+
"storybook": "7.0.0-alpha.56"
4549
}
46-
}
50+
}

example/src/components/AccountForm.stories.tsx

+37-22
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
2-
import type { ComponentMeta, ComponentStoryObj } from '@storybook/react';
3-
import { screen } from '@testing-library/dom';
4-
import userEvent from '@testing-library/user-event';
2+
import type { Meta, StoryObj } from '@storybook/react';
3+
import { within, userEvent} from '@storybook/testing-library';
54

65
import { AccountForm, AccountFormProps } from './AccountForm';
76

8-
export default {
7+
const meta = {
98
title: 'CSF3/AccountForm',
109
component: AccountForm,
1110
parameters: {
@@ -15,43 +14,53 @@ export default {
1514
<p>This uses a custom render from meta</p>
1615
<AccountForm {...args} />
1716
</div>)
18-
} as ComponentMeta<typeof AccountForm>;
17+
} as Meta<typeof AccountForm>;
1918

20-
type Story = ComponentStoryObj<typeof AccountForm>
19+
export default meta;
20+
21+
type Story = StoryObj<typeof meta>;
2122

2223
export const Standard: Story = {
2324
args: { passwordVerification: false },
2425
};
2526

2627
export const StandardEmailFilled: Story = {
2728
...Standard,
28-
play: () => userEvent.type(screen.getByTestId('email'), '[email protected]'),
29+
play: async ({canvasElement}) => {
30+
const canvas = within(canvasElement);
31+
await userEvent.type(canvas.getByTestId('email'), '[email protected]');
32+
}
2933
};
3034

3135
export const StandardEmailFailed: Story = {
3236
...Standard,
33-
play: async () => {
34-
await userEvent.type(screen.getByTestId('email'), '[email protected]@com');
35-
await userEvent.type(screen.getByTestId('password1'), 'testpasswordthatwontfail');
36-
await userEvent.click(screen.getByTestId('submit'));
37+
play: async ({canvasElement}) => {
38+
const canvas = within(canvasElement);
39+
await userEvent.type(canvas.getByTestId('email'), '[email protected]@com');
40+
await userEvent.type(canvas.getByTestId('password1'), 'testpasswordthatwontfail');
41+
await userEvent.click(canvas.getByTestId('submit'));
3742
},
3843
};
3944

4045
export const StandardPasswordFailed: Story = {
4146
...Standard,
4247
play: async (context) => {
48+
const {canvasElement} = context;
49+
const canvas = within(canvasElement);
4350
await StandardEmailFilled.play!(context);
44-
await userEvent.type(screen.getByTestId('password1'), 'asdf');
45-
await userEvent.click(screen.getByTestId('submit'));
51+
await userEvent.type(canvas.getByTestId('password1'), 'asdf');
52+
await userEvent.click(canvas.getByTestId('submit'));
4653
},
4754
};
4855

4956
export const StandardFailHover: Story = {
5057
...StandardPasswordFailed,
5158
play: async (context) => {
59+
const {canvasElement} = context;
60+
const canvas = within(canvasElement);
5261
await StandardPasswordFailed.play!(context);
5362
await sleep(100);
54-
await userEvent.hover(screen.getByTestId('password-error-info'));
63+
await userEvent.hover(canvas.getByTestId('password-error-info'));
5564
},
5665
};
5766

@@ -62,19 +71,23 @@ export const Verification: Story = {
6271
export const VerificationPasssword1: Story = {
6372
...Verification,
6473
play: async (context) => {
74+
const {canvasElement} = context;
75+
const canvas = within(canvasElement);
6576
await StandardEmailFilled.play!(context);
66-
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf');
67-
await userEvent.click(screen.getByTestId('submit'));
77+
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf');
78+
await userEvent.click(canvas.getByTestId('submit'));
6879
},
6980
};
7081

7182
export const VerificationPasswordMismatch: Story = {
7283
...Verification,
7384
play: async (context) => {
85+
const {canvasElement} = context;
86+
const canvas = within(canvasElement);
7487
await StandardEmailFilled.play!(context);
75-
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf');
76-
await userEvent.type(screen.getByTestId('password2'), 'asdf1234');
77-
await userEvent.click(screen.getByTestId('submit'));
88+
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf');
89+
await userEvent.type(canvas.getByTestId('password2'), 'asdf1234');
90+
await userEvent.click(canvas.getByTestId('submit'));
7891
},
7992
};
8093

@@ -83,13 +96,15 @@ const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
8396
export const VerificationSuccess: Story = {
8497
...Verification,
8598
play: async (context) => {
99+
const {canvasElement} = context;
100+
const canvas = within(canvasElement);
86101
await StandardEmailFilled.play!(context);
87102
await sleep(1000);
88-
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf', { delay: 50 });
103+
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf', { delay: 50 });
89104
await sleep(1000);
90-
await userEvent.type(screen.getByTestId('password2'), 'asdfasdf', { delay: 50 });
105+
await userEvent.type(canvas.getByTestId('password2'), 'asdfasdf', { delay: 50 });
91106
await sleep(1000);
92-
await userEvent.click(screen.getByTestId('submit'));
107+
await userEvent.click(canvas.getByTestId('submit'));
93108
},
94109
};
95110

example/src/components/Button.stories.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
import { StoryFn as CSF2Story, StoryObj as CSF3Story, Meta, ComponentStoryObj } from '@storybook/react';
2+
import { StoryFn as CSF2Story, StoryObj as CSF3Story, Meta } from '@storybook/react';
33
import { useArgs } from '@storybook/addons';
4-
import { screen } from '@testing-library/react';
5-
import userEvent from '@testing-library/user-event';
4+
import { within, userEvent} from '@storybook/testing-library';
65

76
import { Button, ButtonProps } from './Button';
87

@@ -81,8 +80,9 @@ export const InputFieldFilled: CSF3Story = {
8180
render: () => {
8281
return <input />;
8382
},
84-
play: async (context) => {
85-
await userEvent.type(screen.getByRole('textbox'), 'Hello world!');
83+
play: async ({canvasElement}) => {
84+
const canvas = within(canvasElement);
85+
await userEvent.type(canvas.getByRole('textbox'), 'Hello world!');
8686
},
8787
};
8888

0 commit comments

Comments
 (0)