@@ -25,23 +25,33 @@ export const Default: Story = {
2525 name : 'Default' ,
2626 play : async ( { canvasElement, step, args } ) => {
2727 const canvas = within ( canvasElement ) ;
28- const input = canvas . getByRole ( 'radio' ) ;
28+ const input = canvas . getByRole < HTMLInputElement > ( 'radio' ) ;
2929
30- await step ( 'Radio Button handles focus event ' , async ( ) => {
30+ await step ( 'Click radio button ' , async ( ) => {
3131 await expect ( args . onFocus ) . not . toHaveBeenCalled ( ) ;
3232
3333 await userEvent . click ( input ) ;
3434
3535 await expect ( args . onFocus ) . toHaveBeenCalledOnce ( ) ;
36+ await expect ( args . onChange ) . toHaveBeenCalledOnce ( ) ;
37+ await expect ( args . onChange ) . toHaveBeenLastCalledWith ( true , expect . anything ( ) ) ;
38+ await expect ( args . onInput ) . toHaveBeenCalledOnce ( ) ;
39+ await expect ( args . onInput ) . toHaveBeenLastCalledWith ( true , expect . anything ( ) ) ;
40+ await expect ( input . checked ) . toBe ( true ) ;
41+ } ) ;
3642
43+ await step ( 'Click radio button again' , async ( ) => {
3744 await userEvent . click ( input ) ;
3845
3946 await expect ( args . onFocus ) . toHaveBeenCalledOnce ( ) ;
4047 await expect ( args . onChange ) . toHaveBeenCalledOnce ( ) ;
48+ await expect ( args . onChange ) . toHaveBeenLastCalledWith ( true , expect . anything ( ) ) ;
4149 await expect ( args . onInput ) . toHaveBeenCalledOnce ( ) ;
50+ await expect ( args . onInput ) . toHaveBeenLastCalledWith ( true , expect . anything ( ) ) ;
51+ await expect ( input . checked ) . toBe ( true ) ;
4252 } ) ;
4353
44- await step ( 'Radio Button handles blur event ' , async ( ) => {
54+ await step ( 'Click outside checkbox ' , async ( ) => {
4555 await expect ( args . onBlur ) . not . toHaveBeenCalled ( ) ;
4656
4757 await userEvent . click ( canvasElement ) ;
@@ -50,3 +60,35 @@ export const Default: Story = {
5060 } ) ;
5161 } ,
5262} ;
63+
64+ export const UsingLabel : Story = {
65+ name : 'Using Label' ,
66+ play : async ( { canvasElement, step, args } ) => {
67+ const canvas = within ( canvasElement ) ;
68+ const input = canvas . getByRole < HTMLInputElement > ( 'radio' ) ;
69+ const label = canvas . getByText ( 'Radio Button Label' ) ;
70+
71+ await step ( 'Click radio button label' , async ( ) => {
72+ await expect ( args . onFocus ) . not . toHaveBeenCalled ( ) ;
73+
74+ await userEvent . click ( label ) ;
75+
76+ await expect ( args . onFocus ) . toHaveBeenCalledOnce ( ) ;
77+ await expect ( args . onChange ) . toHaveBeenCalledOnce ( ) ;
78+ await expect ( args . onChange ) . toHaveBeenLastCalledWith ( true , expect . anything ( ) ) ;
79+ await expect ( args . onInput ) . toHaveBeenCalledOnce ( ) ;
80+ await expect ( args . onInput ) . toHaveBeenLastCalledWith ( true , expect . anything ( ) ) ;
81+ await expect ( input . checked ) . toBe ( true ) ;
82+ } ) ;
83+
84+ await step ( 'Click radio button label again' , async ( ) => {
85+ await userEvent . click ( label ) ;
86+
87+ await expect ( args . onChange ) . toHaveBeenCalledOnce ( ) ;
88+ await expect ( args . onChange ) . toHaveBeenLastCalledWith ( true , expect . anything ( ) ) ;
89+ await expect ( args . onInput ) . toHaveBeenCalledOnce ( ) ;
90+ await expect ( args . onInput ) . toHaveBeenLastCalledWith ( true , expect . anything ( ) ) ;
91+ await expect ( input . checked ) . toBe ( true ) ;
92+ } ) ;
93+ } ,
94+ } ;
0 commit comments