mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +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,7 +1,7 @@
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { useListsSubTab } from './useListsSubTab';
|
||||
import { rememberListsSubTab, useListsSubTab } from './useListsSubTab';
|
||||
|
||||
// FE-HOOK-LISTSTAB-001 to FE-HOOK-LISTSTAB-006
|
||||
|
||||
@@ -47,3 +47,40 @@ describe('useListsSubTab', () => {
|
||||
expect(renderHook(() => useListsSubTab(3, { onlyKnownTabs: true })).result.current[0]).toBe('todo');
|
||||
});
|
||||
});
|
||||
|
||||
// FE-HOOK-LISTSTAB-007 to FE-HOOK-LISTSTAB-009: picking the sub-tab from outside the Lists tab.
|
||||
describe('rememberListsSubTab', () => {
|
||||
it('FE-HOOK-LISTSTAB-007: the Lists tab opens on the sub-tab picked before it was on screen', () => {
|
||||
sessionStorage.setItem('trip-lists-subtab-7', 'todo');
|
||||
rememberListsSubTab(7, 'packing');
|
||||
expect(renderHook(() => useListsSubTab(7)).result.current[0]).toBe('packing');
|
||||
});
|
||||
|
||||
it('FE-HOOK-LISTSTAB-008: a Lists tab already on screen follows, one for another trip does not', () => {
|
||||
sessionStorage.setItem('trip-lists-subtab-7', 'todo');
|
||||
sessionStorage.setItem('trip-lists-subtab-8', 'todo');
|
||||
const same = renderHook(() => useListsSubTab(7));
|
||||
const other = renderHook(() => useListsSubTab(8));
|
||||
act(() => rememberListsSubTab(7, 'packing'));
|
||||
expect(same.result.current[0]).toBe('packing');
|
||||
expect(other.result.current[0]).toBe('todo');
|
||||
same.unmount();
|
||||
act(() => rememberListsSubTab(7, 'todo'));
|
||||
expect(sessionStorage.getItem('trip-lists-subtab-7')).toBe('todo');
|
||||
});
|
||||
|
||||
it('FE-HOOK-LISTSTAB-009: blocked storage still switches the tab on screen and does not throw', () => {
|
||||
const { result } = renderHook(() => useListsSubTab(7));
|
||||
const setItem = vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
||||
throw new Error('blocked');
|
||||
});
|
||||
const getItem = vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
||||
throw new Error('blocked');
|
||||
});
|
||||
act(() => rememberListsSubTab(7, 'todo'));
|
||||
expect(result.current[0]).toBe('todo');
|
||||
expect(renderHook(() => useListsSubTab(9)).result.current[0]).toBe('packing');
|
||||
setItem.mockRestore();
|
||||
getItem.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user