Skip to content

Commit ac573bb

Browse files
ivicacclaude
andcommitted
732 client - Fix DateTimePicker test flakiness by anchoring calendar to selected date
Pass `defaultMonth={date}` to Calendar so the popover opens at the selected date's month instead of today's month. Use `getByLabelText` with the full accessible name to disambiguate from outside-day collisions where the same numeric label appears in adjacent months. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4241508 commit ac573bb

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

client/src/components/DateTimePicker/DateTimePicker.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ describe('DateTimePicker', () => {
3030

3131
await userEvent.click(trigger);
3232

33-
// Calendar should be visible.
34-
// We look for a day, e.g., 26th.
35-
const day26 = screen.getByText('26');
33+
const day26 = screen.getByLabelText('Tuesday, December 26th, 2023');
3634

3735
await userEvent.click(day26);
3836

client/src/components/DateTimePicker/DateTimePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function DateTimePicker({onChange, value}: {onChange: (date: Date
5757
</PopoverTrigger>
5858

5959
<PopoverContent align="start" className="w-auto p-0">
60-
<Calendar autoFocus mode="single" onSelect={handleSelect} selected={date} />
60+
<Calendar autoFocus defaultMonth={date} mode="single" onSelect={handleSelect} selected={date} />
6161

6262
<div className="border-t p-3">
6363
<input

0 commit comments

Comments
 (0)