mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
test(places): cover the place sheet sections, tags, trip lists and the visited filter
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
} from '../../../tests/helpers/placesLibrary';
|
||||
import { OnlineOnlyError } from '../../repo/onlineOnly';
|
||||
import { placesLibraryRepo } from '../../repo/placesLibraryRepo';
|
||||
import { useSaveToCollectionStore } from '../../store/saveToCollectionStore';
|
||||
import type { TranslationFn } from '../../types';
|
||||
import { entryHasPosition, firstOrigin, parseEntryKey, usePlacesLibrary } from './usePlacesLibrary';
|
||||
|
||||
@@ -61,6 +62,7 @@ beforeEach(() => {
|
||||
detail.mockReset();
|
||||
coverPhoto.mockReset();
|
||||
coverPhoto.mockResolvedValue(null);
|
||||
useSaveToCollectionStore.setState({ version: 0 });
|
||||
});
|
||||
|
||||
describe('parseEntryKey and entryHasPosition', () => {
|
||||
@@ -439,3 +441,41 @@ describe('usePlacesLibrary: the cover', () => {
|
||||
expect(firstOrigin([trip], 'own:9')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('usePlacesLibrary: personal tags and outside saves', () => {
|
||||
it('FE-COMP-PLACESLIBHOOK-027: picked tags go to the server, a second pick of one drops it, and reset clears them', async () => {
|
||||
const { result } = await mountLoaded(libraryPage([]));
|
||||
expect(result.current.tagIds).toEqual([]);
|
||||
|
||||
act(() => {
|
||||
result.current.toggleTag(4);
|
||||
result.current.toggleTag(7);
|
||||
});
|
||||
expect(result.current.tagIds).toEqual([4, 7]);
|
||||
expect(result.current.filtered).toBe(true);
|
||||
await waitFor(() =>
|
||||
expect(list).toHaveBeenLastCalledWith({ ...FIRST_PAGE, tag_ids: [4, 7] }, expect.any(AbortSignal))
|
||||
);
|
||||
|
||||
act(() => result.current.toggleTag(4));
|
||||
expect(result.current.tagIds).toEqual([7]);
|
||||
await waitFor(() =>
|
||||
expect(list).toHaveBeenLastCalledWith({ ...FIRST_PAGE, tag_ids: [7] }, expect.any(AbortSignal))
|
||||
);
|
||||
|
||||
act(() => result.current.resetFilters());
|
||||
expect(result.current.tagIds).toEqual([]);
|
||||
expect(result.current.filtered).toBe(false);
|
||||
await waitFor(() => expect(list).toHaveBeenLastCalledWith(FIRST_PAGE, expect.any(AbortSignal)));
|
||||
});
|
||||
|
||||
it('FE-COMP-PLACESLIBHOOK-028: a place saved to a list anywhere reads the overview again', async () => {
|
||||
const { result } = await mountLoaded(libraryPage([]));
|
||||
expect(list).toHaveBeenCalledTimes(1);
|
||||
|
||||
list.mockResolvedValueOnce(libraryPage([libraryEntry()]));
|
||||
act(() => useSaveToCollectionStore.getState().bumpVersion());
|
||||
await waitFor(() => expect(result.current.entries).toHaveLength(1));
|
||||
expect(list).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user