| 1 | import fs from 'fs' |
| 2 | import path from 'path' |
| 3 | import { describe, expect, it } from 'vitest' |
| 4 | |
| 5 | const readSource = (filePath: string): string => fs.readFileSync(path.resolve(filePath), 'utf8') |
| 6 | |
| 7 | describe('slide master runtime contract', () => { |
| 8 | it('tracks the master directory and waits for it before every browser capture path', () => { |
| 9 | const historySource = readSource('src/main/history/git-history-service.ts') |
| 10 | const exportScript = readSource('src/main/io/html-pptx/browser-scripts.ts') |
| 11 | const videoExporter = readSource('src/main/io/html-video/exporter.ts') |
| 12 | const pageExport = readSource('src/main/ipc/runtime/page-export.ts') |
| 13 | const pptxRenderer = readSource('src/main/io/html-pptx/renderer.ts') |
| 14 | const thumbnails = readSource('src/main/io/thumbnails/html-thumbnail-service.ts') |
| 15 | |
| 16 | expect(historySource).toContain("rel === 'master/master.css'") |
| 17 | expect(historySource).toContain("rel === 'master/master.html'") |
| 18 | expect(historySource).toContain("rel === 'master/layouts.json'") |
| 19 | expect(exportScript).toContain('link[data-ppt-master="1"]') |
| 20 | expect(exportScript).toContain('母版样式表加载失败') |
| 21 | expect(exportScript).toContain('_pptMasterExport') |
| 22 | expect(exportScript).toContain("get('_pptMasterExpected') === '1'") |
| 23 | expect(exportScript).toContain("get('_pptMasterElementsExpected') === '1'") |
| 24 | expect(exportScript).toContain('assertMasterElementsReady') |
| 25 | expect(exportScript).toContain('window.PPT?.whenReadyForPrint') |
| 26 | expect(videoExporter).toContain('link[data-ppt-master="1"]') |
| 27 | expect(videoExporter).toContain('母版样式表加载失败') |
| 28 | expect(videoExporter).toContain('_pptMasterExport') |
| 29 | expect(videoExporter).toContain("get('_pptMasterExpected') === '1'") |
| 30 | expect(videoExporter).toContain("get('_pptMasterElementsExpected') === '1'") |
| 31 | expect(videoExporter).toContain('assertMasterElementsReady') |
| 32 | expect(videoExporter).toContain('window.PPT?.whenReadyForPrint') |
| 33 | expect(pageExport).toContain("'_pptMasterExpected'") |
| 34 | expect(pageExport).toContain("'_pptMasterElementsExpected'") |
| 35 | expect(pptxRenderer).toContain("'_pptMasterExpected'") |
| 36 | expect(pptxRenderer).toContain("'_pptMasterElementsExpected'") |
| 37 | expect(thumbnails).toContain("'_pptMasterExpected'") |
| 38 | expect(thumbnails).toContain("'_pptMasterElementsExpected'") |
| 39 | }) |
| 40 | |
| 41 | it('injects global elements as a fixed root layer and tracks the work for print export', () => { |
| 42 | const runtime = readSource('resources/ppt-runtime.js') |
| 43 | |
| 44 | expect(runtime).toContain('loadMasterElementsWhenReady') |
| 45 | expect(runtime).toContain('./master/master.html') |
| 46 | expect(runtime).toContain('data-ppt-master-elements-layer') |
| 47 | expect(runtime).toContain('data-ppt-master-off') |
| 48 | expect(runtime).toContain('trackPrintTask(masterElementsTask)') |
| 49 | expect(runtime).toContain('assertMasterElementsReady') |
| 50 | expect(runtime).toContain('母版全局元素加载失败') |
| 51 | }) |
| 52 | |
| 53 | it('exposes an ignore-cache preview refresh and places the control in workspace tabs', () => { |
| 54 | const previewSource = readSource('src/renderer/src/components/preview/PreviewIframe.tsx') |
| 55 | const runtimeStoreSource = readSource('src/renderer/src/store/sessionDetailRuntimeStore.ts') |
| 56 | const tabsSource = readSource( |
| 57 | 'src/renderer/src/components/session-detail/workspace/toolbar/WorkspaceTabs.tsx' |
| 58 | ) |
| 59 | |
| 60 | expect(previewSource).toContain('reloadIgnoringCache') |
| 61 | expect(runtimeStoreSource).toContain('reloadCurrentPreviewIgnoringCache') |
| 62 | expect(tabsSource).toContain('<MasterWorkbenchPanel />') |
| 63 | }) |
| 64 | |
| 65 | it('keeps master creation out of shared edit and retry context', () => { |
| 66 | const generationContext = readSource('src/main/generation/context.ts') |
| 67 | |
| 68 | expect(generationContext).not.toContain('createSessionMasterIfMissing') |
| 69 | }) |
| 70 | |
| 71 | it('prevents stale master form data and guaranteed failed saves', () => { |
| 72 | const panelSource = readSource( |
| 73 | 'src/renderer/src/components/session-detail/workspace/workbench/MasterWorkbenchPanel.tsx' |
| 74 | ) |
| 75 | |
| 76 | expect(panelSource).toContain('masterLoadRequestRef') |
| 77 | expect(panelSource).toContain('currentSessionIdRef') |
| 78 | expect(panelSource).toContain('status?.missingPageCount') |
| 79 | }) |
| 80 | }) |
| 81 |