fix(vacay): correct weekend toggling and remove redundant labels

This commit is contained in:
Luffy
2026-11-13 16:07:19 +08:00
committed by Maurice
parent a76a96ccca
commit 75d458b06b
34 changed files with 74 additions and 57 deletions
@@ -51,7 +51,6 @@ export default function VacaySettings({ onClose }: VacaySettingsProps) {
{/* Weekend days selector */}
{plan.block_weekends !== false && (
<div data-testid="weekend-days" style={{ paddingInlineStart: 36 }}>
<p className="text-xs font-medium mb-2 text-content-muted">{t('vacay.weekendDays')}</p>
<div className="flex flex-wrap gap-1.5">
{[
{ day: 1, label: t('vacay.mon') },
@@ -110,6 +110,26 @@ describe('useVacaySettings', () => {
expect(result.current.weekendDays).toEqual([5, 6]);
});
it.each([
[6, 0],
[0, 6],
])('keeps day %i deselected when the last selected day %i is then removed', (first, last) => {
const { result } = renderHook(() => useVacaySettings({ language: 'en', loadCountries: false }));
act(() => result.current.toggleWeekendDay(first));
expect(updatePlan).toHaveBeenLastCalledWith({ weekend_days: String(last) });
act(() => useVacayStore.setState({ plan: plan({ weekend_days: String(last) }) }));
expect(result.current.weekendDays).toEqual([last]);
act(() => result.current.toggleWeekendDay(last));
expect(updatePlan).toHaveBeenLastCalledWith({ weekend_days: String(first) });
act(() => useVacayStore.setState({ plan: plan({ weekend_days: String(first) }) }));
expect(result.current.weekendDays).toEqual([first]);
act(() => result.current.toggleWeekendDay(last));
expect(updatePlan).toHaveBeenLastCalledWith({ weekend_days: `${first},${last}` });
});
it('FE-COMP-VACAYSET-005: dissolving toasts and then hands over', async () => {
const order: string[] = [];
toast.success.mockImplementation(() => order.push('toast'));
@@ -62,6 +62,8 @@ export function useVacaySettings({ language, loadCountries }: { language: string
const weekendDays: number[] = plan?.weekend_days ? String(plan.weekend_days).split(',').map(Number) : [0, 6];
const toggleWeekendDay = (day: number) => {
const next = weekendDays.includes(day) ? weekendDays.filter((d) => d !== day) : [...weekendDays, day];
// An empty value restores both default days, including the day just deselected.
if (next.length === 0) next.push(...[0, 6].filter((d) => d !== day));
updatePlan({ weekend_days: next.join(',') });
};