返回 oh-my-ppt
page-writer-slide-size.test.ts
根目录 / tests / unit / tools / page-writer-slide-size.test.ts
1 // @vitest-environment happy-dom
2
3 import { describe, expect, it, vi } from 'vitest'
4
5 vi.mock('electron', () => ({
6 app: {
7 getPath: () => '/tmp'
8 },
9 BrowserWindow: class BrowserWindow {},
10 ipcMain: {},
11 session: {}
12 }))
13
14 vi.mock('@electron-toolkit/utils', () => ({
15 is: {
16 dev: false
17 }
18 }))
19 import {
20 buildBasePageStyleTag,
21 buildFitScript,
22 preprocessPageHtml
23 } from '../../../src/main/presentation/html/page-writer-core'
24 import {
25 buildPageScaffoldHtml,
26 buildProjectIndexHtml
27 } from '../../../src/main/session/template-builder'
28 import { SLIDE_SIZE_PRESETS, requireSlideSizePreset } from '../../../src/shared/slide-size'
29
30 describe('page writer slide size', () => {
31 const portrait = requireSlideSizePreset('vertical-9-16')
32
33 it('injects dynamic guard styles, fit dimensions and root metadata', () => {
34 expect(buildBasePageStyleTag(portrait)).toContain('--ppt-slide-width: 900px')
35 expect(buildBasePageStyleTag(portrait)).toContain('--ppt-slide-height: 1600px')
36 expect(buildFitScript(portrait)).toContain('const WIDTH = 900')
37 expect(buildFitScript(portrait)).toContain('const HEIGHT = 1600')
38
39 const html = buildPageScaffoldHtml(
40 { pageNumber: 1, pageId: 'page-1', title: 'Portrait' },
41 portrait
42 )
43 expect(html).toContain('data-ppt-slide-size-id="vertical-9-16"')
44 expect(html).toContain('data-ppt-width="900"')
45 expect(html).toContain('data-ppt-height="1600"')
46 })
47
48 it('writes deck metadata for the standalone index shell', () => {
49 const html = buildProjectIndexHtml(
50 'Deck',
51 [{ pageNumber: 1, pageId: 'page-1', title: 'One', htmlPath: 'page-1.html' }],
52 portrait
53 )
54 expect(html).toContain('--ppt-slide-width: 900px')
55 expect(html).toContain('"slideSizeId":"vertical-9-16"')
56 expect(html).toContain('"height":1600')
57 })
58
59 it.each(SLIDE_SIZE_PRESETS)('strips fixed canvas classes for %s', (preset) => {
60 const slideSize = requireSlideSizePreset(preset.id)
61 const aspect =
62 slideSize.id === 'wide-16-9'
63 ? '16/9'
64 : slideSize.id === 'vertical-9-16'
65 ? '9/16'
66 : slideSize.id === 'standard-4-3'
67 ? '4/3'
68 : slideSize.id === 'square-1-1'
69 ? '1/1'
70 : '3/4'
71 const html = preprocessPageHtml(
72 `<div class="w-[${slideSize.width}px] h-[${slideSize.height}px] aspect-[${aspect}] size-[${slideSize.width}px]" style="width: ${slideSize.width}px; height: ${slideSize.height}px"><p>Content</p></div>`
73 )
74 expect(html).not.toContain(`w-[${slideSize.width}px]`)
75 expect(html).not.toContain(`h-[${slideSize.height}px]`)
76 expect(html).not.toContain(`aspect-[${aspect}]`)
77 expect(html).not.toContain(`size-[${slideSize.width}px]`)
78 expect(html).not.toContain(`width: ${slideSize.width}px`)
79 expect(html).not.toContain(`height: ${slideSize.height}px`)
80 })
81 })
82
82 lines TYPESCRIPT