Files
bmp-website-2026/tests/int/home-winner-selection.int.spec.ts
2026-07-31 14:25:11 +02:00

53 lines
2.0 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { CmsRouteDoc } from '@/spa/cmsRoute'
import { resolveHomeWinners } from '@/spa/homeWinnerSelection'
const selected2026Winners: CmsRouteDoc[] = Array.from({ length: 16 }, (_, index) => ({
id: 65 + index,
title: `Winner ${65 + index}`,
year: 2026,
}))
const published2025Winners: CmsRouteDoc[] = Array.from({ length: 9 }, (_, index) => ({
id: 12 + index,
title: `Winner ${12 + index}`,
year: 2025,
}))
describe('home winner selection', () => {
it('uses a non-empty CMS selection without appending winners from the fallback year', () => {
const featured = selected2026Winners.map(({ id }) => id)
const winners = resolveHomeWinners(featured, [...selected2026Winners, ...published2025Winners])
expect(winners).toEqual(selected2026Winners)
expect(winners.some((winner) => winner.year === 2025)).toBe(false)
})
it('falls back to at most eight 2025 winners when the CMS selection is empty', () => {
const winners = resolveHomeWinners([], published2025Winners)
expect(winners).toEqual(published2025Winners.slice(0, 8))
})
it('omits an unpublished selected winner without changing the remaining page order', () => {
const [first, unpublished, third] = selected2026Winners
const selection = [third, { ...unpublished, image: { id: 99 } }, first]
const publicWinners = resolveHomeWinners(selection, [first, third])
const previewWinners = resolveHomeWinners(selection, [first, unpublished, third])
expect(publicWinners).toEqual([third, first])
expect(previewWinners).toEqual([third, unpublished, first])
})
it('does not replace an entirely unpublished CMS selection with fallback winners', () => {
const [unpublished] = selected2026Winners
expect(resolveHomeWinners([{ ...unpublished, image: { id: 99 } }], [])).toEqual([])
})
it('does not resurrect static winners when the published collection is empty', () => {
expect(resolveHomeWinners([], [])).toEqual([])
})
})