-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateProcessor.test.ts
More file actions
62 lines (53 loc) · 2.56 KB
/
Copy pathTemplateProcessor.test.ts
File metadata and controls
62 lines (53 loc) · 2.56 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
import { TemplateProcessor } from '@shared/visualServer/TemplateProcessor';
describe('TemplateProcessor', () => {
let target: TemplateProcessor;
beforeEach(() => {
target = new TemplateProcessor();
});
describe('injectServiceData', () => {
it('should replace the placeholder with data', () => {
const html = 'let TEST_DATA = []; // {{ TEST_GRAPH_DATA }}';
const data = '[1, 2, 3]';
const result = target.injectServiceData(html, 'TEST', data);
expect(result).toBe('let TEST_DATA = [1, 2, 3]; // {{ TEST_GRAPH_DATA }}');
});
it("should not replace if placeholder doesn't match exactly", () => {
const html = 'let TEST_DATA = [1]; // {{ TEST_GRAPH_DATA }}';
const data = '[2]';
const result = target.injectServiceData(html, 'TEST', data);
expect(result).toBe(html);
});
it('should handle multiple occurrences if global flag is used (it is in implementation)', () => {
const html = 'let TEST_DATA = []; // {{ TEST_GRAPH_DATA }}\nlet TEST_DATA = []; // {{ TEST_GRAPH_DATA }}';
const data = '[1]';
const result = target.injectServiceData(html, 'TEST', data);
expect(result).toBe('let TEST_DATA = [1]; // {{ TEST_GRAPH_DATA }}\nlet TEST_DATA = [1]; // {{ TEST_GRAPH_DATA }}');
});
});
describe('injectGlobalDefinitions', () => {
it('should inject definitions into let placeholder', () => {
const html = 'let GLOBAL_DEFINITIONS = {}; // {{ GLOBAL_DEFINITIONS_DATA }}';
const data = '{a:1}';
const result = target.injectGlobalDefinitions(html, data);
expect(result).toBe('let GLOBAL_DEFINITIONS = {a:1}; // {{ GLOBAL_DEFINITIONS_DATA }}');
});
it('should inject definitions into const placeholder', () => {
const html = 'const GLOBAL_DEFINITIONS = {}; // {{ GLOBAL_DEFINITIONS_DATA }}';
const data = '{b:2}';
const result = target.injectGlobalDefinitions(html, data);
expect(result).toBe('let GLOBAL_DEFINITIONS = {b:2}; // {{ GLOBAL_DEFINITIONS_DATA }}');
});
it('should handle missing comment part if regex allows', () => {
const html = 'let GLOBAL_DEFINITIONS = {};';
const data = '{c:3}';
const result = target.injectGlobalDefinitions(html, data);
expect(result).toBe('let GLOBAL_DEFINITIONS = {c:3}; // {{ GLOBAL_DEFINITIONS_DATA }}');
});
it('should not replace if already populated', () => {
const html = 'let GLOBAL_DEFINITIONS = {existing:true};';
const data = '{new:true}';
const result = target.injectGlobalDefinitions(html, data);
expect(result).toBe(html);
});
});
});