mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
fix(tours): open a tour's packing list on Packing, and ask before letting go of it while Packing is off
"Open packing list" switched to the Lists tab but left it on whichever sub-tab was open last, so someone who had been in the to-dos landed there. It now picks the packing side first, and a Lists tab already on screen follows the choice; storage that is blocked no longer throws either. With the Packing addon off, "Remove link" let go of the link on one click, and the link cannot be made again until Packing is back on. It now opens the tour's packing dialog with only the dimmed link and the Remove link and Cancel buttons, so nothing changes without a second, deliberate click.
This commit is contained in:
@@ -1,17 +1,33 @@
|
||||
// P2D-XD-01: from a tour's packing link to the trip's Lists tab, the tour's detail closed on the way.
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { useListsSubTab } from '../../hooks/useListsSubTab';
|
||||
import { useTourDetailActions } from './useTourDetailActions';
|
||||
import type { useTripPlanner } from './useTripPlanner';
|
||||
|
||||
describe('useTourDetailActions', () => {
|
||||
const planner = () => ({ tripId: 5, setSelectedPlaceId: vi.fn(), handleTabChange: vi.fn() });
|
||||
const actions = (p: ReturnType<typeof planner>) =>
|
||||
renderHook(() => useTourDetailActions(p as unknown as ReturnType<typeof useTripPlanner>)).result.current;
|
||||
|
||||
it('FE-TOUR-DETAIL-ACTIONS-001: opening the packing list closes the tour and switches to the Lists tab', () => {
|
||||
const planner = { setSelectedPlaceId: vi.fn(), handleTabChange: vi.fn() };
|
||||
const { result } = renderHook(() =>
|
||||
useTourDetailActions(planner as unknown as ReturnType<typeof useTripPlanner>)
|
||||
);
|
||||
result.current.onOpenPacking();
|
||||
expect(planner.setSelectedPlaceId).toHaveBeenCalledWith(null);
|
||||
expect(planner.handleTabChange).toHaveBeenCalledWith('listen');
|
||||
const p = planner();
|
||||
actions(p).onOpenPacking();
|
||||
expect(p.setSelectedPlaceId).toHaveBeenCalledWith(null);
|
||||
expect(p.handleTabChange).toHaveBeenCalledWith('listen');
|
||||
});
|
||||
|
||||
it('FE-TOUR-DETAIL-ACTIONS-002: the Lists tab opens on packing even when the to-dos were last open', () => {
|
||||
sessionStorage.setItem('trip-lists-subtab-5', 'todo');
|
||||
actions(planner()).onOpenPacking();
|
||||
expect(renderHook(() => useListsSubTab(5)).result.current[0]).toBe('packing');
|
||||
});
|
||||
|
||||
it('FE-TOUR-DETAIL-ACTIONS-003: a Lists tab already on screen on the to-dos switches to packing', () => {
|
||||
sessionStorage.setItem('trip-lists-subtab-5', 'todo');
|
||||
const lists = renderHook(() => useListsSubTab(5));
|
||||
expect(lists.result.current[0]).toBe('todo');
|
||||
act(() => actions(planner()).onOpenPacking());
|
||||
expect(lists.result.current[0]).toBe('packing');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { TourListItem } from '@trek/shared';
|
||||
import { rememberListsSubTab } from '../../hooks/useListsSubTab';
|
||||
import { tourRepo } from '../../repo/tourRepo';
|
||||
import { useTripStore } from '../../store/tripStore';
|
||||
import type { Place } from '../../types';
|
||||
@@ -36,9 +37,10 @@ export function useTourDetailActions(planner: ReturnType<typeof useTripPlanner>)
|
||||
onToursChanged: (placeIds: number[]) => invalidateTourPlaceIds({ placeIds }),
|
||||
/** LIB-02: a tour taken over from another trip; the tours rail opens it in the planner. */
|
||||
onTakenOver: bringIn,
|
||||
/** P2D-XD-01: the packing list a tour points at, in the trip's Lists tab. */
|
||||
/** P2D-XD-01: the packing list a tour points at, in the trip's Lists tab, on its packing side. */
|
||||
onOpenPacking: () => {
|
||||
planner.setSelectedPlaceId(null);
|
||||
rememberListsSubTab(tripId, 'packing');
|
||||
planner.handleTabChange('listen');
|
||||
},
|
||||
onSaveAsNew: async (tour: TourListItem) => {
|
||||
|
||||
Reference in New Issue
Block a user