mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
test(places): cover the place sheet sections, tags, trip lists and the visited filter
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
// FE-MOB-ENTRYTAGS-001 to FE-MOB-ENTRYTAGS-006: the reader's own tags on a place in the
|
||||
// phone sheet of All places (PLC-21), rendered against a mocked useEntryTags.
|
||||
import type { Tag } from '@trek/shared';
|
||||
|
||||
import { bothOrigins } from '../../../../tests/helpers/placesLibrary';
|
||||
import { fireEvent, render, screen } from '../../../../tests/helpers/render';
|
||||
import type { useEntryTags } from '../../../components/Collections/useEntryTags';
|
||||
import MEntryTagsSection from './MEntryTagsSection';
|
||||
|
||||
type EntryTags = ReturnType<typeof useEntryTags>;
|
||||
|
||||
const hook = vi.hoisted(() => ({ state: null as unknown as EntryTags, args: [] as unknown[] }));
|
||||
vi.mock('../../../components/Collections/useEntryTags', () => ({
|
||||
useEntryTags: (args: unknown) => {
|
||||
hook.args.push(args);
|
||||
return hook.state;
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('../../../components/shared/ConfirmDialog', () => ({
|
||||
default: ({ isOpen, onConfirm, title }: { isOpen: boolean; onConfirm: () => void; title: string }) =>
|
||||
isOpen ? (
|
||||
<div role="dialog" aria-label={title}>
|
||||
<button type="button" onClick={onConfirm}>
|
||||
confirm
|
||||
</button>
|
||||
</div>
|
||||
) : null,
|
||||
}));
|
||||
|
||||
const t = (k: string, p?: Record<string, unknown>) => (p ? `${k}:${JSON.stringify(p)}` : k);
|
||||
|
||||
const tag = (id: number, name: string, color = '#aa0000'): Tag => ({ id, user_id: 1, trip_id: null, name, color });
|
||||
const BEACH = tag(1, 'Beach');
|
||||
const WINE = tag(3, 'Wine', '');
|
||||
|
||||
function state(over: Partial<EntryTags> = {}): EntryTags {
|
||||
return {
|
||||
all: [BEACH, WINE],
|
||||
assigned: [],
|
||||
assignedIds: [],
|
||||
query: '',
|
||||
setQuery: vi.fn(),
|
||||
matches: [BEACH, WINE],
|
||||
canCreate: false,
|
||||
toggle: vi.fn(() => Promise.resolve()),
|
||||
createAndAdd: vi.fn(() => Promise.resolve()),
|
||||
rename: vi.fn(() => Promise.resolve()),
|
||||
destroy: vi.fn(() => Promise.resolve()),
|
||||
busy: false,
|
||||
...over,
|
||||
};
|
||||
}
|
||||
|
||||
function mount(over: Partial<EntryTags> = {}) {
|
||||
hook.state = state(over);
|
||||
render(<MEntryTagsSection data={bothOrigins()} onChanged={vi.fn()} t={t} />);
|
||||
return hook.state;
|
||||
}
|
||||
|
||||
const openPicker = () => fireEvent.click(screen.getByRole('button', { name: 'placeTags.add' }));
|
||||
|
||||
beforeEach(() => {
|
||||
hook.args.length = 0;
|
||||
});
|
||||
|
||||
describe('MEntryTagsSection', () => {
|
||||
it('FE-MOB-ENTRYTAGS-001: says the tags are private until the picker opens, and the button closes it again', () => {
|
||||
mount();
|
||||
expect(screen.getByText('placeTags.private')).toBeInTheDocument();
|
||||
openPicker();
|
||||
expect(screen.queryByText('placeTags.private')).toBeNull();
|
||||
const close = screen.getByRole('button', { name: 'common.close' });
|
||||
expect(close).toHaveAttribute('aria-expanded', 'true');
|
||||
fireEvent.click(close);
|
||||
expect(screen.queryByRole('textbox', { name: 'placeTags.search' })).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-MOB-ENTRYTAGS-002: shows the carried tags as chips and ticks them in the picker', () => {
|
||||
const tags = mount({ assigned: [{ id: 3, name: 'Wine', color: null }], assignedIds: [3] });
|
||||
expect(screen.getByText('Wine')).toBeInTheDocument();
|
||||
openPicker();
|
||||
expect(screen.getByRole('button', { name: 'Wine' })).toHaveAttribute('aria-pressed', 'true');
|
||||
expect(screen.getByRole('button', { name: 'Beach' })).toHaveAttribute('aria-pressed', 'false');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Beach' }));
|
||||
expect(tags.toggle).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
it('FE-MOB-ENTRYTAGS-003: types into the search and makes a new tag from it by tap or Enter', () => {
|
||||
const tags = mount({ query: ' Rooftop ', matches: [], canCreate: true });
|
||||
openPicker();
|
||||
const search = screen.getByRole('textbox', { name: 'placeTags.search' });
|
||||
fireEvent.change(search, { target: { value: 'R' } });
|
||||
expect(tags.setQuery).toHaveBeenCalledWith('R');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'placeTags.create:{"name":"Rooftop"}' }));
|
||||
fireEvent.submit(search);
|
||||
expect(tags.createAndAdd).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('FE-MOB-ENTRYTAGS-004: no match and nothing to make says so, and Enter makes nothing', () => {
|
||||
const tags = mount({ query: 'zz', matches: [] });
|
||||
openPicker();
|
||||
expect(screen.getByText('placeTags.none')).toBeInTheDocument();
|
||||
fireEvent.submit(screen.getByRole('textbox', { name: 'placeTags.search' }));
|
||||
expect(tags.createAndAdd).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('FE-MOB-ENTRYTAGS-005: renames a tag in place, or cancels', () => {
|
||||
const tags = mount();
|
||||
openPicker();
|
||||
fireEvent.click(screen.getAllByRole('button', { name: 'placeTags.rename' })[1]);
|
||||
const input = screen.getByRole('textbox', { name: 'placeTags.rename' });
|
||||
expect(input).toHaveValue('Wine');
|
||||
fireEvent.change(input, { target: { value: 'Red wine' } });
|
||||
fireEvent.submit(input);
|
||||
expect(tags.rename).toHaveBeenCalledWith(3, 'Red wine');
|
||||
|
||||
fireEvent.click(screen.getAllByRole('button', { name: 'placeTags.rename' })[0]);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.cancel' }));
|
||||
expect(screen.queryByRole('textbox', { name: 'placeTags.rename' })).toBeNull();
|
||||
expect(tags.rename).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('FE-MOB-ENTRYTAGS-006: deleting asks first and then deletes the tag', () => {
|
||||
const tags = mount();
|
||||
openPicker();
|
||||
fireEvent.click(screen.getAllByRole('button', { name: 'placeTags.delete' })[0]);
|
||||
expect(screen.getByRole('dialog', { name: 'placeTags.deleteTitle:{"name":"Beach"}' })).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'confirm' }));
|
||||
expect(tags.destroy).toHaveBeenCalledWith(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
// FE-MOB-ORIGINNOTES-001 to FE-MOB-ORIGINNOTES-004: the notes of a place on the phone sheet.
|
||||
import type { PlacesLibraryDetailResponse } from '@trek/shared';
|
||||
import type { MockInstance } from 'vitest';
|
||||
|
||||
import {
|
||||
libraryDetail,
|
||||
libraryEntry,
|
||||
listDetail,
|
||||
listOrigin,
|
||||
tripDetail,
|
||||
tripOrigin,
|
||||
} from '../../../../tests/helpers/placesLibrary';
|
||||
import { fireEvent, render, screen, waitFor } from '../../../../tests/helpers/render';
|
||||
import { placesLibraryRepo } from '../../../repo/placesLibraryRepo';
|
||||
import MOriginNotesSection from './MOriginNotesSection';
|
||||
|
||||
const toastError = vi.hoisted(() => vi.fn());
|
||||
vi.mock('../../../components/shared/Toast', () => {
|
||||
const toast = { error: toastError, success: vi.fn(), warning: vi.fn(), info: vi.fn() };
|
||||
return { useToast: () => toast };
|
||||
});
|
||||
|
||||
const t = (k: string, p?: Record<string, unknown>) => (p ? `${k}:${JSON.stringify(p)}` : k);
|
||||
|
||||
function data(listNotes: string | null, canEdit = true): PlacesLibraryDetailResponse {
|
||||
const entry = libraryEntry({
|
||||
origins: [tripOrigin({ can_edit: canEdit }), listOrigin({ can_edit: canEdit })],
|
||||
});
|
||||
return libraryDetail(entry, [tripDetail(), listDetail({ notes: listNotes })]);
|
||||
}
|
||||
|
||||
let saveNotes: MockInstance<typeof placesLibraryRepo.saveNotes>;
|
||||
|
||||
beforeEach(() => {
|
||||
toastError.mockReset();
|
||||
saveNotes = vi.spyOn(placesLibraryRepo, 'saveNotes').mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('MOriginNotesSection', () => {
|
||||
it('FE-MOB-ORIGINNOTES-001: nothing to read and nowhere to write leaves the section out', () => {
|
||||
const { container } = render(<MOriginNotesSection data={data(null, false)} onSaved={vi.fn()} t={t} />);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it('FE-MOB-ORIGINNOTES-002: a read-only note shows its text and source, without pencil or plus', () => {
|
||||
render(<MOriginNotesSection data={data('Ask for Marco', false)} onSaved={vi.fn()} t={t} />);
|
||||
expect(screen.getByText('COLLECTIONS.NOTES')).toBeInTheDocument();
|
||||
expect(screen.getByText('Favourites')).toBeInTheDocument();
|
||||
expect(screen.getByText('Ask for Marco')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'placeNotes.edit' })).toBeNull();
|
||||
expect(screen.queryByRole('button', { name: 'placeNotes.add' })).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-MOB-ORIGINNOTES-003: edits a note and saves the change, a failure toasts and keeps it open', async () => {
|
||||
const onSaved = vi.fn();
|
||||
saveNotes.mockRejectedValueOnce(new Error('offline'));
|
||||
render(<MOriginNotesSection data={data('Ask for Marco')} onSaved={onSaved} t={t} />);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'placeNotes.edit' }));
|
||||
const field = screen.getByRole('textbox', { name: 'placeNotes.fieldLabel:{"source":"Favourites"}' });
|
||||
expect(field).toHaveValue('Ask for Marco');
|
||||
fireEvent.change(field, { target: { value: 'Ask for Giulia' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.save' }));
|
||||
await waitFor(() => expect(toastError).toHaveBeenCalledWith('common.error'));
|
||||
expect(screen.getByRole('textbox')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.save' }));
|
||||
await waitFor(() => expect(onSaved).toHaveBeenCalledTimes(1));
|
||||
expect(saveNotes).toHaveBeenLastCalledWith({ kind: 'list', collection_place_id: 900 }, 'Ask for Giulia');
|
||||
expect(screen.queryByRole('textbox')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-MOB-ORIGINNOTES-004: the plus asks where with several empty places, a pick opens it and cancel closes it', () => {
|
||||
render(<MOriginNotesSection data={data(null)} onSaved={vi.fn()} t={t} />);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'placeNotes.add' }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /Rome 2026/ }));
|
||||
expect(screen.getByRole('textbox', { name: 'placeNotes.fieldLabel:{"source":"Rome 2026"}' })).toHaveValue('');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.cancel' }));
|
||||
expect(screen.queryByRole('textbox')).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
// FE-M-PLACEACTSECTION-001 to FE-M-PLACEACTSECTION-005: the tours and bookings of a place
|
||||
// on the phone (PLC-18), against a mocked hook.
|
||||
import {
|
||||
activitiesState,
|
||||
activityCandidate,
|
||||
listSource,
|
||||
placeActivity,
|
||||
tripSource,
|
||||
} from '../../../../tests/helpers/placeExtras';
|
||||
import { libraryEntry } from '../../../../tests/helpers/placesLibrary';
|
||||
import { fireEvent, render, screen } from '../../../../tests/helpers/render';
|
||||
import { usePlaceActivities } from '../../../components/Collections/usePlaceActivities';
|
||||
import MPlaceActivitiesSection from './MPlaceActivitiesSection';
|
||||
|
||||
const mockNavigate = vi.fn();
|
||||
vi.mock('react-router', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('react-router')>();
|
||||
return { ...actual, useNavigate: () => mockNavigate };
|
||||
});
|
||||
|
||||
vi.mock('../../../components/Collections/usePlaceActivities', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../../../components/Collections/usePlaceActivities')>();
|
||||
return { ...actual, usePlaceActivities: vi.fn() };
|
||||
});
|
||||
|
||||
const hook = vi.mocked(usePlaceActivities);
|
||||
const t = (k: string) => k;
|
||||
|
||||
function show(state = activitiesState()) {
|
||||
hook.mockReturnValue(state);
|
||||
render(<MPlaceActivitiesSection entry={libraryEntry()} language="en-GB" t={t} />);
|
||||
return state;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mockNavigate.mockClear();
|
||||
hook.mockReset();
|
||||
});
|
||||
|
||||
describe('MPlaceActivitiesSection', () => {
|
||||
it('FE-M-PLACEACTSECTION-001: is not there with nothing linked and nothing to link', () => {
|
||||
show();
|
||||
expect(screen.queryByText('PLACEACTIVITIES.TITLE')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-M-PLACEACTSECTION-002: an activity opens where it lives, a said link comes off again', () => {
|
||||
const linked = placeActivity();
|
||||
const implicit = placeActivity({ key: 'reservation:8', title: 'Dinner', can_unlink: false });
|
||||
const state = show(activitiesState({ activities: [linked, implicit] }));
|
||||
expect(screen.getByText('PLACEACTIVITIES.TITLE')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: /Colosseum tickets/ }));
|
||||
expect(mockNavigate).toHaveBeenCalledWith('/trips/5?booking=7');
|
||||
const unlink = screen.getAllByRole('button', { name: 'placeActivities.unlink' });
|
||||
expect(unlink).toHaveLength(1);
|
||||
fireEvent.click(unlink[0]);
|
||||
expect(state.unlink).toHaveBeenCalledWith(linked);
|
||||
expect(screen.queryByRole('button', { name: 'placeActivities.link' })).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-M-PLACEACTSECTION-003: with nothing linked yet the round button opens the picker', () => {
|
||||
const state = show(activitiesState({ canLink: true }));
|
||||
expect(screen.getByText('placeActivities.none')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'placeActivities.link' }));
|
||||
expect(state.openPicker).toHaveBeenCalledTimes(1);
|
||||
expect(state.closePicker).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('FE-M-PLACEACTSECTION-004: an open picker lists the candidates, links one, and the button closes it', () => {
|
||||
const tour = activityCandidate({ key: 'collection_tour:3', type: 'tour', title: 'Old town walk' });
|
||||
const state = show(
|
||||
activitiesState({
|
||||
canLink: true,
|
||||
picking: [
|
||||
{ source: tripSource(), candidates: [activityCandidate()] },
|
||||
{ source: listSource(), candidates: [tour] },
|
||||
],
|
||||
})
|
||||
);
|
||||
expect(screen.queryByText('placeActivities.none')).toBeNull();
|
||||
fireEvent.click(screen.getByRole('button', { name: /Old town walk/ }));
|
||||
expect(state.link).toHaveBeenCalledWith(listSource(), tour);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.close' }));
|
||||
expect(state.closePicker).toHaveBeenCalledTimes(1);
|
||||
expect(state.openPicker).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('FE-M-PLACEACTSECTION-005: a picker without candidates says so, and a running write disables the buttons', () => {
|
||||
show(activitiesState({ canLink: true, busy: true, picking: [{ source: tripSource(), candidates: [] }] }));
|
||||
expect(screen.getByText('placeActivities.nothingToLink')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'common.close' })).toBeDisabled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
// FE-M-PLACEHISTSECTION-001 to FE-M-PLACEHISTSECTION-004: the change history of a place
|
||||
// on the phone (PLC-14), against a mocked hook.
|
||||
import { historyEntries, historyEntry, historyState } from '../../../../tests/helpers/placeExtras';
|
||||
import { libraryEntry } from '../../../../tests/helpers/placesLibrary';
|
||||
import { fireEvent, render, screen } from '../../../../tests/helpers/render';
|
||||
import { usePlaceHistory } from '../../../components/Collections/usePlaceHistory';
|
||||
import MPlaceHistorySection from './MPlaceHistorySection';
|
||||
|
||||
vi.mock('../../../components/Collections/usePlaceHistory', () => ({ usePlaceHistory: vi.fn() }));
|
||||
|
||||
const hook = vi.mocked(usePlaceHistory);
|
||||
const t = (k: string) => k;
|
||||
|
||||
function show(state = historyState()) {
|
||||
hook.mockReturnValue(state);
|
||||
render(<MPlaceHistorySection entry={libraryEntry()} language="en-GB" t={t} />);
|
||||
return state;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
hook.mockReset();
|
||||
});
|
||||
|
||||
describe('MPlaceHistorySection', () => {
|
||||
it('FE-M-PLACEHISTSECTION-001: is not there before the first change', () => {
|
||||
show();
|
||||
expect(screen.queryByText('PLACEHISTORY.TITLE')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-M-PLACEHISTSECTION-002: a change shows from and to, where, who and when', () => {
|
||||
show(
|
||||
historyState({
|
||||
entries: [
|
||||
historyEntry(),
|
||||
historyEntry({
|
||||
id: 2,
|
||||
field: 'opening_hours',
|
||||
automatic: true,
|
||||
origin: { kind: 'list', collection_id: 9, collection_name: 'Favourites', collection_place_id: 900 },
|
||||
}),
|
||||
],
|
||||
})
|
||||
);
|
||||
expect(screen.getByText('PLACEHISTORY.TITLE')).toBeInTheDocument();
|
||||
expect(screen.getByText('Colosseo')).toHaveClass('line-through');
|
||||
expect(screen.getByText('Colosseum')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Rome 2026, anna/)).toBeInTheDocument();
|
||||
expect(screen.getByText('placeHistory.field.opening_hours')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Favourites, placeHistory\.automatic/)).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-M-PLACEHISTSECTION-003: shows three at first, then all, then reads more', () => {
|
||||
const state = show(historyState({ entries: historyEntries(4), hasMore: true }));
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(3);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'placeHistory.showAll' }));
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(4);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'placeHistory.more' }));
|
||||
expect(state.more).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('FE-M-PLACEHISTSECTION-004: a few changes with more on the server still offer "show all"; loading waits', () => {
|
||||
show(historyState({ entries: historyEntries(2), hasMore: true, loadingMore: true }));
|
||||
expect(screen.getByRole('button', { name: 'placeHistory.showAll' })).toBeDisabled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
// FE-M-PLACEMEDIASECTION-001 to FE-M-PLACEMEDIASECTION-004: the pictures and trip files of
|
||||
// a place on the phone (PLC-19, PLC-20), against a mocked hook.
|
||||
import { mediaFile, mediaState, photos } from '../../../../tests/helpers/placeExtras';
|
||||
import { libraryEntry } from '../../../../tests/helpers/placesLibrary';
|
||||
import { fireEvent, render, screen } from '../../../../tests/helpers/render';
|
||||
import { usePlaceMedia } from '../../../components/Collections/usePlaceMedia';
|
||||
import MPlaceMediaSection from './MPlaceMediaSection';
|
||||
|
||||
vi.mock('../../../components/Collections/usePlaceMedia', () => ({ usePlaceMedia: vi.fn() }));
|
||||
vi.mock('../../../components/Journey/PhotoLightbox', () => ({
|
||||
default: (p: { photos: { id: string }[]; startIndex: number; label?: string; onClose: () => void }) => (
|
||||
<div role="dialog" aria-label={p.label}>
|
||||
<span>{`${p.photos.length} from ${p.startIndex}`}</span>
|
||||
<button type="button" onClick={p.onClose}>
|
||||
close lightbox
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
const hook = vi.mocked(usePlaceMedia);
|
||||
const t = (k: string) => k;
|
||||
|
||||
function show(state = mediaState()) {
|
||||
hook.mockReturnValue(state);
|
||||
render(<MPlaceMediaSection entry={libraryEntry()} t={t} />);
|
||||
return state;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
hook.mockReset();
|
||||
});
|
||||
|
||||
describe('MPlaceMediaSection', () => {
|
||||
it('FE-M-PLACEMEDIASECTION-001: is not there without pictures or files', () => {
|
||||
show();
|
||||
expect(screen.queryByText('PLACES.MEDIA.PHOTOS')).toBeNull();
|
||||
expect(screen.queryByText('PLACES.MEDIA.FILES')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-M-PLACEMEDIASECTION-002: shows six and counts the rest; a tap opens that picture', () => {
|
||||
const state = show(mediaState({ photos: photos(9) }));
|
||||
expect(screen.getByText('PLACES.MEDIA.PHOTOS')).toBeInTheDocument();
|
||||
expect(screen.queryByText('PLACES.MEDIA.FILES')).toBeNull();
|
||||
expect(screen.getAllByRole('button')).toHaveLength(6);
|
||||
expect(screen.getByText('+3')).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Photo 4' }));
|
||||
expect(state.setOpen).toHaveBeenCalledWith(4);
|
||||
});
|
||||
|
||||
it('FE-M-PLACEMEDIASECTION-003: files alone show without a picture row and link to their trip', () => {
|
||||
show(mediaState({ files: [mediaFile()] }));
|
||||
expect(screen.queryByText('PLACES.MEDIA.PHOTOS')).toBeNull();
|
||||
const file = screen.getByRole('link', { name: /tickets\.pdf/ });
|
||||
expect(file).toHaveAttribute('href', '/trips/5/files?file=31');
|
||||
expect(file).toHaveTextContent('Rome 2026');
|
||||
});
|
||||
|
||||
it('FE-M-PLACEMEDIASECTION-004: the open picture shows in the lightbox, which closes again', () => {
|
||||
const state = show(mediaState({ photos: photos(2), open: 1 }));
|
||||
expect(screen.getByRole('dialog', { name: 'Colosseum' })).toHaveTextContent('2 from 1');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'close lightbox' }));
|
||||
expect(state.close).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
// FE-MOB-VISITS-001 to FE-MOB-VISITS-005: the visits of a place on the phone sheets.
|
||||
import type { PlaceVisit } from '@trek/shared';
|
||||
|
||||
import { libraryEntry } from '../../../../tests/helpers/placesLibrary';
|
||||
import { render, screen } from '../../../../tests/helpers/render';
|
||||
import { visitDate } from '../../../components/Collections/libraryDates';
|
||||
import { usePlaceVisits } from '../../../components/Collections/usePlaceVisits';
|
||||
import MVisitsSection, { MTripPlaceVisits } from './MVisitsSection';
|
||||
|
||||
vi.mock('../../../components/Collections/usePlaceVisits', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('../../../components/Collections/usePlaceVisits')>()),
|
||||
usePlaceVisits: vi.fn(),
|
||||
}));
|
||||
|
||||
const hook = vi.mocked(usePlaceVisits);
|
||||
const t = (k: string, p?: Record<string, unknown>) => (p ? `${k}:${JSON.stringify(p)}` : k);
|
||||
|
||||
function visit(over: Partial<PlaceVisit> = {}): PlaceVisit {
|
||||
return {
|
||||
visited_on: '2026-07-02',
|
||||
visited_time: null,
|
||||
trip: { id: 5, title: 'Rome 2026' },
|
||||
place_id: 42,
|
||||
day_id: 3,
|
||||
day_number: 2,
|
||||
name: 'Colosseum',
|
||||
participants: [],
|
||||
...over,
|
||||
};
|
||||
}
|
||||
|
||||
function visits(list: PlaceVisit[], lastVisit: string | null = '2026-07-02') {
|
||||
hook.mockReturnValue({ visits: list, count: list.length, lastVisit, loading: false });
|
||||
}
|
||||
|
||||
const summary = (count: number) =>
|
||||
`visits.summary:${JSON.stringify({ count, date: visitDate('2026-07-02', null, 'en-GB') })}`;
|
||||
|
||||
beforeEach(() => {
|
||||
hook.mockReset();
|
||||
});
|
||||
|
||||
describe('MVisitsSection', () => {
|
||||
it('FE-MOB-VISITS-001: not there at all without a visit', () => {
|
||||
visits([], null);
|
||||
const { container } = render(<MVisitsSection entry={libraryEntry()} language="en-GB" t={t} />);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it('FE-MOB-VISITS-002: a card per visit with its day, time and trip, under the summary', () => {
|
||||
visits([visit({ visited_time: '09:15' }), visit({ day_id: 8, trip: { id: 6, title: 'Lazio' } })]);
|
||||
render(<MVisitsSection entry={libraryEntry()} language="en-GB" t={t} />);
|
||||
expect(screen.getByText('VISITS.TITLE')).toBeInTheDocument();
|
||||
expect(screen.getByText(summary(2))).toBeInTheDocument();
|
||||
expect(screen.getByText(visitDate('2026-07-02', '09:15', 'en-GB') as string)).toBeInTheDocument();
|
||||
expect(screen.getByText('Rome 2026')).toBeInTheDocument();
|
||||
expect(screen.getByText('Lazio')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-MOB-VISITS-003: shows at most three companions, and none for a visit alone', () => {
|
||||
const people = ['anna', 'ben', 'cleo', 'dan'].map((username, i) => ({ id: i + 1, username, avatar_url: null }));
|
||||
visits([visit({ participants: people }), visit({ day_id: 4, participants: [people[3]] })]);
|
||||
render(<MVisitsSection entry={libraryEntry()} language="en-GB" t={t} />);
|
||||
expect(screen.getByText('A')).toBeInTheDocument();
|
||||
expect(screen.getByText('B')).toBeInTheDocument();
|
||||
expect(screen.getByText('C')).toBeInTheDocument();
|
||||
expect(screen.queryByText('D')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('MTripPlaceVisits', () => {
|
||||
const trip = { id: 5, title: 'Rome 2026' };
|
||||
const place = { id: 42, name: 'Colosseum' };
|
||||
|
||||
it('FE-MOB-VISITS-004: sums up the visits of the trip place', () => {
|
||||
visits([visit()]);
|
||||
render(<MTripPlaceVisits trip={trip} place={place} language="en-GB" t={t} />);
|
||||
expect(screen.getByText(summary(1))).toBeInTheDocument();
|
||||
expect(hook).toHaveBeenCalledWith({ entry: expect.objectContaining({ key: 'trip:42' }) });
|
||||
});
|
||||
|
||||
it('FE-MOB-VISITS-005: not shown before the first visit', () => {
|
||||
visits([], null);
|
||||
const { container } = render(<MTripPlaceVisits trip={trip} place={place} language="en-GB" t={t} />);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
});
|
||||
@@ -34,6 +34,12 @@ describe('placesBrowserModel — planned pool', () => {
|
||||
const out = filterPool(named, { filter: 'planned', categoryFilters: noCats, search: 'eiff', plannedIds })
|
||||
expect(out.map(p => p.id)).toEqual([3])
|
||||
})
|
||||
|
||||
it('MOBILE-POOL-visited: the visited pool keeps the places in the visited set, and none without it', () => {
|
||||
const visitedIds = new Set([2])
|
||||
expect(filterPool(places, { filter: 'visited', categoryFilters: noCats, search: '', plannedIds, visitedIds }).map(p => p.id)).toEqual([2])
|
||||
expect(filterPool(places, { filter: 'visited', categoryFilters: noCats, search: '', plannedIds })).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
// FE-MOB-PMODEL-001 to FE-MOB-PMODEL-012
|
||||
|
||||
Reference in New Issue
Block a user