@@ -8,9 +8,6 @@ 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-
1411const formSchema = z . object ( {
1512 date : z . coerce . date ( {
1613 required_error : 'Please select a date' ,
@@ -128,19 +125,9 @@ export const Default: Story = {
128125 const dialog = await within ( document . body ) . findByRole ( 'dialog' ) ;
129126 const dialogCanvas = within ( dialog ) ;
130127
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 ) ;
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 ) ;
144131 } ) ;
145132
146133 await step ( 'Submit form and verify success' , async ( ) => {
@@ -150,8 +137,7 @@ export const Default: Story = {
150137
151138 // Verify submission with comprehensive assertions
152139 await expect ( canvas . findByText ( 'Submitted with date:' ) ) . 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 ( ) ;
140+ await expect ( canvas . findByText ( / 6 \/ 1 \/ 2 0 2 5 | 1 \/ 6 \/ 2 0 2 5 / ) ) . resolves . toBeInTheDocument ( ) ;
155141 } ) ;
156142 } ,
157143} ;
0 commit comments