updates on the minor changes like zone updates and datepicker fix

This commit is contained in:
2026-09-28 15:36:59 +05:30
parent 3bde09839c
commit 5bf0104b61
8 changed files with 284 additions and 22 deletions

View File

@@ -122,3 +122,72 @@ describe('DatePicker — the popover after a choice', () => {
expect(screen.queryByText('This Month')).not.toBeInTheDocument();
});
});
/**
* rangeSelect (Orders Summary): the first calendar click used to commit a
* single day and close the popover, so an operator could never pick a from
* AND a to date. With rangeSelect the first click only marks the start.
*/
describe('DatePicker — rangeSelect', () => {
// A month well in the past, so every day in it is selectable under maxDate.
const month = today.subtract(2, 'month').startOf('month');
const day = (n) => month.date(n).format('YYYY-MM-DD');
const dayButton = (n) =>
screen.getAllByRole('button', { name: String(n) }).find((b) => !b.className.includes('text-ink-4/40'));
const openRangePicker = (onChange, extra = {}) => {
render(<DatePicker value={{ from: day(1), to: day(1) }} onChange={onChange} rangeSelect maxDate={todayStr} {...extra} />);
openCalendar();
};
it('keeps the calendar open after the first click and emits nothing yet', () => {
const onChange = jest.fn();
openRangePicker(onChange);
fireEvent.click(dayButton(5));
expect(onChange).not.toHaveBeenCalled();
expect(screen.getByText(/now pick the end date/i)).toBeInTheDocument();
});
it('emits { from, to } on the second click and closes', () => {
const onChange = jest.fn();
openRangePicker(onChange);
fireEvent.click(dayButton(5));
fireEvent.click(dayButton(12));
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith({ from: day(5), to: day(12) });
expect(screen.queryByText(/pick the end date/i)).not.toBeInTheDocument();
});
it('orders the two clicks when the end is picked before the start', () => {
const onChange = jest.fn();
openRangePicker(onChange);
fireEvent.click(dayButton(20));
fireEvent.click(dayButton(3));
expect(onChange).toHaveBeenCalledWith({ from: day(3), to: day(20) });
});
it('greys out and ignores days after maxDate', () => {
const onChange = jest.fn();
render(<DatePicker value={todayStr} onChange={onChange} rangeSelect maxDate={todayStr} />);
openCalendar();
const tomorrow = today.add(1, 'day');
// Only assert when tomorrow is visible in this month's grid.
const btn = screen
.getAllByRole('button', { name: String(tomorrow.date()) })
.find((b) => b.disabled);
if (tomorrow.month() === today.month()) {
expect(btn).toBeDefined();
fireEvent.click(btn);
fireEvent.click(btn);
expect(onChange).not.toHaveBeenCalled();
}
});
it('leaves the default (single-click) pickers unchanged', () => {
const onChange = jest.fn();
render(<DatePicker value={todayStr} onChange={onChange} />);
openCalendar();
fireEvent.click(screen.getByText('Yesterday'));
expect(onChange).toHaveBeenCalledWith(today.subtract(1, 'day').format('YYYY-MM-DD'));
});
});