1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const chai_1 = require("chai");
|
19 | const tree_decorator_1 = require("./tree-decorator");
|
20 | class MockTreeDecoratorService extends tree_decorator_1.AbstractTreeDecoratorService {
|
21 | constructor() {
|
22 | super([]);
|
23 | }
|
24 | }
|
25 | describe('tree-decorator', () => {
|
26 | describe('tree-decorator-service', () => {
|
27 | const decoratorService = new MockTreeDecoratorService();
|
28 | it('should inflate an empty object into an empty map', () => {
|
29 | (0, chai_1.expect)(decoratorService.inflateDecorators({})).to.be.empty;
|
30 | });
|
31 | it('should inflate an object into the corresponding map', () => {
|
32 | const expected = new Map();
|
33 | expected.set('id_1', [
|
34 | {
|
35 | tooltip: 'tooltip'
|
36 | },
|
37 | {
|
38 | fontData: {
|
39 | color: 'blue'
|
40 | }
|
41 | }
|
42 | ]);
|
43 | expected.set('id_2', [
|
44 | {
|
45 | backgroundColor: 'yellow'
|
46 | },
|
47 | {
|
48 | priority: 100
|
49 | }
|
50 | ]);
|
51 | (0, chai_1.expect)(decoratorService.inflateDecorators({
|
52 | 'id_1': [
|
53 | {
|
54 | 'tooltip': 'tooltip'
|
55 | },
|
56 | {
|
57 | 'fontData': {
|
58 | 'color': 'blue'
|
59 | }
|
60 | }
|
61 | ],
|
62 | 'id_2': [
|
63 | {
|
64 | 'backgroundColor': 'yellow'
|
65 | },
|
66 | {
|
67 | 'priority': 100
|
68 | }
|
69 | ]
|
70 | })).to.be.deep.equal(expected);
|
71 | });
|
72 | it('should deflate an empty map into an empty object', () => {
|
73 | (0, chai_1.expect)(decoratorService.inflateDecorators({})).to.be.empty;
|
74 | });
|
75 | it('should inflate an object into the corresponding map', () => {
|
76 | const decorations = new Map();
|
77 | decorations.set('id_1', [
|
78 | {
|
79 | tooltip: 'tooltip'
|
80 | },
|
81 | {
|
82 | fontData: {
|
83 | color: 'blue'
|
84 | }
|
85 | }
|
86 | ]);
|
87 | decorations.set('id_2', [
|
88 | {
|
89 | backgroundColor: 'yellow'
|
90 | },
|
91 | {
|
92 | priority: 100
|
93 | }
|
94 | ]);
|
95 | (0, chai_1.expect)(decoratorService.deflateDecorators(decorations)).to.be.deep.equal({
|
96 | 'id_1': [
|
97 | {
|
98 | 'tooltip': 'tooltip'
|
99 | },
|
100 | {
|
101 | 'fontData': {
|
102 | 'color': 'blue'
|
103 | }
|
104 | }
|
105 | ],
|
106 | 'id_2': [
|
107 | {
|
108 | 'backgroundColor': 'yellow'
|
109 | },
|
110 | {
|
111 | 'priority': 100
|
112 | }
|
113 | ]
|
114 | });
|
115 | });
|
116 | });
|
117 | describe('caption-highlight', () => {
|
118 | describe('range-contains', () => {
|
119 | [
|
120 | [1, 2, 3, false],
|
121 | [0, 0, 1, true],
|
122 | [1, 0, 1, true],
|
123 | [1, 1, 1, true],
|
124 | [2, 1, 1, true],
|
125 | [3, 1, 1, false],
|
126 | [1, 1, -100, false],
|
127 | ].forEach(test => {
|
128 | const [input, offset, length, expected] = test;
|
129 | it(`${input} should ${expected ? '' : 'not '}be contained in the [${offset}:${length}] range`, () => {
|
130 | (0, chai_1.expect)(tree_decorator_1.TreeDecoration.CaptionHighlight.Range.contains(input, { offset, length })).to.be.equal(expected);
|
131 | });
|
132 | });
|
133 | });
|
134 | it('split', () => {
|
135 | const actual = tree_decorator_1.TreeDecoration.CaptionHighlight.split('alma', {
|
136 | ranges: [{ offset: 0, length: 1 }]
|
137 | });
|
138 | (0, chai_1.expect)(actual).has.lengthOf(2);
|
139 | (0, chai_1.expect)(actual[0].highlight).to.be.true;
|
140 | (0, chai_1.expect)(actual[0].data).to.be.equal('a');
|
141 | (0, chai_1.expect)(actual[1].highlight).to.be.undefined;
|
142 | (0, chai_1.expect)(actual[1].data).to.be.equal('lma');
|
143 | });
|
144 | });
|
145 | });
|
146 |
|
\ | No newline at end of file |