// 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; function renderPanel(variant: PanelProps['variant'], over: Partial = {}) { const onIncludeNotes = vi.fn(); const onToggleTag = vi.fn(); render( ); 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']]); }); });