Files
ipal-kit/test/blockPosition.test.ts
Radosław SmolińskiandClaude Opus 5.5 6f56ef4205 Block library: item headings follow the section; the leading block's first image is the LCP image
Found by ipal-doctor live-seo on the reference archive pages (entry list under a
page header without a picture): cards jumped h1 → h3, and the first card image
was lazy.

- itemHeadingLevel: items one below the section heading (h3 under h2, h2 under the
  page h1, h2 when the block shows no heading); createBlockRegistry({ itemHeadings })
  fixes a level per block. featureGrid, entryList, pricing, steps, team.
- blockPosition / blockHasImage (root): createPageRoute and the 404 view pass
  firstImage next to isFirst; leadsWithImage marks the first image of the leading
  block eager + fetchPriority high (hero, textMedia, featureGrid, gallery, team,
  entryList); priorityImage: false turns it off.
- reference/ipal-doctor.json: the two live-seo silences removed; reference skills
  and docs/agent/reference-site/INDEX.md refreshed.
- bin/ipal-blocks.mjs executable like the other bins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 16:38:04 +01:00

30 lines
1.2 KiB
TypeScript

import { describe, expect, test } from 'vitest'
import { blockHasImage, blockPosition } from '../src/index.js'
const image = { height: 600, mimeType: 'image/jpeg', url: '/api/media/file/a.jpg', width: 900 }
describe('blockPosition', () => {
const blocks = [
{ blockType: 'hero', header: { heading: 'Blog' }, media: null, variant: 'page' },
{ blockType: 'entryList', entryCollection: 'posts' },
{ blockType: 'gallery', items: [{ media: image }] },
{ blockType: 'cta', media: 7 },
]
test('isFirst only for the first block; firstImage until a block shows an image', () => {
expect(blocks.map((_, index) => blockPosition({ allBlocks: blocks, index }))).toEqual([
{ firstImage: true, isFirst: true },
{ firstImage: true, isFirst: false },
{ firstImage: true, isFirst: false },
{ firstImage: false, isFirst: false },
])
})
test('blockHasImage: populated images anywhere in the data; ids and videos do not count', () => {
expect(blockHasImage({ items: [{ media: image }] })).toBe(true)
expect(blockHasImage({ media: 7 })).toBe(false)
expect(blockHasImage({ media: { mimeType: 'video/mp4', url: '/v.mp4' } })).toBe(false)
})
})