1+ import React from 'react' ;
2+ import type { ComponentMeta } from '@storybook/react' ;
3+ import { screen } from '@testing-library/dom' ;
4+ import userEvent from '@testing-library/user-event' ;
5+
6+ import { AccountForm , AccountFormProps } from './AccountForm' ;
7+
8+ export default {
9+ title : 'CSF3/AccountForm' ,
10+ component : AccountForm ,
11+ parameters : {
12+ layout : 'centered' ,
13+ } ,
14+ } as ComponentMeta < typeof AccountForm > ;
15+
16+
17+ export const Standard = {
18+ args : { passwordVerification : false } ,
19+ } ;
20+
21+ export const StandardEmailFilled = {
22+ ...Standard ,
23+ play : ( ) => userEvent . type ( screen . getByTestId ( 'email' ) , 'michael@chromatic.com' ) ,
24+ } ;
25+
26+ export const StandardEmailFailed = {
27+ ...Standard ,
28+ play : async ( ) => {
29+ await userEvent . type ( screen . getByTestId ( 'email' ) , 'michael@chromatic.com.com@com' ) ;
30+ await userEvent . type ( screen . getByTestId ( 'password1' ) , 'testpasswordthatwontfail' ) ;
31+ await userEvent . click ( screen . getByTestId ( 'submit' ) ) ;
32+ } ,
33+ } ;
34+
35+ export const StandardPasswordFailed = {
36+ ...Standard ,
37+ play : async ( ) => {
38+ await StandardEmailFilled . play ( ) ;
39+ await userEvent . type ( screen . getByTestId ( 'password1' ) , 'asdf' ) ;
40+ await userEvent . click ( screen . getByTestId ( 'submit' ) ) ;
41+ } ,
42+ } ;
43+
44+ export const StandardFailHover = {
45+ ...StandardPasswordFailed ,
46+ play : async ( ) => {
47+ await StandardPasswordFailed . play ( ) ;
48+ await sleep ( 100 ) ;
49+ await userEvent . hover ( screen . getByTestId ( 'password-error-info' ) ) ;
50+ } ,
51+ } ;
52+
53+ export const Verification = {
54+ args : { passwordVerification : true } ,
55+ } ;
56+
57+ export const VerificationPasssword1 = {
58+ ...Verification ,
59+ play : async ( ) => {
60+ await StandardEmailFilled . play ( ) ;
61+ await userEvent . type ( screen . getByTestId ( 'password1' ) , 'asdfasdf' ) ;
62+ await userEvent . click ( screen . getByTestId ( 'submit' ) ) ;
63+ } ,
64+ } ;
65+
66+ export const VerificationPasswordMismatch = {
67+ ...Verification ,
68+ play : async ( ) => {
69+ await StandardEmailFilled . play ( ) ;
70+ await userEvent . type ( screen . getByTestId ( 'password1' ) , 'asdfasdf' ) ;
71+ await userEvent . type ( screen . getByTestId ( 'password2' ) , 'asdf1234' ) ;
72+ await userEvent . click ( screen . getByTestId ( 'submit' ) ) ;
73+ } ,
74+ } ;
75+
76+ const sleep = ( ms : number ) => new Promise ( ( r ) => setTimeout ( r , ms ) ) ;
77+
78+ export const VerificationSuccess = {
79+ ...Verification ,
80+ play : async ( ) => {
81+ await StandardEmailFilled . play ( ) ;
82+ await sleep ( 1000 ) ;
83+ await userEvent . type ( screen . getByTestId ( 'password1' ) , 'asdfasdf' , { delay : 50 } ) ;
84+ await sleep ( 1000 ) ;
85+ await userEvent . type ( screen . getByTestId ( 'password2' ) , 'asdfasdf' , { delay : 50 } ) ;
86+ await sleep ( 1000 ) ;
87+ await userEvent . click ( screen . getByTestId ( 'submit' ) ) ;
88+ } ,
89+ } ;
90+
91+ export const StandardWithRenderFunction = {
92+ ...Standard ,
93+ render : ( args : AccountFormProps ) => ( < div >
94+ < p > This uses a custom render</ p >
95+ < AccountForm { ...args } />
96+ </ div > ) ,
97+ } ;
0 commit comments