@@ -2,7 +2,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
22import { PasswordField } from '@lambdacurry/forms/remix-hook-form/password-field' ;
33import { Button } from '@lambdacurry/forms/ui/button' ;
44import type { Meta , StoryContext , StoryObj } from '@storybook/react-vite' ;
5- import { expect , userEvent } from '@storybook/test' ;
5+ import { expect , userEvent , within } from '@storybook/test' ;
66import { useRef } from 'react' ;
77import { type ActionFunctionArgs , useFetcher } from 'react-router' ;
88import { getValidatedFormData , RemixFormProvider , useRemixForm } from 'remix-hook-form' ;
@@ -114,14 +114,16 @@ export default meta;
114114type Story = StoryObj < typeof meta > ;
115115
116116// Test scenarios
117- const testDefaultValues = ( { canvas } : StoryContext ) => {
117+ const testDefaultValues = ( { canvasElement } : StoryContext ) => {
118+ const canvas = within ( canvasElement ) ;
118119 const passwordInput = canvas . getByLabelText ( 'Password' ) ;
119120 const confirmInput = canvas . getByLabelText ( 'Confirm Password' ) ;
120121 expect ( passwordInput ) . toHaveValue ( INITIAL_PASSWORD ) ;
121122 expect ( confirmInput ) . toHaveValue ( INITIAL_PASSWORD ) ;
122123} ;
123124
124- const testPasswordVisibilityToggle = async ( { canvas } : StoryContext ) => {
125+ const testPasswordVisibilityToggle = async ( { canvasElement } : StoryContext ) => {
126+ const canvas = within ( canvasElement ) ;
125127 const passwordInput = canvas . getByLabelText ( 'Password' ) ;
126128
127129 // Find the toggle button within the same form item as the password input
@@ -150,7 +152,8 @@ const testPasswordVisibilityToggle = async ({ canvas }: StoryContext) => {
150152 expect ( showButtonAgain ) . toBeInTheDocument ( ) ;
151153} ;
152154
153- const testWeakPasswordValidation = async ( { canvas } : StoryContext ) => {
155+ const testWeakPasswordValidation = async ( { canvasElement } : StoryContext ) => {
156+ const canvas = within ( canvasElement ) ;
154157 const passwordInput = canvas . getByLabelText ( 'Password' ) ;
155158 const submitButton = canvas . getByRole ( 'button' , { name : 'Create Account' } ) ;
156159
@@ -162,7 +165,8 @@ const testWeakPasswordValidation = async ({ canvas }: StoryContext) => {
162165 await expect ( await canvas . findByText ( WEAK_PASSWORD_ERROR ) ) . toBeInTheDocument ( ) ;
163166} ;
164167
165- const testPasswordMismatchValidation = async ( { canvas } : StoryContext ) => {
168+ const testPasswordMismatchValidation = async ( { canvasElement } : StoryContext ) => {
169+ const canvas = within ( canvasElement ) ;
166170 const passwordInput = canvas . getByLabelText ( 'Password' ) ;
167171 const confirmInput = canvas . getByLabelText ( 'Confirm Password' ) ;
168172 const submitButton = canvas . getByRole ( 'button' , { name : 'Create Account' } ) ;
@@ -180,7 +184,8 @@ const testPasswordMismatchValidation = async ({ canvas }: StoryContext) => {
180184 await expect ( await canvas . findByText ( MISMATCH_PASSWORD_ERROR ) ) . toBeInTheDocument ( ) ;
181185} ;
182186
183- const testValidSubmission = async ( { canvas } : StoryContext ) => {
187+ const testValidSubmission = async ( { canvasElement } : StoryContext ) => {
188+ const canvas = within ( canvasElement ) ;
184189 const passwordInput = canvas . getByLabelText ( 'Password' ) ;
185190 const confirmInput = canvas . getByLabelText ( 'Confirm Password' ) ;
186191 const submitButton = canvas . getByRole ( 'button' , { name : 'Create Account' } ) ;
@@ -199,7 +204,8 @@ const testValidSubmission = async ({ canvas }: StoryContext) => {
199204 expect ( successMessage ) . toBeInTheDocument ( ) ;
200205} ;
201206
202- const testRefFunctionality = async ( { canvas } : StoryContext ) => {
207+ const testRefFunctionality = async ( { canvasElement } : StoryContext ) => {
208+ const canvas = within ( canvasElement ) ;
203209 const refInput = canvas . getByLabelText ( 'Ref Example' ) ;
204210 const focusButton = canvas . getByRole ( 'button' , { name : 'Focus' } ) ;
205211
0 commit comments