// FE-COMP-LIBORIGINS-001 to FE-COMP-LIBORIGINS-004 import React from 'react'; import { listOrigin, tripOrigin } from '../../../tests/helpers/placesLibrary'; import { render, screen } from '../../../tests/helpers/render'; import { useTranslation } from '../../i18n/TranslationContext'; import LibraryOrigins from './LibraryOrigins'; import { originName } from './originName'; type Props = Omit, 't'>; function Harness(props: Props): React.ReactElement { const { t } = useTranslation(); return ; } const pillTexts = (container: HTMLElement) => Array.from(container.querySelectorAll('.col-origin-pill')).map((el) => el.textContent); describe('LibraryOrigins', () => { it("FE-COMP-LIBORIGINS-001: an origin goes by its list's or its trip's name", () => { expect(originName(listOrigin({ collection_name: 'Wishlist' }))).toBe('Wishlist'); expect(originName(tripOrigin({ trip_title: 'Japan 2027' }))).toBe('Japan 2027'); }); it('FE-COMP-LIBORIGINS-002: trips come before lists, each with a title saying where the place is', () => { const { container } = render( ); expect(pillTexts(container)).toEqual(['Rome 2026', 'Favourites']); expect(screen.getByTitle('In the trip Rome 2026')).toBeInTheDocument(); expect(screen.getByTitle('In the list Favourites')).toBeInTheDocument(); }); it('FE-COMP-LIBORIGINS-003: past two origins the rest is counted', () => { const { container } = render( ); expect(pillTexts(container)).toEqual(['First trip', 'Second trip', '+2']); expect(screen.queryByText('A list')).not.toBeInTheDocument(); }); it('FE-COMP-LIBORIGINS-004: two origins or fewer show no count', () => { const { container } = render(); expect(pillTexts(container)).toEqual(['Rome 2026']); expect(container.querySelector('.col-origin-pill.more')).toBeNull(); }); });