返回 oh-my-ppt
static-background.test.ts
根目录 / tests / unit / html-pptx / static-background.test.ts
1 import { describe, expect, it } from 'vitest'
2 import {
3 isPptxStaticBackgroundShape,
4 resolvePptxCaptureRect,
5 resolvePptxExportLayout
6 } from '../../../src/main/io/html-pptx/static-background'
7 import { resolveSlideSize } from '../../../src/shared/slide-size'
8
9 describe('PPTX static background shape classification', () => {
10 it('keeps full-page and full-height column fills in the screenshot base', () => {
11 expect(isPptxStaticBackgroundShape({ x: 0, y: 0, w: 13.333, h: 7.5 })).toBe(true)
12 expect(isPptxStaticBackgroundShape({ x: 0, y: 0, w: 6.133, h: 7.5 })).toBe(true)
13 })
14
15 it('keeps regular cards and centered large content shapes editable', () => {
16 expect(isPptxStaticBackgroundShape({ x: 6.6, y: 4.3, w: 6.2, h: 0.8 })).toBe(false)
17 expect(isPptxStaticBackgroundShape({ x: 1, y: 1, w: 10, h: 5 })).toBe(false)
18 })
19
20 it('does not classify near-full-width header bands as slide backgrounds', () => {
21 expect(isPptxStaticBackgroundShape({ x: 0, y: 0, w: 13.3, h: 2.5 })).toBe(false)
22 })
23
24 it('uses 10 by 7.5in geometry for standard 4:3 slides', () => {
25 const layout = resolvePptxExportLayout(resolveSlideSize({ id: 'standard-4-3' }))
26
27 expect(layout).toMatchObject({
28 captureWidthPx: 1600,
29 captureHeightPx: 1200,
30 slideWidthIn: 10,
31 slideHeightIn: 7.5
32 })
33 expect(isPptxStaticBackgroundShape({ x: 0, y: 0, w: 10, h: 7.5 }, layout)).toBe(true)
34 expect(isPptxStaticBackgroundShape({ x: 0, y: 0, w: 10, h: 2.5 }, layout)).toBe(false)
35 })
36
37 it('clips overlay captures to the remaining pixels at the right and bottom edges', () => {
38 const layout = resolvePptxExportLayout(resolveSlideSize({ id: 'wide-16-9' }))
39
40 expect(resolvePptxCaptureRect({ x: 1550, y: 860, w: 100, h: 100 }, layout, 2)).toEqual({
41 x: 1548,
42 y: 858,
43 width: 52,
44 height: 42
45 })
46 expect(resolvePptxCaptureRect({ x: 1605, y: 20, w: 30, h: 20 }, layout, 2)).toBeNull()
47 })
48 })
49
49 lines TYPESCRIPT