-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlDataExtractor.test.ts
More file actions
83 lines (69 loc) · 2.8 KB
/
Copy pathHtmlDataExtractor.test.ts
File metadata and controls
83 lines (69 loc) · 2.8 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
76
77
78
79
80
81
82
83
import { HtmlDataExtractor } from '@shared/visualServer/HtmlDataExtractor';
describe('HtmlDataExtractor', () => {
let target: HtmlDataExtractor;
beforeEach(() => {
target = new HtmlDataExtractor();
});
describe('extractArray', () => {
it('should extract a simple array', () => {
const html = 'let TEST_DATA = [1, 2, 3];';
const result = target.extractArray(html, 'TEST_DATA');
expect(result).toBe('[1, 2, 3]');
});
it('should extract nested arrays', () => {
const html = 'let TEST_DATA = [[1], [2, 3]];';
const result = target.extractArray(html, 'TEST_DATA');
expect(result).toBe('[[1], [2, 3]]');
});
it('should handle whitespace after equals sign', () => {
const html = 'let TEST_DATA = [true];';
const result = target.extractArray(html, 'TEST_DATA');
expect(result).toBe('[true]');
});
it('should return null if variable not found', () => {
const html = 'let OTHER_DATA = [];';
const result = target.extractArray(html, 'TEST_DATA');
expect(result).toBeNull();
});
it('should return null if does not start with bracket', () => {
const html = 'let TEST_DATA = "string";';
const result = target.extractArray(html, 'TEST_DATA');
expect(result).toBeNull();
});
it('should return null if brackets are unbalanced', () => {
const html = 'let TEST_DATA = [1, 2';
const result = target.extractArray(html, 'TEST_DATA');
expect(result).toBeNull();
});
it('should return null if brackets are unbalanced (extra closing)', () => {
const html = 'let TEST_DATA = [1, 2';
expect(target.extractArray(html, 'TEST_DATA')).toBeNull();
});
it('should handle array with objects', () => {
const html = 'let TEST_DATA = [{a: 1}, {b: [2]}];';
const result = target.extractArray(html, 'TEST_DATA');
expect(result).toBe('[{a: 1}, {b: [2]}]');
});
});
describe('extractGlobalDefinitions', () => {
it('should extract definition with let', () => {
const html = 'let GLOBAL_DEFINITIONS = { "key": "value" };';
const result = target.extractGlobalDefinitions(html);
expect(result).toBe('{ "key": "value" }');
});
it('should extract definition with const', () => {
const html = 'const GLOBAL_DEFINITIONS = { "key": "data" };';
const result = target.extractGlobalDefinitions(html);
expect(result).toBe('{ "key": "data" }');
});
it('should return null if not found', () => {
const html = 'let OTHER = {};';
const result = target.extractGlobalDefinitions(html);
expect(result).toBeNull();
});
it('should return null if regex match has no group', () => {
const html = 'let GLOBAL_DEFINITIONS = ;';
expect(target.extractGlobalDefinitions(html)).toBeNull();
});
});
});