fe127ec3ed
Deliver schema v9, book/chapter IPC extensions, BookSettingsTab, chapter meta/tags, AI session menu, focus mode and TTS, template context enrich, and Wave 1 E2E coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
93 lines
2.2 KiB
TypeScript
93 lines
2.2 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { buildTemplateContext } from '../../src/shared/chapter-template'
|
|
import type { Chapter, OutlineItem, SettingEntry, Volume } from '../../src/shared/types'
|
|
|
|
const volumeId = 'vol-1'
|
|
const chapterId = 'ch-1'
|
|
|
|
const volumes: Volume[] = [
|
|
{ id: volumeId, name: '第一卷', description: '', sortOrder: 0, createdAt: '', updatedAt: '' }
|
|
]
|
|
|
|
const chapters: Chapter[] = [
|
|
{
|
|
id: 'ch-prev',
|
|
volumeId,
|
|
title: '序章',
|
|
content: '',
|
|
status: 'draft',
|
|
publishStatus: 'draft',
|
|
sortOrder: 0,
|
|
wordCount: 0,
|
|
cursorOffset: 0,
|
|
createdAt: '',
|
|
updatedAt: ''
|
|
}
|
|
]
|
|
|
|
describe('buildTemplateContext', () => {
|
|
it('UT-TEMPL-05: characterList from settings', () => {
|
|
const settings: SettingEntry[] = [
|
|
{
|
|
id: 's1',
|
|
type: 'character',
|
|
name: '林远',
|
|
description: '',
|
|
properties: {},
|
|
createdAt: '',
|
|
updatedAt: ''
|
|
},
|
|
{
|
|
id: 's2',
|
|
type: 'character',
|
|
name: '苏晴',
|
|
description: '',
|
|
properties: {},
|
|
createdAt: '',
|
|
updatedAt: ''
|
|
}
|
|
]
|
|
const ctx = buildTemplateContext({
|
|
chapterTitle: '新章',
|
|
penName: '笔名',
|
|
volumes,
|
|
chapters,
|
|
outlines: [],
|
|
settings,
|
|
activeVolumeId: volumeId
|
|
})
|
|
expect(ctx.characterList).toContain('林远')
|
|
expect(ctx.characterList).toContain('苏晴')
|
|
expect(ctx.chapterNumber).toBe(2)
|
|
expect(ctx.previousChapterTitle).toBe('序章')
|
|
})
|
|
|
|
it('UT-TEMPL-06: outlineItem from linked outline', () => {
|
|
const outlines: OutlineItem[] = [
|
|
{
|
|
id: 'o1',
|
|
parentId: null,
|
|
title: '主角觉醒',
|
|
description: '',
|
|
status: 'planned',
|
|
expectedWordCount: null,
|
|
chapterId,
|
|
sortOrder: 0,
|
|
createdAt: '',
|
|
updatedAt: ''
|
|
}
|
|
]
|
|
const ctx = buildTemplateContext({
|
|
chapterTitle: '第一章',
|
|
penName: '笔名',
|
|
volumes,
|
|
chapters,
|
|
outlines,
|
|
settings: [],
|
|
activeVolumeId: volumeId,
|
|
selectedChapterId: chapterId
|
|
})
|
|
expect(ctx.outlineItem).toBe('主角觉醒')
|
|
})
|
|
})
|