返回 oh-my-ppt
patch-inserted-svg-paint.test.ts
根目录 / tests / unit / editor / patch-inserted-svg-paint.test.ts
1 import { describe, expect, it } from 'vitest'
2 import { patchGenericElementProperties } from '../../../src/main/element-editor/shared'
3 import {
4 buildIconElementHtml,
5 buildShapeElementHtml
6 } from '../../../src/renderer/src/components/session-detail/workspace/insert-shapes'
7
8 describe('patchGenericElementProperties inserted svg paint', () => {
9 it('writes background color edits to inserted shape fill and stroke', () => {
10 const html = `
11 <body data-page-id="page">
12 <main class="ppt-page-root" data-ppt-guard-root="1">
13 ${buildShapeElementHtml({
14 blockId: 'select-arcsin1-shape0001',
15 left: 10,
16 top: 20,
17 width: 100,
18 height: 80,
19 zIndex: 3,
20 type: 'rounded-rect'
21 })}
22 </main>
23 </body>
24 `
25
26 const next = patchGenericElementProperties(
27 html,
28 'body[data-page-id="page"] [data-block-id="select-arcsin1-shape0001"]',
29 { style: { backgroundColor: '#ff3366' } }
30 )
31
32 expect(next).toContain('fill="#ff3366"')
33 expect(next).toContain('stroke="#ff3366"')
34 expect(next).not.toContain('background-color: #ff3366')
35 })
36
37 it('writes background color edits to inserted icon currentColor host', () => {
38 const html = `
39 <body data-page-id="page">
40 <main class="ppt-page-root" data-ppt-guard-root="1">
41 ${buildIconElementHtml({
42 blockId: 'select-arcsin1-icon00001',
43 iconId: 'lightbulb',
44 left: 10,
45 top: 20,
46 width: 80,
47 height: 80,
48 zIndex: 3
49 })}
50 </main>
51 </body>
52 `
53
54 const next = patchGenericElementProperties(
55 html,
56 'body[data-page-id="page"] [data-block-id="select-arcsin1-icon00001"]',
57 { style: { backgroundColor: '#3366ff' } }
58 )
59
60 expect(next).toContain('color: #3366ff')
61 expect(next).not.toContain('background-color: #3366ff')
62 })
63 })
64
64 lines TYPESCRIPT