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) }) })