返回 oh-my-ppt
edit-summary.test.ts
根目录 / tests / unit / session-detail / edit-summary.test.ts
1 import { describe, expect, it, vi } from 'vitest'
2 import type { EditContext } from '../../../src/main/generation/types'
3 import type { EditedPageDescriptor } from '../../../src/main/generation/generation-utils'
4 import { buildLocalSuccessfulEditSummary } from '../../../src/main/generation/edit-summary-core'
5 import { emitSuccessfulEditSummary } from '../../../src/main/generation/edit-summary'
6
7 const changedPage = {
8 pageNumber: 1
9 }
10
11 describe('edit summary', () => {
12 it('builds deterministic selector summaries from verified changed pages', () => {
13 expect(
14 buildLocalSuccessfulEditSummary({
15 appLocale: 'zh',
16 editScope: 'selector',
17 changedPages: [changedPage]
18 })
19 ).toBe('已完成第1页的选中元素修改。')
20 })
21
22 it('reports mixed deck outcomes from verified success and failure facts', () => {
23 expect(
24 buildLocalSuccessfulEditSummary({
25 appLocale: 'zh',
26 editScope: 'deck',
27 changedPages: [changedPage],
28 failedPageLabels: ['第3页']
29 })
30 ).toBe('部分修改完成:成功 第1页;失败 第3页。')
31 })
32
33 it('reports an all-failed deck edit instead of treating it as no change', () => {
34 expect(
35 buildLocalSuccessfulEditSummary({
36 appLocale: 'zh',
37 editScope: 'deck',
38 changedPages: [],
39 failedPageLabels: ['第1页', '第3页']
40 })
41 ).toBe('页面修改失败:第1页、第3页。')
42 })
43
44 it('keeps the no-change message for flows without failed pages', () => {
45 expect(
46 buildLocalSuccessfulEditSummary({
47 appLocale: 'en',
48 editScope: 'page',
49 changedPages: []
50 })
51 ).toBe('No page changes needed to be saved this time.')
52 })
53
54 it('does not fail a completed edit when the assistant message cannot be stored', async () => {
55 const emitAssistant = vi.fn().mockRejectedValue(new Error('message store unavailable'))
56 const context = {
57 appLocale: 'zh',
58 sessionId: 'session-1',
59 runId: 'run-1'
60 } as EditContext
61 const page = {
62 ...changedPage,
63 id: 'row-1',
64 title: '封面',
65 pageId: 'page-1',
66 html: '<section></section>',
67 htmlPath: '/tmp/page-1.html'
68 } as EditedPageDescriptor
69
70 await emitSuccessfulEditSummary(
71 context,
72 buildLocalSuccessfulEditSummary({
73 appLocale: context.appLocale,
74 changedPages: [page],
75 editScope: 'page'
76 }),
77 emitAssistant
78 )
79
80 expect(emitAssistant).toHaveBeenCalledWith(context, '修改完成:第1页。')
81 })
82 })
83
83 lines TYPESCRIPT