76 lines
2.6 KiB
JavaScript
76 lines
2.6 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { ref } from 'vue'
|
|
import { useContentMarkdownBlocks } from '../composables/useContentMarkdownBlocks.js'
|
|
|
|
/**
|
|
* 긴 본문 테스트용 Markdown을 만든다.
|
|
* @param {number} count - 문단 개수
|
|
* @param {number} length - 문단 길이
|
|
* @returns {string} Markdown 본문
|
|
*/
|
|
const createLongMarkdown = (count, length) => {
|
|
return Array.from({ length: count }, (_, index) => `문단 ${index} ${'가'.repeat(length)}`).join('\n\n')
|
|
}
|
|
|
|
test('공개 Markdown 블록 계산은 본문 파싱과 제목 ID 생성을 관리한다', () => {
|
|
const state = useContentMarkdownBlocks({
|
|
content: [
|
|
'# 같은 제목',
|
|
'## 같은 제목',
|
|
'',
|
|
'',
|
|
':::gallery',
|
|
'',
|
|
':::'
|
|
].join('\n'),
|
|
interactive: false,
|
|
inArticleAdCode: ''
|
|
})
|
|
|
|
assert.deepEqual(state.blocks.value.map((block) => block.type), ['heading', 'heading', 'spacer', 'image', 'gallery'])
|
|
assert.deepEqual(Object.values(state.headingIdsByBlock.value), ['같은-제목', '같은-제목-2'])
|
|
assert.deepEqual(
|
|
state.contentLightboxImages.value.map((image) => image.url),
|
|
['/uploads/posts/2026/07/a.jpg', '/uploads/posts/2026/07/b.jpg']
|
|
)
|
|
})
|
|
|
|
test('공개 Markdown 블록 계산은 광고 코드를 렌더 블록에 삽입하고 라이브 편집에서는 제외한다', () => {
|
|
const content = ref(createLongMarkdown(14, 180))
|
|
const interactive = ref(false)
|
|
const inArticleAdCode = ref('<ins>ad</ins>')
|
|
const state = useContentMarkdownBlocks({ content, interactive, inArticleAdCode })
|
|
|
|
assert.equal(state.normalizedInArticleAdCode.value, '<ins>ad</ins>')
|
|
assert.equal(state.inArticleAdAfterBlockIds.value.length, 1)
|
|
assert.equal(state.renderBlocks.value.filter((block) => block.type === 'in-article-ad').length, 1)
|
|
|
|
interactive.value = true
|
|
|
|
assert.deepEqual(state.inArticleAdAfterBlockIds.value, [])
|
|
assert.equal(state.renderBlocks.value.some((block) => block.type === 'in-article-ad'), false)
|
|
})
|
|
|
|
test('공개 Markdown 블록 계산은 마지막 블록 범위 기준으로 하단 삽입 줄을 계산한다', () => {
|
|
const content = ref([
|
|
'첫 문단',
|
|
'',
|
|
':::gallery',
|
|
'',
|
|
'',
|
|
':::'
|
|
].join('\n'))
|
|
const state = useContentMarkdownBlocks({
|
|
content,
|
|
interactive: true,
|
|
inArticleAdCode: ''
|
|
})
|
|
|
|
assert.equal(state.tailInsertBeforeLine.value, 6)
|
|
|
|
content.value = '한 줄'
|
|
|
|
assert.equal(state.tailInsertBeforeLine.value, 1)
|
|
})
|