fix: start the quick controls from the selected day's own hours
"Opens later at" and "closes earlier at" were prefilled with 14:00 and 16:00 — arbitrary values, wrong on most days, which left the preview showing hours nobody had asked for until both fields were corrected. They now start from the day's real opening and closing, so any adjustment is relative to what that day actually is. A day with a lunch break is bounded by its first opening and its last closing, which is what these two actions act on. Changing the date changes the hours the times are relative to, so a value typed for Tuesday must not survive into Thursday. The fields live in a component keyed on the date and React resets them by remounting — the React compiler rightly refuses an effect that writes state back, and it is the clearer arrangement anyway. The end-to-end test picks a trading day rather than assuming today is one. The first version guarded the assertions behind a visibility check, which would have passed in silence on exactly the days the controls matter least. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
This commit is contained in:
@@ -6,6 +6,18 @@ async function panelFilename(request: import('@playwright/test').APIRequestConte
|
||||
return ((await response.json()) as { filename: string }).filename;
|
||||
}
|
||||
|
||||
/** The seeded week trades Tuesday to Saturday; Sunday and Monday are closed. */
|
||||
function nextTradingDay(): string {
|
||||
for (let offset = 0; offset < 7; offset += 1) {
|
||||
const date = today(offset);
|
||||
const weekday = new Date(`${date}T00:00:00.000Z`).getUTCDay();
|
||||
if (weekday >= 2) {
|
||||
return date;
|
||||
}
|
||||
}
|
||||
throw new Error('aucun jour ouvré dans les sept prochains jours');
|
||||
}
|
||||
|
||||
test.beforeEach(async () => {
|
||||
await resetDatabase();
|
||||
});
|
||||
@@ -57,6 +69,23 @@ test('a quick change can target a day other than today', async ({ page }) => {
|
||||
expect(exception?.isClosed).toBe(true);
|
||||
});
|
||||
|
||||
test('the quick controls start from the selected day’s own hours', async ({ page }) => {
|
||||
// The seeded week is closed on Sunday and Monday, so the day is chosen
|
||||
// rather than assumed: a conditional assertion would pass in silence on the
|
||||
// days it matters least.
|
||||
const tradingDay = nextTradingDay();
|
||||
|
||||
await signIn(page, 'admin');
|
||||
await page.goto('/admin/exceptions');
|
||||
await page.getByLabel('Jour à modifier').selectOption(tradingDay);
|
||||
|
||||
// An arbitrary 14:00 would be wrong on most days and leave the preview
|
||||
// showing hours nobody asked for.
|
||||
await expect(page.getByLabel('Nouvelle heure d’ouverture')).toHaveValue('10:00');
|
||||
await expect(page.getByLabel('Nouvelle heure de fermeture')).toHaveValue('18:30');
|
||||
await expect(page.getByText('Habituellement 10:00 – 18:30.')).toBeVisible();
|
||||
});
|
||||
|
||||
test('the reference week can be edited and shows what will change', async ({ page }) => {
|
||||
await signIn(page, 'admin');
|
||||
await page.goto('/admin/horaires');
|
||||
|
||||
Reference in New Issue
Block a user