1
1
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' ;
5
4
6
5
import { AccountForm , AccountFormProps } from './AccountForm' ;
7
6
8
- export default {
7
+ const meta = {
9
8
title : 'CSF3/AccountForm' ,
10
9
component : AccountForm ,
11
10
parameters : {
@@ -15,43 +14,53 @@ export default {
15
14
< p > This uses a custom render from meta</ p >
16
15
< AccountForm { ...args } />
17
16
</ div > )
18
- } as ComponentMeta < typeof AccountForm > ;
17
+ } as Meta < typeof AccountForm > ;
19
18
20
- type Story = ComponentStoryObj < typeof AccountForm >
19
+ export default meta ;
20
+
21
+ type Story = StoryObj < typeof meta > ;
21
22
22
23
export const Standard : Story = {
23
24
args : { passwordVerification : false } ,
24
25
} ;
25
26
26
27
export const StandardEmailFilled : Story = {
27
28
...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
+ }
29
33
} ;
30
34
31
35
export const StandardEmailFailed : Story = {
32
36
...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' ) ) ;
37
42
} ,
38
43
} ;
39
44
40
45
export const StandardPasswordFailed : Story = {
41
46
...Standard ,
42
47
play : async ( context ) => {
48
+ const { canvasElement} = context ;
49
+ const canvas = within ( canvasElement ) ;
43
50
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' ) ) ;
46
53
} ,
47
54
} ;
48
55
49
56
export const StandardFailHover : Story = {
50
57
...StandardPasswordFailed ,
51
58
play : async ( context ) => {
59
+ const { canvasElement} = context ;
60
+ const canvas = within ( canvasElement ) ;
52
61
await StandardPasswordFailed . play ! ( context ) ;
53
62
await sleep ( 100 ) ;
54
- await userEvent . hover ( screen . getByTestId ( 'password-error-info' ) ) ;
63
+ await userEvent . hover ( canvas . getByTestId ( 'password-error-info' ) ) ;
55
64
} ,
56
65
} ;
57
66
@@ -62,19 +71,23 @@ export const Verification: Story = {
62
71
export const VerificationPasssword1 : Story = {
63
72
...Verification ,
64
73
play : async ( context ) => {
74
+ const { canvasElement} = context ;
75
+ const canvas = within ( canvasElement ) ;
65
76
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' ) ) ;
68
79
} ,
69
80
} ;
70
81
71
82
export const VerificationPasswordMismatch : Story = {
72
83
...Verification ,
73
84
play : async ( context ) => {
85
+ const { canvasElement} = context ;
86
+ const canvas = within ( canvasElement ) ;
74
87
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' ) ) ;
78
91
} ,
79
92
} ;
80
93
@@ -83,13 +96,15 @@ const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
83
96
export const VerificationSuccess : Story = {
84
97
...Verification ,
85
98
play : async ( context ) => {
99
+ const { canvasElement} = context ;
100
+ const canvas = within ( canvasElement ) ;
86
101
await StandardEmailFilled . play ! ( context ) ;
87
102
await sleep ( 1000 ) ;
88
- await userEvent . type ( screen . getByTestId ( 'password1' ) , 'asdfasdf' , { delay : 50 } ) ;
103
+ await userEvent . type ( canvas . getByTestId ( 'password1' ) , 'asdfasdf' , { delay : 50 } ) ;
89
104
await sleep ( 1000 ) ;
90
- await userEvent . type ( screen . getByTestId ( 'password2' ) , 'asdfasdf' , { delay : 50 } ) ;
105
+ await userEvent . type ( canvas . getByTestId ( 'password2' ) , 'asdfasdf' , { delay : 50 } ) ;
91
106
await sleep ( 1000 ) ;
92
- await userEvent . click ( screen . getByTestId ( 'submit' ) ) ;
107
+ await userEvent . click ( canvas . getByTestId ( 'submit' ) ) ;
93
108
} ,
94
109
} ;
95
110
0 commit comments