에디터 블록 옵션 계산 분리
This commit is contained in:
230
tests/markdown-editor-block-options.test.js
Normal file
230
tests/markdown-editor-block-options.test.js
Normal file
@@ -0,0 +1,230 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
createCalloutOptionsReplacementPlan,
|
||||
createCodeOptionsReplacementPlan,
|
||||
createEmbedUrlReplacementPlan,
|
||||
createGalleryImageMovePlan,
|
||||
createGalleryImagesAppendPlan,
|
||||
createLiveInlineColorValue,
|
||||
createMediaImageRemovePlan,
|
||||
createMediaImagesReplacementPlan,
|
||||
createMediaImageUpdatePlan,
|
||||
createMediaUseAltPatch,
|
||||
createQuoteBackgroundValue,
|
||||
createSourceInlineColorValue,
|
||||
createToggleOptionsReplacementPlan
|
||||
} from '../lib/markdown-editor-block-options.js'
|
||||
|
||||
const imageBlock = {
|
||||
kind: 'image',
|
||||
startLine: 2,
|
||||
endLine: 2,
|
||||
images: [{
|
||||
url: '/uploads/one.png',
|
||||
caption: '',
|
||||
useAlt: false,
|
||||
width: 'regular',
|
||||
pixelWidth: null
|
||||
}]
|
||||
}
|
||||
|
||||
const galleryBlock = {
|
||||
kind: 'gallery',
|
||||
startLine: 1,
|
||||
endLine: 4,
|
||||
images: [
|
||||
{ url: '/uploads/one.png', caption: '', useAlt: false, width: 'regular', pixelWidth: null },
|
||||
{ url: '/uploads/two.png', caption: '둘', useAlt: true, width: 'regular', pixelWidth: 235 }
|
||||
]
|
||||
}
|
||||
|
||||
test('단일 이미지와 갤러리 이미지 목록 교체 계획을 만든다', () => {
|
||||
assert.deepEqual(createMediaImagesReplacementPlan(imageBlock, []), {
|
||||
startLine: 2,
|
||||
endLine: 2,
|
||||
replacementLines: []
|
||||
})
|
||||
|
||||
assert.deepEqual(createMediaImagesReplacementPlan(galleryBlock, galleryBlock.images), {
|
||||
startLine: 1,
|
||||
endLine: 4,
|
||||
replacementLines: [
|
||||
':::gallery',
|
||||
'',
|
||||
'{size=235}',
|
||||
':::'
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('미디어 이미지 수정과 삭제 계획을 만든다', () => {
|
||||
assert.deepEqual(createMediaImageUpdatePlan(imageBlock, 0, { caption: '캡션', useAlt: true }), {
|
||||
startLine: 2,
|
||||
endLine: 2,
|
||||
replacementLines: ['']
|
||||
})
|
||||
|
||||
assert.deepEqual(createMediaImageRemovePlan(galleryBlock, 1), {
|
||||
startLine: 1,
|
||||
endLine: 4,
|
||||
replacementLines: [
|
||||
':::gallery',
|
||||
'',
|
||||
':::'
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('파일명 캡션 사용 patch를 만든다', () => {
|
||||
assert.deepEqual(createMediaUseAltPatch({
|
||||
url: '/uploads/posts/2026/07/sample-car.png',
|
||||
caption: '',
|
||||
legacyBracketLabel: ''
|
||||
}, true), {
|
||||
useAlt: true,
|
||||
caption: 'sample-car.png'
|
||||
})
|
||||
|
||||
assert.deepEqual(createMediaUseAltPatch({
|
||||
url: '/uploads/posts/2026/07/sample-car.png',
|
||||
caption: 'sample-car.png',
|
||||
legacyBracketLabel: ''
|
||||
}, false), {
|
||||
useAlt: false,
|
||||
caption: ''
|
||||
})
|
||||
})
|
||||
|
||||
test('갤러리 이미지 이동과 추가 계획을 만든다', () => {
|
||||
assert.equal(createGalleryImageMovePlan(galleryBlock, 0, -1), null)
|
||||
assert.deepEqual(createGalleryImageMovePlan(galleryBlock, 0, 1), {
|
||||
startLine: 1,
|
||||
endLine: 4,
|
||||
replacementLines: [
|
||||
':::gallery',
|
||||
'{size=235}',
|
||||
'',
|
||||
':::'
|
||||
]
|
||||
})
|
||||
|
||||
assert.deepEqual(createGalleryImagesAppendPlan(galleryBlock, [{ url: '/uploads/three.png' }]), {
|
||||
startLine: 1,
|
||||
endLine: 4,
|
||||
replacementLines: [
|
||||
':::gallery',
|
||||
'',
|
||||
'{size=235}',
|
||||
'',
|
||||
':::'
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('임베드 블록 값 교체 계획을 만든다', () => {
|
||||
const block = { kind: 'iframe', startLine: 3, endLine: 5 }
|
||||
|
||||
assert.deepEqual(createEmbedUrlReplacementPlan(block, ' https://example.com '), {
|
||||
startLine: 3,
|
||||
endLine: 5,
|
||||
replacementLines: [':::iframe', 'https://example.com', ':::']
|
||||
})
|
||||
|
||||
assert.deepEqual(createEmbedUrlReplacementPlan(block, ' '), {
|
||||
startLine: 3,
|
||||
endLine: 5,
|
||||
replacementLines: []
|
||||
})
|
||||
})
|
||||
|
||||
test('인용 배경색은 옵션 줄을 삽입하거나 교체한다', () => {
|
||||
assert.equal(createQuoteBackgroundValue({
|
||||
value: '> 인용',
|
||||
block: { kind: 'quote', startLine: 0, endLine: 0, hasQuoteOptions: false },
|
||||
background: 'blue'
|
||||
}), '> [!bg=blue]\n> 인용')
|
||||
|
||||
assert.equal(createQuoteBackgroundValue({
|
||||
value: '> [!bg=gray]\n> 인용',
|
||||
block: { kind: 'quote', startLine: 0, endLine: 1, hasQuoteOptions: true },
|
||||
background: 'purple'
|
||||
}), '> [!bg=purple]\n> 인용')
|
||||
})
|
||||
|
||||
test('콜아웃·코드·토글 선언 줄 교체 계획을 만든다', () => {
|
||||
assert.deepEqual(createCalloutOptionsReplacementPlan({
|
||||
kind: 'callout',
|
||||
startLine: 1,
|
||||
endLine: 3,
|
||||
calloutEmojiEnabled: false,
|
||||
calloutEmoji: '💡',
|
||||
calloutBackground: 'gray',
|
||||
title: '기존'
|
||||
}, {
|
||||
calloutEmojiEnabled: true,
|
||||
calloutBackground: 'blue',
|
||||
title: '주의'
|
||||
}), {
|
||||
startLine: 1,
|
||||
endLine: 3,
|
||||
replacementLines: [':::callout emoji=💡 bg=blue title=주의']
|
||||
})
|
||||
|
||||
assert.deepEqual(createCodeOptionsReplacementPlan({
|
||||
kind: 'code',
|
||||
startLine: 5,
|
||||
endLine: 7,
|
||||
language: 'javascript',
|
||||
showLineNumbers: false
|
||||
}, {
|
||||
showLineNumbers: true
|
||||
}), {
|
||||
startLine: 5,
|
||||
endLine: 7,
|
||||
replacementLines: ['```javascript line-numbers']
|
||||
})
|
||||
|
||||
assert.deepEqual(createToggleOptionsReplacementPlan({
|
||||
kind: 'toggle',
|
||||
startLine: 9,
|
||||
endLine: 11,
|
||||
title: '더 보기',
|
||||
defaultOpen: false
|
||||
}, {
|
||||
defaultOpen: true
|
||||
}), {
|
||||
startLine: 9,
|
||||
endLine: 11,
|
||||
replacementLines: [':::toggle open 더 보기']
|
||||
})
|
||||
})
|
||||
|
||||
test('소스와 라이브 인라인 색상 적용 결과를 만든다', () => {
|
||||
assert.deepEqual(createSourceInlineColorValue({
|
||||
value: 'hello world',
|
||||
context: { kind: 'inline-color', mode: 'source', start: 6, end: 11 },
|
||||
color: 'red'
|
||||
}), {
|
||||
value: 'hello ::red[world]',
|
||||
selectionStart: 18,
|
||||
selectionEnd: 18
|
||||
})
|
||||
|
||||
assert.deepEqual(createLiveInlineColorValue({
|
||||
value: '- 안녕하세요',
|
||||
context: {
|
||||
kind: 'inline-color',
|
||||
mode: 'live',
|
||||
sourceLine: 0,
|
||||
bodyText: '안녕하세요',
|
||||
startOffset: 0,
|
||||
endOffset: 2
|
||||
},
|
||||
color: 'blue'
|
||||
}), {
|
||||
value: '- ::blue[안녕]하세요',
|
||||
focusLine: 0,
|
||||
focusOffset: 2
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user