import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import packages from '../content/packages'; import shootTypes from '../content/shootTypes'; import sitePages from '../sitePages'; import { anyPackage, shootType } from '../test/arbitraries'; import { isPortfolioLive, shootContactLink, shootPortfolioLink, } from './shootLinks'; import { visiblePackages } from './visiblePackages'; const shoot = (id: string) => shootTypes.find((item) => item.id === id)!; describe('shootContactLink', () => { it('preselects the package of a shoot that has one', () => { expect(shootContactLink(shoot('newborn'), packages)).toEqual({ to: '/contact', search: { pakket: 'newborn' }, }); }); it('links without a package for a shoot that has none', () => { expect(shootContactLink(shoot('loveshoot'), packages)).toEqual({ to: '/contact', }); }); it('leaves out a package that is not shown', () => { expect( shootContactLink( shoot('gezin'), packages.filter((pkg) => pkg.id !== 'gezin'), ), ).toEqual({ to: '/contact' }); }); it('always goes to the contact page (invariant)', () => { fc.assert( fc.property(shootType, fc.array(anyPackage), (item, list) => { return shootContactLink(item, list).to === '/contact'; }), ); }); it('only preselects a shown package, and then exactly that one (invariant)', () => { fc.assert( fc.property(shootType, fc.array(anyPackage), (item, list) => { const link = shootContactLink(item, list); const shownIds = visiblePackages(list).map((pkg) => pkg.id); const expected = shownIds.includes(item.packageId ?? ''); expect(link.search !== undefined).toBe(expected); if (link.search !== undefined) { expect(link.search.pakket).toBe(item.packageId); expect(shownIds).toContain(link.search.pakket); } }), ); }); }); describe('shootPortfolioLink', () => { it('filters the portfolio on the shoot type (invariant)', () => { fc.assert( fc.property(shootType, (item) => { expect(shootPortfolioLink(item)).toEqual({ to: '/portfolio', search: { shoot: item.id }, }); }), ); }); }); describe('isPortfolioLive', () => { it('follows whether the portfolio page is indexed', () => { expect(isPortfolioLive(sitePages)).toBe( sitePages['/portfolio'].indexed, ); expect( isPortfolioLive({ ...sitePages, '/portfolio': { ...sitePages['/portfolio'], indexed: true }, }), ).toBe(true); expect( isPortfolioLive({ ...sitePages, '/portfolio': { ...sitePages['/portfolio'], indexed: false }, }), ).toBe(false); }); });