返回 oh-my-ppt
page-frame-padding.test.ts
根目录 / tests / unit / tools / page-frame-padding.test.ts
1 import { describe, expect, it } from 'vitest'
2 import { readFileSync } from 'fs'
3 import path from 'path'
4
5 const projectRoot = path.resolve(__dirname, '../../..')
6 const pageShellSource = readFileSync(
7 path.join(projectRoot, 'src/main/presentation/html/page-shell.ts'),
8 'utf-8'
9 )
10 const pageWriterCoreSource = readFileSync(
11 path.join(projectRoot, 'src/main/presentation/html/page-writer-core.ts'),
12 'utf-8'
13 )
14 const templateSource = readFileSync(
15 path.join(projectRoot, 'src/main/session/template-builder.ts'),
16 'utf-8'
17 )
18 const indexRuntimeSource = readFileSync(
19 path.join(projectRoot, 'resources/index-runtime.js'),
20 'utf-8'
21 )
22 const previewIframeSource = readFileSync(
23 path.join(projectRoot, 'src/renderer/src/components/preview/PreviewIframe.tsx'),
24 'utf-8'
25 )
26 const generationThumbnailSource = readFileSync(
27 path.join(projectRoot, 'src/renderer/src/components/session-generating/GenerationThumbnail.tsx'),
28 'utf-8'
29 )
30 const pageThumbnailSource = readFileSync(
31 path.join(projectRoot, 'src/renderer/src/components/session-detail/sidebar/PageThumbnail.tsx'),
32 'utf-8'
33 )
34 const browseViewSource = readFileSync(
35 path.join(projectRoot, 'src/renderer/src/components/session-detail/browse/BrowseView.tsx'),
36 'utf-8'
37 )
38 const generationPreviewGridSource = readFileSync(
39 path.join(projectRoot, 'src/renderer/src/components/session-generating/GenerationPreviewGrid.tsx'),
40 'utf-8'
41 )
42
43 describe('page runtime frame padding', () => {
44 it('does not add default padding to the page root', () => {
45 expect(pageShellSource).toContain('.ppt-page-root.p-2,')
46 expect(pageShellSource).toContain('padding: 0;')
47 expect(pageShellSource).not.toContain('padding: 0.5rem')
48 expect(pageShellSource).not.toContain('padding: 2rem')
49 expect(pageShellSource).not.toContain('padding: 3rem')
50 })
51
52 it('creates scaffold pages without padding utility classes on the root frame', () => {
53 expect(templateSource).toContain(
54 '<main class="ppt-page-root" data-ppt-guard-root="1" data-ppt-slide-size-id='
55 )
56 expect(templateSource).not.toContain('ppt-page-root p-2')
57 expect(pageWriterCoreSource).toContain(
58 '<main class="ppt-page-root" data-ppt-guard-root="1" data-ppt-slide-size-id='
59 )
60 expect(pageWriterCoreSource).not.toContain('ppt-page-root p-2')
61 })
62
63 it('keeps preview scaling letterboxed to match the session canvas', () => {
64 expect(indexRuntimeSource).toContain(
65 'Math.min(rect.width / slideWidth, rect.height / slideHeight)'
66 )
67 expect(indexRuntimeSource).not.toContain(
68 'Math.max(rect.width / slideWidth, rect.height / slideHeight)'
69 )
70 expect(indexRuntimeSource).toContain(
71 'Math.max(0, (rect.width - slideWidth * scale) / 2)'
72 )
73
74 expect(previewIframeSource).toContain(
75 'Math.min(width / slideSize.width, height / slideSize.height)'
76 )
77 expect(previewIframeSource).not.toContain(
78 'Math.max(width / slideSize.width, height / slideSize.height)'
79 )
80 expect(previewIframeSource).toContain(
81 'Math.max(0, (width - slideSize.width * nextScale) / 2)'
82 )
83 })
84
85 it('keeps generation thumbnail card surfaces aligned with their grid cell', () => {
86 expect(generationPreviewGridSource).toContain('className="min-w-0 w-full"')
87 expect(generationThumbnailSource).toContain('flex w-full min-w-0 flex-col')
88 expect(generationThumbnailSource).toContain('p-1.5')
89 expect(generationThumbnailSource).toContain('h-[180px] w-full min-w-0 shrink-0')
90 expect(generationThumbnailSource).not.toContain('rounded-[0.9rem]')
91 expect(generationThumbnailSource).toContain(
92 "slideSize.width >= slideSize.height"
93 )
94 expect(generationThumbnailSource).toContain("height: '100%'")
95 expect(generationThumbnailSource).toContain("contain: 'paint'")
96 expect(generationThumbnailSource).toContain('flex w-full min-w-0 items-center')
97 })
98
99 it('keeps list thumbnails in fixed-height viewports with centered slide canvases', () => {
100 expect(pageThumbnailSource).toContain('h-[138px] w-full items-center justify-center')
101 expect(browseViewSource).toContain('h-[220px] w-full items-center justify-center')
102 for (const source of [generationThumbnailSource, pageThumbnailSource, browseViewSource]) {
103 expect(source).toContain("slideSize.width >= slideSize.height")
104 expect(source).toContain("width: '100%'")
105 expect(source).toContain("height: '100%'")
106 expect(source).not.toContain('aspectRatio: `${slideSize.width}/${slideSize.height}`, contain')
107 }
108 })
109
110 it('uses black letterbox bars in presentation mode', () => {
111 expect(templateSource).toContain('body.present { background: #000000; }')
112 expect(templateSource).toContain('body.present .ppt-preview-viewport { border-radius: 0; background: #000000; }')
113 expect(indexRuntimeSource).toContain('function ensurePresentBackgroundStyles()')
114 expect(indexRuntimeSource).toContain('body.present { background: #000000 !important; }')
115 })
116 })
117
117 lines TYPESCRIPT