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:
@@ -1,6 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { checkRange, earlyClosing, expandRange, lateOpening, MAX_RANGE_DAYS } from './exceptions';
|
||||
import {
|
||||
checkRange,
|
||||
earlyClosing,
|
||||
expandRange,
|
||||
lateOpening,
|
||||
MAX_RANGE_DAYS,
|
||||
usualBounds,
|
||||
} from './exceptions';
|
||||
import type { Slot } from './types';
|
||||
|
||||
const FULL: Slot[] = [{ open: '10:00', close: '18:30' }];
|
||||
@@ -130,3 +137,32 @@ describe('checkRange', () => {
|
||||
expect(checkRange('2026-01-01', '2030-01-01')).toBe('TOO_LONG');
|
||||
});
|
||||
});
|
||||
|
||||
describe('usualBounds', () => {
|
||||
it('takes the times of a single period', () => {
|
||||
expect(usualBounds([{ open: '11:00', close: '18:00' }])).toEqual({
|
||||
open: '11:00',
|
||||
close: '18:00',
|
||||
});
|
||||
});
|
||||
|
||||
it('spans a day with a lunch break from first opening to last closing', () => {
|
||||
// "Opens later" and "closes earlier" act on the day as a whole.
|
||||
expect(usualBounds(SPLIT)).toEqual({ open: '10:00', close: '18:30' });
|
||||
});
|
||||
|
||||
it('falls back to usable times on a closed day', () => {
|
||||
// The controls are hidden there, but the inputs must still hold a value.
|
||||
expect(usualBounds([])).toEqual({ open: '10:00', close: '18:00' });
|
||||
});
|
||||
|
||||
it('handles three periods', () => {
|
||||
expect(
|
||||
usualBounds([
|
||||
{ open: '09:30', close: '12:00' },
|
||||
{ open: '13:30', close: '16:00' },
|
||||
{ open: '17:00', close: '19:30' },
|
||||
]),
|
||||
).toEqual({ open: '09:30', close: '19:30' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user