-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathline.spec.ts
237 lines (236 loc) · 11.4 KB
/
line.spec.ts
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import { Sparkline, SparklineTooltip } from '../../src/sparkline/index';
import { createElement } from '@syncfusion/ej2-base';
import { removeElement, getIdElement } from '../../src/sparkline/utils/helper';
import { ISparklineLoadedEventArgs } from '../../src/sparkline/model/interface';
import {profile , inMB, getMemoryProfile} from '../common.spec';
Sparkline.Inject(SparklineTooltip);
/**
* Sparkline Test case file
*/
describe('Sparkline Component Line Series Spec', () => {
beforeAll(() => {
const isDef = (o: any) => o !== undefined && o !== null;
if (!isDef(window.performance)) {
console.log("Unsupported environment, window.performance.memory is unavailable");
this.skip(); //Skips test (in Chai)
return;
}
});
describe('Sparkline testing Line series spec', () => {
let element: Element;
let sparkline: Sparkline;
let id: string = 'spark-container';
let ele: Element;
let d: string[];
beforeAll(() => {
element = createElement('div', { id: id });
(element as HTMLDivElement).style.width = '400px';
(element as HTMLDivElement).style.height = '100px';
document.body.appendChild(element);
sparkline = new Sparkline({
height: '40%',
width: '20%',
dataSource: [-10, 5, -15, 10, 5, 15, -20, 25]
});
});
afterAll(() => {
sparkline.destroy();
removeElement(id);
});
it('Sparkline line series checking with array of data', () => {
sparkline.loaded = () => {
ele = getIdElement(id + '_sparkline_line');
expect(ele.getAttribute('opacity')).toBe('1');
expect(ele.getAttribute('stroke')).toBe('#00bdae');
expect(ele.getAttribute('stroke-width')).toBe('1');
expect(ele.getAttribute('fill')).toBe('transparent');
d = ele.getAttribute('d').split(' ');
expect(d.length).toBe(28);
d = ele.getAttribute('d').split('M');
expect(d.length).toBe(2);
d = ele.getAttribute('d').split('L');
expect(d.length).toBe(9);
};
sparkline.appendTo('#' + id);
});
it('Sparkline line series checking with object array of data', () => {
sparkline.loaded = () => {
ele = getIdElement(id + '_sparkline_line');
expect(ele.getAttribute('opacity')).toBe('1');
expect(ele.getAttribute('stroke')).toBe('#00bdae');
expect(ele.getAttribute('stroke-width')).toBe('1');
expect(ele.getAttribute('fill')).toBe('transparent');
d = ele.getAttribute('d').split(' ');
expect(d.length).toBe(22);
d = ele.getAttribute('d').split('M');
expect(d.length).toBe(2);
d = ele.getAttribute('d').split('L');
expect(d.length).toBe(7);
};
sparkline.dataSource = [
{ x: 0, yval: 2900 },
{ x: 1, yval: 3900 },
{ x: 2, yval: 3500 },
{ x: 3, yval: 3800 },
{ x: 4, yval: 2500 },
{ x: 5, yval: 3200 }
];
sparkline.xName = 'x';
sparkline.yName = 'yval';
sparkline.refresh();
});
it('Sparkline range band checking spec', () => {
sparkline.loaded = () => {
ele = getIdElement(id + '_rangeBand_1');
expect(ele.getAttribute('opacity')).toBe('0.5');
expect(ele.getAttribute('stroke')).toBe('transparent');
expect(ele.getAttribute('stroke-width')).toBe('1');
expect(ele.getAttribute('fill')).toBe('blue');
d = ele.getAttribute('d').split(' ');
expect(d.length).toBe(14);
d = ele.getAttribute('d').split('M');
expect(d.length).toBe(2);
d = ele.getAttribute('d').split('L');
expect(d.length).toBe(4);
};
sparkline.rangeBandSettings = [
{ startRange: 1500, endRange: 6000, color: 'gray', opacity: 1 },
{ startRange: 500, endRange: 1500, color: 'blue', opacity: 0.5 },
{ startRange: 1500, endRange: 3500, color: 'red', opacity: 1 },
{ startRange: 4000, endRange: 6000, color: 'blue', opacity: 2 },
];
sparkline.refresh();
});
it('Sparkline line series checking with axis settings', () => {
sparkline.loaded = () => {
ele = getIdElement(id + '_Sparkline_XAxis');
expect(ele.getAttribute('x1')).toBe('5');
expect(ele.getAttribute('y1')).toBe('35');
expect(ele.getAttribute('x2')).toBe('75');
expect(ele.getAttribute('y2')).toBe('35');
expect(ele.getAttribute('stroke')).toBe('#000000');
expect(ele.getAttribute('stroke-width')).toBe('1');
};
sparkline.axisSettings = {
minX: 1, maxX: 4, minY: 2800, maxY: 3800,
lineSettings: { visible: true}
};
sparkline.refresh();
});
it('Sparkline axis custom value and line customization', () => {
sparkline.loaded = () => {
ele = getIdElement(id + '_Sparkline_XAxis');
expect(ele.getAttribute('x1')).toBe('5');
expect(ele.getAttribute('y1')).toBe('20');
expect(ele.getAttribute('x2')).toBe('75');
expect(ele.getAttribute('y2')).toBe('20');
expect(ele.getAttribute('stroke')).toBe('#9900cc');
expect(ele.getAttribute('stroke-width')).toBe('3');
};
sparkline.axisSettings = {
value: 3300,
lineSettings: { visible: true, color: '#9900cc', width: 3}
};
sparkline.theme = 'MaterialDark';
sparkline.refresh();
});
it('Sparkline line with negative values', () => {
sparkline.loaded = (args: ISparklineLoadedEventArgs) => {
ele = getIdElement(id + '_sparkline_line');
d = ele.getAttribute('d').split(' ');
expect(d.length).toBe(31);
d = ele.getAttribute('d').split('M');
expect(d.length).toBe(2);
d = ele.getAttribute('d').split('L');
expect(d.length).toBe(10);
};
sparkline.theme = 'BootstrapDark';
sparkline.axisSettings = {minY: -9, maxY: -1, value: -5, minX: 0, maxX: 8};
sparkline.dataSource = [-3, -8, -5, -1, -7, -4, -9, -2, -6];
sparkline.refresh();
});
it('Sparkline line with category axis', () => {
sparkline.loaded = (args: ISparklineLoadedEventArgs) => {
ele = getIdElement(id + '_sparkline_line');
d = ele.getAttribute('d').split(' ');
expect(d.length).toBe(28);
d = ele.getAttribute('d').split('M');
expect(d.length).toBe(2);
d = ele.getAttribute('d').split('L');
expect(d.length).toBe(9);
};
sparkline.axisSettings = {minY: 3000, maxY: 5500, value: -5, minX: 0, maxX: 8};
sparkline.dataSource = [
{xDate: new Date(2017, 1, 1), x: 0, xval: 'Jan', yval: 2900 },
{xDate: new Date(2017, 1, 2), x: 1, xval: 'Feb', yval: 3900 },
{xDate: new Date(2017, 1, 3), x: 2, xval: 'Mar', yval: 3500 },
{xDate: new Date(2017, 1, 4), x: 3, xval: 'Apr', yval: 3800 },
{xDate: new Date(2017, 1, 5), x: 4, xval: 'May', yval: 2500 },
{xDate: new Date(2017, 1, 6), x: 5, xval: 'Jun', yval: 3200 },
{xDate: new Date(2017, 1, 7), x: 6, xval: 'Jul', yval: 1800 },
{xDate: new Date(2017, 1, 8), x: 7, xval: 'Aug', yval: 5000 },
];
sparkline.refresh();
});
it('Sparkline line with datetime axis', () => {
sparkline.loaded = (args: ISparklineLoadedEventArgs) => {
ele = getIdElement(id + '_sparkline_line');
d = ele.getAttribute('d').split(' ');
expect(d.length).toBe(28);
d = ele.getAttribute('d').split('M');
expect(d.length).toBe(2);
d = ele.getAttribute('d').split('L');
expect(d.length).toBe(9);
};
sparkline.axisSettings = { minX: new Date(2017, 1, 1).getTime(), maxX: new Date(2017, 1, 8).getTime()};
sparkline.dataSource = [
{xDate: new Date(2017, 1, 1), x: 0, xval: 'Jan', yval: 2900 },
{xDate: new Date(2017, 1, 2), x: 1, xval: 'Feb', yval: 3900 },
{xDate: new Date(2017, 1, 3), x: 2, xval: 'Mar', yval: 3500 },
{xDate: new Date(2017, 1, 4), x: 3, xval: 'Apr', yval: 3800 },
{xDate: new Date(2017, 1, 5), x: 4, xval: 'May', yval: 2500 },
{xDate: new Date(2017, 1, 6), x: 5, xval: 'Jun', yval: 3200 },
{xDate: new Date(2017, 1, 7), x: 6, xval: 'Jul', yval: 1800 },
{xDate: new Date(2017, 1, 8), x: 7, xval: 'Aug', yval: 5000 },
];
sparkline.xName = 'xDate';
sparkline.theme = 'HighContrast';
sparkline.refresh();
});
it('Sparkline line with datetime axis', () => {
sparkline.loaded = (args: ISparklineLoadedEventArgs) => {
ele = getIdElement(id + '_sparkline_line');
d = ele.getAttribute('d').split(' ');
expect(d.length).toBe(28);
d = ele.getAttribute('d').split('M');
expect(d.length).toBe(2);
d = ele.getAttribute('d').split('L');
expect(d.length).toBe(9);
};
sparkline.axisSettings = { minX: new Date(2017, 1, 1).getTime(), maxX: new Date(2017, 1, 8).getTime()};
sparkline.dataSource = [
{xDate: new Date(2017, 1, 1), x: 0, xval: 'Jan', yval: 2900 },
{xDate: new Date(2017, 1, 2), x: 1, xval: 'Feb', yval: 3900 },
{xDate: new Date(2017, 1, 3), x: 2, xval: 'Mar', yval: 3500 },
{xDate: new Date(2017, 1, 4), x: 3, xval: 'Apr', yval: 3800 },
{xDate: new Date(2017, 1, 5), x: 4, xval: 'May', yval: 2500 },
{xDate: new Date(2017, 1, 6), x: 5, xval: 'Jun', yval: 3200 },
{xDate: new Date(2017, 1, 7), x: 6, xval: 'Jul', yval: 1800 },
{xDate: new Date(2017, 1, 8), x: 7, xval: 'Aug', yval: 5000 },
];
sparkline.xName = 'xDate';
sparkline.theme = 'HighContrast';
sparkline.enableRtl = true;
sparkline.refresh();
});
});
it('memory leak', () => {
profile.sample();
let average: any = inMB(profile.averageChange)
//Check average change in memory samples to not be over 10MB
expect(average).toBeLessThan(10);
let memory: any = inMB(getMemoryProfile())
//Check the final memory usage against the first usage, there should be little change if everything was properly deallocated
expect(memory).toBeLessThan(profile.samples[0] + 0.25);
});
});