-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathinline-run-patch.test.ts
More file actions
75 lines (61 loc) · 2.66 KB
/
inline-run-patch.test.ts
File metadata and controls
75 lines (61 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { describe, expect, it } from 'bun:test';
import { INLINE_PROPERTY_BY_KEY, validateInlineRunPatch } from './inline-run-patch.js';
import { DocumentApiValidationError } from '../errors.js';
describe('INLINE_PROPERTY_REGISTRY: caps entry', () => {
const entry = INLINE_PROPERTY_BY_KEY['caps'];
it('exists in the registry', () => {
expect(entry).toBeDefined();
});
it('uses mark storage (not runAttribute)', () => {
expect(entry.storage).toBe('mark');
});
it('targets the textStyle mark with textTransform attribute', () => {
expect(entry.carrier).toEqual({
storage: 'mark',
markName: 'textStyle',
textStyleAttr: 'textTransform',
});
});
it('accepts boolean input type', () => {
expect(entry.type).toBe('boolean');
});
it('maps to the w:caps OOXML element', () => {
expect(entry.ooxmlElement).toBe('w:caps');
});
});
describe('validateInlineRunPatch: rejects Object.prototype keys', () => {
it('rejects toString as an unknown inline property', () => {
expect(() => validateInlineRunPatch({ toString: true })).toThrow(DocumentApiValidationError);
expect(() => validateInlineRunPatch({ toString: true })).toThrow('Unknown inline property: "toString"');
});
it('rejects constructor as an unknown inline property', () => {
expect(() => validateInlineRunPatch({ constructor: true })).toThrow(DocumentApiValidationError);
expect(() => validateInlineRunPatch({ constructor: true })).toThrow('Unknown inline property: "constructor"');
});
it('rejects hasOwnProperty as an unknown inline property', () => {
expect(() => validateInlineRunPatch({ hasOwnProperty: true })).toThrow(DocumentApiValidationError);
});
it('rejects __proto__ as an unknown inline property', () => {
// JSON.parse produces __proto__ as an own property (not the setter)
const patch = JSON.parse('{"__proto__": true}');
expect(() => validateInlineRunPatch(patch)).toThrow(DocumentApiValidationError);
});
it('still accepts valid inline properties', () => {
expect(() => validateInlineRunPatch({ bold: true })).not.toThrow();
expect(() => validateInlineRunPatch({ italic: null })).not.toThrow();
expect(() => validateInlineRunPatch({ fontSize: 12 })).not.toThrow();
});
});
describe('INLINE_PROPERTY_REGISTRY: smallCaps entry', () => {
const entry = INLINE_PROPERTY_BY_KEY['smallCaps'];
it('uses runAttribute storage (distinct from caps)', () => {
expect(entry.storage).toBe('runAttribute');
});
it('targets the run node with smallCaps property key', () => {
expect(entry.carrier).toEqual({
storage: 'runAttribute',
nodeName: 'run',
runPropertyKey: 'smallCaps',
});
});
});