관리자 라이브 전환 포커스 계산 분리
This commit is contained in:
122
tests/markdown-editor-focus.test.js
Normal file
122
tests/markdown-editor-focus.test.js
Normal file
@@ -0,0 +1,122 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
findCodeFenceRangeAtLine,
|
||||
findNextFencedClosingLine,
|
||||
findPreviousFencedOpeningLine,
|
||||
isCodeFenceBodyLine,
|
||||
resolvePreviewFocusPosition
|
||||
} from '../lib/markdown-editor-focus.js'
|
||||
|
||||
test('fenced 블록의 이전 여는 줄과 다음 닫는 줄을 찾는다', () => {
|
||||
const lines = [
|
||||
'앞',
|
||||
':::callout',
|
||||
'본문',
|
||||
':::',
|
||||
'뒤'
|
||||
]
|
||||
|
||||
assert.equal(findPreviousFencedOpeningLine(
|
||||
lines,
|
||||
3,
|
||||
(line) => line.startsWith(':::callout')
|
||||
), 1)
|
||||
assert.equal(findNextFencedClosingLine(lines, 1, ':::'), 3)
|
||||
})
|
||||
|
||||
test('코드 펜스 범위와 본문 줄을 판별한다', () => {
|
||||
const lines = [
|
||||
'앞',
|
||||
'```js',
|
||||
'console.log(1)',
|
||||
'```',
|
||||
'뒤'
|
||||
]
|
||||
|
||||
assert.deepEqual(findCodeFenceRangeAtLine(lines, 1), {
|
||||
openingLine: 1,
|
||||
closingLine: 3
|
||||
})
|
||||
assert.deepEqual(findCodeFenceRangeAtLine(lines, 2), {
|
||||
openingLine: 1,
|
||||
closingLine: 3
|
||||
})
|
||||
assert.equal(isCodeFenceBodyLine(lines, 2), true)
|
||||
assert.equal(isCodeFenceBodyLine(lines, 3), false)
|
||||
assert.equal(isCodeFenceBodyLine(lines, 4), false)
|
||||
})
|
||||
|
||||
test('닫히지 않은 코드 펜스는 이후 줄을 본문으로 본다', () => {
|
||||
const lines = [
|
||||
'```',
|
||||
'code'
|
||||
]
|
||||
|
||||
assert.deepEqual(findCodeFenceRangeAtLine(lines, 0), {
|
||||
openingLine: 0,
|
||||
closingLine: null
|
||||
})
|
||||
assert.equal(isCodeFenceBodyLine(lines, 1), true)
|
||||
})
|
||||
|
||||
test('라이브 포커스는 코드 선언 줄에서 첫 본문 줄로 이동한다', () => {
|
||||
const value = [
|
||||
'앞',
|
||||
'```js',
|
||||
'const a = 1',
|
||||
'```',
|
||||
'뒤'
|
||||
].join('\n')
|
||||
|
||||
assert.deepEqual(resolvePreviewFocusPosition({
|
||||
value,
|
||||
line: 1,
|
||||
offset: 5
|
||||
}), {
|
||||
line: 2,
|
||||
offset: 0
|
||||
})
|
||||
})
|
||||
|
||||
test('라이브 포커스는 callout과 toggle 선언 줄에서 본문 줄로 이동한다', () => {
|
||||
assert.deepEqual(resolvePreviewFocusPosition({
|
||||
value: ':::callout title=주의\n본문\n:::',
|
||||
line: 0,
|
||||
offset: 10
|
||||
}), {
|
||||
line: 1,
|
||||
offset: 0
|
||||
})
|
||||
|
||||
assert.deepEqual(resolvePreviewFocusPosition({
|
||||
value: ':::toggle title=더보기\n본문\n:::',
|
||||
line: 0,
|
||||
offset: 10
|
||||
}), {
|
||||
line: 1,
|
||||
offset: 0
|
||||
})
|
||||
})
|
||||
|
||||
test('라이브 포커스는 fenced 닫는 줄에서 이전 본문 줄로 보정한다', () => {
|
||||
assert.deepEqual(resolvePreviewFocusPosition({
|
||||
value: ':::callout\n본문\n:::',
|
||||
line: 2,
|
||||
offset: 4
|
||||
}), {
|
||||
line: 1,
|
||||
offset: 4
|
||||
})
|
||||
})
|
||||
|
||||
test('라이브 포커스는 인용 옵션 줄에서 실제 인용 본문 줄로 이동한다', () => {
|
||||
assert.deepEqual(resolvePreviewFocusPosition({
|
||||
value: '> [!bg=blue]\n> 본문',
|
||||
line: 0,
|
||||
offset: 7
|
||||
}), {
|
||||
line: 1,
|
||||
offset: 0
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user