@@ -4,7 +4,7 @@ import { useOnFormValueChange } from '@lambdacurry/forms/remix-hook-form/hooks/u
44import { Select } from '@lambdacurry/forms/remix-hook-form/select' ;
55import { TextField } from '@lambdacurry/forms/remix-hook-form/text-field' ;
66import type { Meta , StoryContext , StoryObj } from '@storybook/react-vite' ;
7- import { expect , userEvent , within } from '@storybook/test' ;
7+ import { expect , userEvent , within , screen } from '@storybook/test' ;
88import { useState } from 'react' ;
99import { type ActionFunctionArgs , useFetcher } from 'react-router' ;
1010import { getValidatedFormData , RemixFormProvider , useRemixForm } from 'remix-hook-form' ;
@@ -87,6 +87,7 @@ const CascadingDropdownExample = () => {
8787 // When country changes, update available states and reset state selection
8888 useOnFormValueChange ( {
8989 name : 'country' ,
90+ methods,
9091 onChange : ( value ) => {
9192 const states = statesByCountry [ value ] || [ ] ;
9293 setAvailableStates ( states ) ;
@@ -160,7 +161,7 @@ export const CascadingDropdowns: Story = {
160161 await userEvent . click ( countryTrigger ) ;
161162
162163 // Wait for dropdown to open and select USA
163- const usaOption = await canvas . findByRole ( ' option' , { name : / u n i t e d s t a t e s / i } ) ;
164+ const usaOption = await screen . findByTestId ( 'select- option-usa' ) ;
164165 await userEvent . click ( usaOption ) ;
165166
166167 // Verify state dropdown is now enabled
@@ -169,7 +170,7 @@ export const CascadingDropdowns: Story = {
169170
170171 // Select a state
171172 await userEvent . click ( stateTrigger ) ;
172- const californiaOption = await canvas . findByRole ( ' option' , { name : / c a l i f o r n i a / i } ) ;
173+ const californiaOption = await screen . findByTestId ( 'select- option- california' ) ;
173174 await userEvent . click ( californiaOption ) ;
174175
175176 // Enter city
@@ -240,18 +241,21 @@ const AutoCalculationExample = () => {
240241 // Recalculate when quantity changes
241242 useOnFormValueChange ( {
242243 name : 'quantity' ,
244+ methods,
243245 onChange : calculateTotal ,
244246 } ) ;
245247
246248 // Recalculate when price changes
247249 useOnFormValueChange ( {
248250 name : 'pricePerUnit' ,
251+ methods,
249252 onChange : calculateTotal ,
250253 } ) ;
251254
252255 // Recalculate when discount changes
253256 useOnFormValueChange ( {
254257 name : 'discount' ,
258+ methods,
255259 onChange : calculateTotal ,
256260 } ) ;
257261
@@ -395,6 +399,7 @@ const ConditionalFieldsExample = () => {
395399 // Show/hide fields based on delivery type
396400 useOnFormValueChange ( {
397401 name : 'deliveryType' ,
402+ methods,
398403 onChange : ( value ) => {
399404 setShowShipping ( value === 'delivery' ) ;
400405 setShowPickup ( value === 'pickup' ) ;
@@ -480,7 +485,7 @@ export const ConditionalFields: Story = {
480485 const deliveryTypeTrigger = canvas . getByRole ( 'combobox' , { name : / d e l i v e r y t y p e / i } ) ;
481486 await userEvent . click ( deliveryTypeTrigger ) ;
482487
483- const deliveryOption = await canvas . findByRole ( ' option' , { name : / h o m e d e l i v e r y / i } ) ;
488+ const deliveryOption = await screen . findByTestId ( 'select- option- delivery' ) ;
484489 await userEvent . click ( deliveryOption ) ;
485490
486491 // Shipping address field should appear
@@ -489,8 +494,10 @@ export const ConditionalFields: Story = {
489494 await userEvent . type ( shippingInput , '123 Main St' ) ;
490495
491496 // Switch to pickup
492- await userEvent . click ( deliveryTypeTrigger ) ;
493- const pickupOption = await canvas . findByRole ( 'option' , { name : / s t o r e p i c k u p / i } ) ;
497+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
498+ await userEvent . click ( canvas . getByRole ( 'combobox' , { name : / d e l i v e r y t y p e / i } ) ) ;
499+ await screen . findByRole ( 'listbox' ) ;
500+ const pickupOption = await screen . findByTestId ( 'select-option-pickup' ) ;
494501 await userEvent . click ( pickupOption ) ;
495502
496503 // Store location should appear, shipping address should be gone
@@ -499,7 +506,7 @@ export const ConditionalFields: Story = {
499506
500507 // Select a store
501508 await userEvent . click ( storeSelect ) ;
502- const mallOption = await canvas . findByRole ( ' option' , { name : / s h o p p i n g m a l l / i } ) ;
509+ const mallOption = await screen . findByTestId ( 'select- option- mall' ) ;
503510 await userEvent . click ( mallOption ) ;
504511
505512 // Submit form
0 commit comments