import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import shootTypes from '../content/shootTypes'; import { uniqueShootTypes } from '../test/arbitraries'; import { shootNavItems } from './shootNavItems'; import { SHOOT_TYPES_PATH, shootIdFromPath, shootPagePath } from './shootPages'; describe('shootNavItems', () => { it('gives one item per shoot (invariant)', () => { fc.assert( fc.property(uniqueShootTypes, (shoots) => { expect(shootNavItems(shoots)).toHaveLength(shoots.length); }), ); }); it('keeps the order and uses the name as label (invariant)', () => { fc.assert( fc.property(uniqueShootTypes, (shoots) => { const items = shootNavItems(shoots); expect(items.map((item) => item.label)).toEqual( shoots.map((shoot) => shoot.name), ); }), ); }); it('links to the page of the same shoot (round trip)', () => { fc.assert( fc.property(uniqueShootTypes, (shoots) => { const items = shootNavItems(shoots); items.forEach((item, index) => { expect(shootIdFromPath(item.to)).toBe(shoots[index].id); }); }), ); }); it('links to a page below the overview (invariant)', () => { fc.assert( fc.property(uniqueShootTypes, (shoots) => { shootNavItems(shoots).forEach((item, index) => { expect(item.to).toBe(shootPagePath(shoots[index].id)); expect(item.to.startsWith(`${SHOOT_TYPES_PATH}/`)).toBe( true, ); }); }), ); }); it('has no other fields than to and label (invariant)', () => { fc.assert( fc.property(uniqueShootTypes, (shoots) => { for (const item of shootNavItems(shoots)) { expect(Object.keys(item).sort()).toEqual(['label', 'to']); } }), ); }); it('gives the five names of the real shoot types in order', () => { expect(shootNavItems(shootTypes).map((item) => item.label)).toEqual([ 'Newborn', 'Zwangerschap', 'Gezin', 'Loveshoot', 'Portretten', ]); }); it('gives an empty list for no shoots', () => { expect(shootNavItems([])).toEqual([]); }); });