@@ -8,6 +8,9 @@ import { RemixFormProvider, createFormData, getValidatedFormData, useRemixForm }
88import { z } from 'zod' ;
99import { withReactRouterStubDecorator } from '../lib/storybook/react-router-stub' ;
1010
11+ // Regex for finding day buttons in calendar
12+ const DAY_BUTTON_REGEX = / ^ \d + $ / ;
13+
1114const formSchema = z . object ( {
1215 date : z . coerce . date ( {
1316 required_error : 'Please select a date' ,
@@ -125,9 +128,19 @@ export const Default: Story = {
125128 const dialog = await within ( document . body ) . findByRole ( 'dialog' ) ;
126129 const dialogCanvas = within ( dialog ) ;
127130
128- // Find a specific day button in the calendar using complete aria-label to avoid ambiguity
129- const dayButton = await dialogCanvas . findByRole ( 'button' , { name : 'Sunday, June 1st, 2025' } ) ;
130- await userEvent . click ( dayButton ) ;
131+ // Find any available day button in the calendar (look for a button with a number)
132+ // We'll look for any day button that's not disabled
133+ const dayButtons = await dialogCanvas . findAllByRole ( 'button' ) ;
134+ const availableDayButton = dayButtons . find ( button => {
135+ const text = button . textContent ;
136+ return text && DAY_BUTTON_REGEX . test ( text . trim ( ) ) && ! button . hasAttribute ( 'disabled' ) ;
137+ } ) ;
138+
139+ if ( ! availableDayButton ) {
140+ throw new Error ( 'No available day button found in calendar' ) ;
141+ }
142+
143+ await userEvent . click ( availableDayButton ) ;
131144 } ) ;
132145
133146 await step ( 'Submit form and verify success' , async ( ) => {
@@ -137,7 +150,8 @@ export const Default: Story = {
137150
138151 // Verify submission with comprehensive assertions
139152 await expect ( canvas . findByText ( 'Submitted with date:' ) ) . resolves . toBeInTheDocument ( ) ;
140- await expect ( canvas . findByText ( / 6 \/ 1 \/ 2 0 2 5 | 1 \/ 6 \/ 2 0 2 5 / ) ) . resolves . toBeInTheDocument ( ) ;
153+ // Check for any date format (MM/DD/YYYY or DD/MM/YYYY)
154+ await expect ( canvas . findByText ( / \d { 1 , 2 } \/ \d { 1 , 2 } \/ \d { 4 } / ) ) . resolves . toBeInTheDocument ( ) ;
141155 } ) ;
142156 } ,
143157} ;
0 commit comments