返回 oh-my-ppt
document-plan-page-skeleton.test.ts
根目录 / tests / unit / io / document-plan-page-skeleton.test.ts
1 import { describe, expect, it } from 'vitest'
2 import { scanDocumentOutline } from '../../../src/main/io/document-outline-scan'
3 import {
4 buildDocumentPlanPageSkeleton,
5 sanitizeDocumentPlanPageSkeletonContent
6 } from '../../../src/main/io/document-plan-page-skeleton'
7
8 describe('document plan page skeleton', () => {
9 it('derives an authoritative skeleton only when source candidates match the plan count', () => {
10 const scan = scanDocumentOutline(
11 [
12 '# Source Manual',
13 '',
14 '## Market',
15 'Market details.',
16 '',
17 '## Execution',
18 'Execution details.'
19 ].join('\n')
20 )
21
22 const skeleton = buildDocumentPlanPageSkeleton({
23 scan,
24 pageCount: 2
25 })
26
27 expect(skeleton).toHaveLength(2)
28 expect(skeleton[0]).toMatchObject({
29 id: 'page-1',
30 pageNumber: 1,
31 title: 'Market',
32 sourceHeading: '## Market',
33 lineStart: 3
34 })
35 expect(
36 buildDocumentPlanPageSkeleton({
37 scan,
38 pageCount: 1
39 })
40 ).toEqual([])
41 expect(
42 buildDocumentPlanPageSkeleton({
43 scan,
44 pageCount: 2
45 })
46 ).toHaveLength(2)
47 })
48
49 it('keeps LLM summaries as skeleton reasons', () => {
50 const skeleton = [
51 {
52 pageNumber: 1,
53 title: '市场洞察',
54 role: 'content' as const,
55 sourceHeading: '## 市场洞察',
56 headingLevel: 2,
57 lineStart: 3,
58 lineEnd: 18,
59 reason: '说明市场增长信号和关键机会。'
60 }
61 ]
62
63 const sanitized = sanitizeDocumentPlanPageSkeletonContent({
64 pageSkeleton: skeleton
65 })
66
67 expect(sanitized[0].reason).toBe('说明市场增长信号和关键机会。')
68 })
69
70 it('drops internal scanner reasons when no model page purpose is available', () => {
71 const skeleton = [
72 {
73 pageNumber: 1,
74 title: 'Execution',
75 role: 'content' as const,
76 sourceHeading: '## Execution',
77 headingLevel: 2,
78 lineStart: 3,
79 lineEnd: 18,
80 reason: 'leaf ## section without standalone child sections'
81 }
82 ]
83
84 const sanitized = sanitizeDocumentPlanPageSkeletonContent({
85 pageSkeleton: skeleton
86 })
87
88 expect(sanitized[0].reason).toBe('')
89 })
90 })
91
91 lines TYPESCRIPT