Files
TREK/client/src/components/Collections/CopyCarryPanel.test.tsx
T
Maurice 20e3d2d9ae test(places): cover the place view, the rating row and the rating filter
Tests for the vote by entry key in the api and the repository, the rating
row and its voters, the rating filter and sort on both views, the edit form
without a choice of copy, and the place view's sections, aligned with the
renamed tag strings.
2026-11-29 23:36:43 +00:00

71 lines
3.3 KiB
TypeScript

// FE-COMP-COPYCARRY-001 to FE-COMP-COPYCARRY-005
import type { ComponentProps } from 'react';
import { fireEvent, render, screen, within } from '../../../tests/helpers/render';
import CopyCarryPanel from './CopyCarryPanel';
import type { CarryTag } from './useTripCopyPicker';
const t = (k: string) => k;
const COFFEE: CarryTag = { key: 'label:7', name: 'Coffee', color: '#f97316' };
const LATE: CarryTag = { key: 'tag:7', name: 'Late' };
type PanelProps = ComponentProps<typeof CopyCarryPanel>;
function renderPanel(variant: PanelProps['variant'], over: Partial<PanelProps> = {}) {
const onIncludeNotes = vi.fn();
const onToggleTag = vi.fn();
render(
<CopyCarryPanel
options={{ hasNotes: true, tags: [COFFEE, LATE] }}
includeNotes={false}
onIncludeNotes={onIncludeNotes}
tagIds={[]}
onToggleTag={onToggleTag}
variant={variant}
t={t}
{...over}
/>
);
return { onIncludeNotes, onToggleTag };
}
describe.each(['dialog', 'sheet'] as const)('CopyCarryPanel (%s)', (variant) => {
it('FE-COMP-COPYCARRY-001: switches the notes on and picks a tag by its carry key', () => {
const props = renderPanel(variant, { tagIds: ['tag:7'] });
fireEvent.click(screen.getByRole('button', { name: 'collections.copyCarry.notes' }));
expect(props.onIncludeNotes).toHaveBeenCalledWith(true);
const group = screen.getByRole('group', { name: 'collections.copyCarry.tags' });
expect(within(group).getByRole('button', { name: 'Late' })).toHaveAttribute('aria-pressed', 'true');
expect(within(group).getByRole('button', { name: 'Coffee' })).toHaveAttribute('aria-pressed', 'false');
fireEvent.click(within(group).getByRole('button', { name: 'Coffee' }));
// A list tag and an older tag may share a number: the key keeps them apart.
expect(props.onToggleTag).toHaveBeenCalledWith('label:7');
});
it('FE-COMP-COPYCARRY-002: shows only what the places carry', () => {
renderPanel(variant, { options: { hasNotes: false, tags: [COFFEE] } });
expect(screen.queryByText('collections.copyCarry.notes')).toBeNull();
expect(screen.getByRole('button', { name: 'Coffee' })).toHaveAttribute('aria-pressed', 'false');
});
it('FE-COMP-COPYCARRY-003: without tags there is no tag group, only the notes', () => {
renderPanel(variant, { options: { hasNotes: true, tags: [] }, includeNotes: true });
expect(screen.queryByRole('group', { name: 'collections.copyCarry.tags' })).toBeNull();
expect(screen.queryByText('collections.copyCarry.all')).toBeNull();
expect(screen.getByText('collections.copyCarry.notesHint')).toBeInTheDocument();
});
it('FE-COMP-COPYCARRY-004: "all" picks every tag not yet picked', () => {
const props = renderPanel(variant, { tagIds: ['tag:7'] });
fireEvent.click(screen.getByRole('button', { name: 'collections.copyCarry.all' }));
expect(props.onToggleTag).toHaveBeenCalledTimes(1);
expect(props.onToggleTag).toHaveBeenCalledWith('label:7');
});
it('FE-COMP-COPYCARRY-005: with every tag picked the same button takes them all off again', () => {
const props = renderPanel(variant, { tagIds: ['label:7', 'tag:7'] });
fireEvent.click(screen.getByRole('button', { name: 'collections.copyCarry.none' }));
expect(props.onToggleTag.mock.calls).toEqual([['label:7'], ['tag:7']]);
});
});