import assert from 'node:assert/strict' import test from 'node:test' import { getContentLightboxImages, getGalleryRows } from '../lib/content-gallery-images.js' test('본문 라이트박스 목록은 단일 이미지와 갤러리 이미지를 원문 순서대로 펼친다', () => { const images = getContentLightboxImages([ { id: 'block-1', type: 'image', url: '/uploads/posts/2026/07/a.jpg', alt: '단일' }, { id: 'block-2', type: 'paragraph', text: '본문' }, { id: 'block-3', type: 'gallery', images: [ { url: '/uploads/posts/2026/07/b.jpg', alt: '갤러리 1' }, { url: '', alt: '빈 이미지' }, { url: '/uploads/posts/2026/07/c.jpg', alt: '갤러리 3' } ] } ]) assert.deepEqual( images.map((image) => [image.url, image.lightboxKey]), [ ['/uploads/posts/2026/07/a.jpg', 'block-1'], ['/uploads/posts/2026/07/b.jpg', 'block-3:0'], ['/uploads/posts/2026/07/c.jpg', 'block-3:2'] ] ) }) test('본문 라이트박스 목록은 이미지 URL이 없는 블록을 제외한다', () => { assert.deepEqual(getContentLightboxImages([ { id: 'block-1', type: 'image', url: '' }, { id: 'block-2', type: 'gallery', images: null }, { id: 'block-3', type: 'gallery', images: [{ alt: 'url 없음' }] } ]), []) }) test('갤러리 행은 기본 3개 단위로 나눈다', () => { const rows = getGalleryRows([ { url: '1.jpg' }, { url: '2.jpg' }, { url: '3.jpg' }, { url: '4.jpg' }, { url: '5.jpg' }, { url: '6.jpg' }, { url: '7.jpg' } ]) assert.deepEqual( rows.map((row) => [row.startIndex, row.images.map((image) => image.url)]), [ [0, ['1.jpg', '2.jpg', '3.jpg']], [3, ['4.jpg', '5.jpg', '6.jpg']], [6, ['7.jpg']] ] ) }) test('갤러리 행 분할은 잘못된 입력을 빈 목록으로 처리한다', () => { assert.deepEqual(getGalleryRows(null), []) assert.deepEqual(getGalleryRows([{ url: '1.jpg' }, { url: '2.jpg' }], 0), [ { startIndex: 0, images: [{ url: '1.jpg' }, { url: '2.jpg' }] } ]) })