11import 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
65import { 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
2223export const Standard : Story = {
2324 args : { passwordVerification : false } ,
2425} ;
2526
2627export const StandardEmailFilled : Story = {
2728 ...Standard ,
28- play : ( ) => userEvent . type ( screen . getByTestId ( 'email' ) , 'michael@chromatic.com' ) ,
29+ play : async ( { canvasElement} ) => {
30+ const canvas = within ( canvasElement ) ;
31+ await userEvent . type ( canvas . getByTestId ( 'email' ) , 'michael@chromatic.com' ) ;
32+ }
2933} ;
3034
3135export const StandardEmailFailed : Story = {
3236 ...Standard ,
33- play : async ( ) => {
34- await userEvent . type ( screen . getByTestId ( 'email' ) , 'michael@chromatic.com.com@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' ) , 'michael@chromatic.com.com@com' ) ;
40+ await userEvent . type ( canvas . getByTestId ( 'password1' ) , 'testpasswordthatwontfail' ) ;
41+ await userEvent . click ( canvas . getByTestId ( 'submit' ) ) ;
3742 } ,
3843} ;
3944
4045export 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
4956export 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 = {
6271export 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
7182export 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));
8396export 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
0 commit comments