본문 이미지 URL 계산 분리
This commit is contained in:
46
tests/content-image-urls.test.js
Normal file
46
tests/content-image-urls.test.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
getContentDisplayImageSrcset,
|
||||
getContentDisplayImageUrl,
|
||||
getContentLightboxImageUrl,
|
||||
getGalleryImageSizes
|
||||
} from '../lib/content-image-urls.js'
|
||||
|
||||
test('본문 이미지 URL은 업로드 원본이면 body-1600 파생 이미지로 변환한다', () => {
|
||||
assert.equal(
|
||||
getContentDisplayImageUrl('/uploads/posts/2026/07/sample.jpg'),
|
||||
'/uploads/posts/2026/07/thumbs/sample-body-1600.webp?v=20260702-1'
|
||||
)
|
||||
})
|
||||
|
||||
test('라이트박스 이미지 URL은 업로드 원본이면 body-2560 파생 이미지로 변환한다', () => {
|
||||
assert.equal(
|
||||
getContentLightboxImageUrl('/uploads/posts/2026/07/sample.png'),
|
||||
'/uploads/posts/2026/07/thumbs/sample-body-2560.webp?v=20260702-1'
|
||||
)
|
||||
})
|
||||
|
||||
test('외부 이미지는 원본 URL을 그대로 사용하고 srcset을 만들지 않는다', () => {
|
||||
const url = 'https://example.com/image.jpg'
|
||||
|
||||
assert.equal(getContentDisplayImageUrl(url), url)
|
||||
assert.equal(getContentLightboxImageUrl(url), url)
|
||||
assert.equal(getContentDisplayImageSrcset(url), '')
|
||||
})
|
||||
|
||||
test('본문 이미지 srcset은 720과 1600 파생 이미지를 함께 제공한다', () => {
|
||||
assert.equal(
|
||||
getContentDisplayImageSrcset('/uploads/posts/2026/07/sample.webp'),
|
||||
[
|
||||
'/uploads/posts/2026/07/thumbs/sample-body-720.webp?v=20260702-1 720w',
|
||||
'/uploads/posts/2026/07/thumbs/sample-body-1600.webp?v=20260702-1 1600w'
|
||||
].join(', ')
|
||||
)
|
||||
})
|
||||
|
||||
test('갤러리 sizes는 행 이미지 개수 기준으로 계산한다', () => {
|
||||
assert.equal(getGalleryImageSizes(1), '(max-width: 768px) 100vw, 100vw')
|
||||
assert.equal(getGalleryImageSizes(2), '(max-width: 768px) 100vw, 50vw')
|
||||
assert.equal(getGalleryImageSizes(3), '(max-width: 768px) 100vw, 33vw')
|
||||
})
|
||||
Reference in New Issue
Block a user