mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
bacc6a29a7
All places offers the pairs that look like one place: both sides side by side with what differs marked, "keep this one" to group them as one place of the user's own (undo right after), and "not the same place" to set a pair aside for good. Desktop dialog and phone sheet share usePlaceDuplicates; every locale has the new strings. What the last dev run flagged on the client: - Tailwind's Prettier plugin had trimmed the leading space of conditional class names (col-filter-btn, col-lrow sel, col-split map-full, col-detail docked), so the filter row and the open row lost their styling; those classes are now joined so the formatter cannot glue them. - The dock position lives in one helper for the lists and All places, which moves the measured-position markers there instead of adding new ones. - usePlacesLibrary is split into filters, pages, detail and cover hooks that derive their loading state instead of setting it inside effects; the big sheets and views are cut into parts under the complexity limit, dynamic icons go through createElement, originName moves out of a component file. - formatRange is guarded like in the packing export, the cover lookup skips places without a position. - Tests follow the rename to Places, the category icon, the default list icon and the new trip collections store; react-hooks/refs is lowered to the count the run measured. - The rating on a place is a round badge again, in the list and on the map.
131 lines
5.1 KiB
TypeScript
131 lines
5.1 KiB
TypeScript
import userEvent from '@testing-library/user-event';
|
|
import type { ComponentProps } from 'react';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { pairKey } from '../../../../src/components/Collections/usePlaceDuplicates';
|
|
import { useTranslation } from '../../../../src/i18n';
|
|
import MDuplicatesSheet from '../../../../src/mobile/screens/collections/MDuplicatesSheet';
|
|
import { duplicatePair, duplicateSide } from '../../../helpers/placesLibrary';
|
|
import { render, screen } from '../../../helpers/render';
|
|
|
|
// FE-MOB-DUPESHEET-001 to FE-MOB-DUPESHEET-012
|
|
|
|
type Props = ComponentProps<typeof MDuplicatesSheet>;
|
|
type Dupes = Props['d'];
|
|
|
|
const PAIR = duplicatePair();
|
|
const OTHER = duplicatePair({
|
|
a: duplicateSide({ key: 'trip:7', name: 'Pantheon' }),
|
|
b: duplicateSide({ key: 'trip:8', name: 'Pantheon Rome' }),
|
|
});
|
|
|
|
function dupes(over: Partial<Dupes> = {}): Dupes {
|
|
return {
|
|
pairs: [PAIR, OTHER],
|
|
hasMore: false,
|
|
loading: false,
|
|
busy: null,
|
|
lastMerge: null,
|
|
merge: vi.fn(() => Promise.resolve()),
|
|
dismiss: vi.fn(() => Promise.resolve()),
|
|
undo: vi.fn(() => Promise.resolve()),
|
|
reload: vi.fn(),
|
|
...over,
|
|
};
|
|
}
|
|
|
|
function Harness(props: Omit<Props, 't'>) {
|
|
const { t } = useTranslation();
|
|
return <MDuplicatesSheet {...props} t={t} />;
|
|
}
|
|
|
|
function setup(over: Partial<Dupes> = {}, open = true) {
|
|
const onClose = vi.fn();
|
|
const d = dupes(over);
|
|
const view = render(<Harness open={open} d={d} onClose={onClose} />);
|
|
return { ...view, d, onClose };
|
|
}
|
|
|
|
describe('MDuplicatesSheet', () => {
|
|
it('FE-MOB-DUPESHEET-001: renders nothing while closed', () => {
|
|
setup({}, false);
|
|
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-002: opens as a dialog with the title and what keeping a side does', () => {
|
|
setup();
|
|
expect(screen.getByRole('dialog', { name: 'Possible duplicates' })).toBeInTheDocument();
|
|
expect(screen.getByText(/Keep one side to group both as one place of yours/)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-003: lists a phone-styled card per pair', () => {
|
|
setup();
|
|
const cards = screen.getAllByRole('article');
|
|
expect(cards).toHaveLength(2);
|
|
expect(cards[0].className).toContain('bg-m-sheet');
|
|
expect(screen.getByText('Pantheon Rome')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-004: with no pairs it says there are none', () => {
|
|
setup({ pairs: [] });
|
|
expect(screen.getByText('No possible duplicates.')).toBeInTheDocument();
|
|
expect(screen.queryByRole('article')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-005: while loading with nothing yet it shows a spinner, not the empty note', () => {
|
|
setup({ pairs: [], loading: true });
|
|
expect(screen.queryByText('No possible duplicates.')).not.toBeInTheDocument();
|
|
expect(document.querySelector('.animate-spin')).not.toBeNull();
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-006: tells that more show up once these are done', () => {
|
|
const more = setup({ hasMore: true });
|
|
expect(screen.getByText('More show up once you are through these.')).toBeInTheDocument();
|
|
more.unmount();
|
|
setup({ hasMore: false });
|
|
expect(screen.queryByText('More show up once you are through these.')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-007: keeping a side merges that pair with that side leading', async () => {
|
|
const user = userEvent.setup();
|
|
const { d } = setup();
|
|
await user.click(screen.getAllByRole('button', { name: /Keep this one/ })[3]);
|
|
expect(d.merge).toHaveBeenCalledWith(OTHER, 'b');
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-008: "Not the same place" dismisses that pair', async () => {
|
|
const user = userEvent.setup();
|
|
const { d } = setup();
|
|
await user.click(screen.getAllByRole('button', { name: 'Not the same place' })[0]);
|
|
expect(d.dismiss).toHaveBeenCalledWith(PAIR);
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-009: only the pair being worked on is busy', () => {
|
|
setup({ busy: pairKey(OTHER) });
|
|
const [first, second] = screen.getAllByRole('article');
|
|
for (const button of first.querySelectorAll('button')) expect(button).toBeEnabled();
|
|
for (const button of second.querySelectorAll('button')) expect(button).toBeDisabled();
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-010: the undo button appears only after a merge and takes it back', async () => {
|
|
const user = userEvent.setup();
|
|
const none = setup();
|
|
expect(screen.queryByRole('button', { name: /Separate/ })).not.toBeInTheDocument();
|
|
none.unmount();
|
|
const { d } = setup({ lastMerge: { id: 4, name: 'Colosseo' } });
|
|
await user.click(screen.getByRole('button', { name: 'Separate Colosseo again' }));
|
|
expect(d.undo).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-011: the undo button is disabled while the undo runs', () => {
|
|
setup({ lastMerge: { id: 4, name: 'Colosseo' }, busy: 'undo' });
|
|
expect(screen.getByRole('button', { name: 'Separate Colosseo again' })).toBeDisabled();
|
|
});
|
|
|
|
it('FE-MOB-DUPESHEET-012: the close button closes the sheet', async () => {
|
|
const user = userEvent.setup();
|
|
const { onClose } = setup();
|
|
await user.click(screen.getByRole('button', { name: 'Close' }));
|
|
expect(onClose).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|