import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import shootPageShared from '@/content/shootPageShared'; import newbornPage from '@/content/shootPages/newborn'; import loveshootPage from '@/content/shootPages/loveshoot'; import packages from '@/content/packages'; import shootTypes from '@/content/shootTypes'; import siteContent from '@/content/siteContent'; import { shootPageViewArb } from '@/test/arbitraries'; import { shootPageBands } from './shootPageBands'; import { shootPageView } from './shootPageView'; import { storyLayout } from './storyLayout'; const sources = { shootTypes, packages, shared: shootPageShared, site: siteContent, portfolioShoots: [], }; describe('shootPageBands', () => { it('gives the newborn page nine bands', () => { const view = shootPageView('newborn', newbornPage, sources)!; const bands = shootPageBands(view); expect(bands).toHaveLength(9); expect(bands.map((band) => band.id)).toEqual([ ...view.stories.map((story) => `story-${story.id}`), 'process', 'photos', 'faq', 'offer', 'closing', ]); expect(bands.map((band) => band.position)).toEqual([ 0, 1, 2, 3, 4, 5, 6, 7, 8, ]); expect(bands[0].tone).toBe('paper'); expect(bands[1].tone).toBe('alt'); }); it('leaves out the photos for loveshoot', () => { const view = shootPageView('loveshoot', loveshootPage, sources)!; const bands = shootPageBands(view); expect(bands).toHaveLength(8); expect(bands.map((band) => band.id)).not.toContain('photos'); }); it('leaves out the FAQ of a view without questions', () => { const view = shootPageView( 'newborn', { ...newbornPage, faq: { ...newbornPage.faq, items: [] } }, sources, )!; const ids = shootPageBands(view).map((band) => band.id); expect(ids).not.toContain('faq'); expect(ids).toContain('photos'); }); it('keeps the order, the alternation and the story tones for any view (invariant)', () => { fc.assert( fc.property(shootPageViewArb, (view) => { const bands = shootPageBands(view); expect(bands).toHaveLength( view.stories.length + 1 + (view.photos ? 1 : 0) + (view.faq ? 1 : 0) + 2, ); bands.forEach((band, index) => { expect(band.position).toBe(index); expect(band.tone).toBe(index % 2 === 0 ? 'paper' : 'alt'); }); const tail = bands.slice(view.stories.length).map((b) => b.id); expect(tail).toEqual([ 'process', ...(view.photos ? ['photos'] : []), ...(view.faq ? ['faq'] : []), 'offer', 'closing', ]); expect( bands.slice(0, view.stories.length).map((b) => b.id), ).toEqual(view.stories.map((story) => `story-${story.id}`)); const layout = storyLayout(view.stories); layout.forEach((item, index) => { expect(bands[index].tone).toBe(item.tone); }); // Story ids are unique in the generated content expect(new Set(bands.map((b) => b.id)).size).toBe(bands.length); }), ); }); });