mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +00:00
fix(vacay): correct weekend toggling and remove redundant labels
This commit is contained in:
@@ -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(',') });
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user