返回 oh-my-ppt
presentation-element-context.test.ts
根目录 / tests / unit / preview / presentation-element-context.test.ts
1 import { describe, expect, it } from 'vitest'
2 import type { PresentationElementSnapshot } from '@arcsin1/presentation-editor-runtime'
3 import { buildSelectedElementRuntimeContext } from '../../../src/renderer/src/lib/presentation-element-context'
4
5 describe('buildSelectedElementRuntimeContext', () => {
6 it('keeps useful editable state while excluding editor and executable attributes', () => {
7 const context = buildSelectedElementRuntimeContext({
8 classList: ['metric-card', 'arcsin1-presentation-editor-selected', 'ppt-inspector-highlight'],
9 attributes: {
10 id: 'revenue',
11 'data-block-id': 'revenue-card',
12 'aria-label': 'Revenue',
13 onclick: 'alert(1)',
14 style: 'color:red',
15 'data-arcsin1-presentation-editor-selected': 'true'
16 },
17 inlineStyle: {
18 color: { value: 'rgb(10, 20, 30)', priority: '' },
19 'border-radius': { value: '12px', priority: 'important' }
20 },
21 computedStyle: {
22 display: 'flex',
23 'font-size': '28px',
24 cursor: 'pointer'
25 },
26 bounds: { x: 14.321, y: 28.765, width: 320.999, height: 96.555 }
27 } as PresentationElementSnapshot)
28
29 expect(context.classList).toEqual(['metric-card'])
30 expect(context.attributes).toEqual({
31 id: 'revenue',
32 'data-block-id': 'revenue-card',
33 'aria-label': 'Revenue'
34 })
35 expect(context.inlineStyle).toEqual({
36 color: { value: 'rgb(10, 20, 30)', priority: '' },
37 'border-radius': { value: '12px', priority: 'important' }
38 })
39 expect(context.computedStyle).toEqual({ display: 'flex', 'font-size': '28px' })
40 expect(context.bounds).toEqual({ x: 14.32, y: 28.77, width: 321, height: 96.56 })
41 })
42
43 it('matches the main-process contract for empty fields and bounded geometry', () => {
44 expect(
45 buildSelectedElementRuntimeContext({
46 classList: ['ppt-inspector-highlight'],
47 attributes: { onclick: 'ignore' },
48 inlineStyle: {},
49 computedStyle: { cursor: 'pointer' },
50 bounds: { x: -999_999, y: 999_999, width: -20, height: 999_999 }
51 } as PresentationElementSnapshot)
52 ).toEqual({
53 bounds: { x: -100_000, y: 100_000, width: 0, height: 100_000 }
54 })
55 })
56 })
57
57 lines TYPESCRIPT