공개 본문 인용 편집 분리
This commit is contained in:
128
tests/useContentMarkdownQuotes.test.js
Normal file
128
tests/useContentMarkdownQuotes.test.js
Normal file
@@ -0,0 +1,128 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { ref } from 'vue'
|
||||
import { useContentMarkdownQuotes } from '../composables/useContentMarkdownQuotes.js'
|
||||
|
||||
/**
|
||||
* 테스트용 인용 편집 상태를 만든다.
|
||||
* @param {string} contentText - Markdown 본문
|
||||
* @returns {{ calls: Object, pendingFocusLine: import('vue').Ref<number|null>, pendingFocusPosition: import('vue').Ref<string>, pendingFocusOffset: import('vue').Ref<number|null>, state: Object }}
|
||||
*/
|
||||
const createQuoteState = (contentText = '') => {
|
||||
const calls = {
|
||||
commits: [],
|
||||
inserts: []
|
||||
}
|
||||
const pendingFocusLine = ref(null)
|
||||
const pendingFocusPosition = ref('auto')
|
||||
const pendingFocusOffset = ref(null)
|
||||
const state = useContentMarkdownQuotes({
|
||||
content: ref(contentText),
|
||||
pendingFocusLine,
|
||||
pendingFocusPosition,
|
||||
pendingFocusOffset,
|
||||
commitInlineBlockLines: (block, replacementLines) => {
|
||||
calls.commits.push({ block, replacementLines })
|
||||
},
|
||||
insertBelowBlock: (block, options) => {
|
||||
calls.inserts.push({ block, options })
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
calls,
|
||||
pendingFocusLine,
|
||||
pendingFocusPosition,
|
||||
pendingFocusOffset,
|
||||
state
|
||||
}
|
||||
}
|
||||
|
||||
test('인용 블록 줄 생성은 옵션 선언 줄을 보존한다', () => {
|
||||
const block = {
|
||||
type: 'quote',
|
||||
meta: {
|
||||
startLine: 1,
|
||||
endLine: 3,
|
||||
quoteContentStartLine: 2
|
||||
}
|
||||
}
|
||||
const { state } = createQuoteState([
|
||||
'제목',
|
||||
'> [!bg=blue]',
|
||||
'> 이전',
|
||||
'> 둘째'
|
||||
].join('\n'))
|
||||
|
||||
assert.deepEqual(state.buildQuoteBlockLines(block, '새 본문\n다음'), [
|
||||
'> [!bg=blue]',
|
||||
'> 새 본문',
|
||||
'> 다음'
|
||||
])
|
||||
})
|
||||
|
||||
test('인용 블록 커밋은 브라우저 보정으로 생긴 >. 접두를 정리한다', () => {
|
||||
const block = {
|
||||
type: 'quote',
|
||||
meta: {
|
||||
startLine: 0,
|
||||
endLine: 0
|
||||
}
|
||||
}
|
||||
const { calls, state } = createQuoteState('> 이전')
|
||||
|
||||
state.onQuoteBlockCommit(block, '>. 발타자르')
|
||||
|
||||
assert.deepEqual(calls.commits[0], {
|
||||
block,
|
||||
replacementLines: ['> 발타자르']
|
||||
})
|
||||
})
|
||||
|
||||
test('인용 블록 아래 이탈은 현재 내용을 저장하고 아래 문단을 삽입한다', () => {
|
||||
const block = {
|
||||
type: 'quote',
|
||||
meta: {
|
||||
startLine: 3,
|
||||
endLine: 4
|
||||
}
|
||||
}
|
||||
const { calls, pendingFocusPosition, pendingFocusOffset, state } = createQuoteState([
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'> 이전',
|
||||
'> 둘째'
|
||||
].join('\n'))
|
||||
|
||||
state.onQuoteBlockInsertBelow(block, {
|
||||
value: '저장',
|
||||
before: '저장',
|
||||
after: '',
|
||||
caretAtEnd: true
|
||||
})
|
||||
|
||||
assert.equal(pendingFocusPosition.value, 'start')
|
||||
assert.equal(pendingFocusOffset.value, 0)
|
||||
assert.deepEqual(calls.commits[0].replacementLines, ['> 저장'])
|
||||
assert.deepEqual(calls.inserts[0], { block, options: { lines: [''] } })
|
||||
})
|
||||
|
||||
test('인용 블록 문단 복귀는 인용 마커 없이 원문 줄을 저장한다', () => {
|
||||
const block = {
|
||||
type: 'quote',
|
||||
meta: {
|
||||
startLine: 5,
|
||||
endLine: 6
|
||||
}
|
||||
}
|
||||
const { calls, pendingFocusLine, pendingFocusPosition, state } = createQuoteState('> 이전')
|
||||
|
||||
state.onQuoteBlockConvertToParagraph(block, {
|
||||
value: '첫 줄\n둘째 줄'
|
||||
})
|
||||
|
||||
assert.equal(pendingFocusLine.value, 5)
|
||||
assert.equal(pendingFocusPosition.value, 'start')
|
||||
assert.deepEqual(calls.commits[0].replacementLines, ['첫 줄', '둘째 줄'])
|
||||
})
|
||||
Reference in New Issue
Block a user