-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathuser-interaction.spec.ts
259 lines (259 loc) · 11.7 KB
/
user-interaction.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
* Sparkline Column WinLoss Series Spec
*/
import { Sparkline, ISparklineLoadedEventArgs, SparklineTooltip } from '../../src/sparkline/index';
import { removeElement, getIdElement, Rect } from '../../src/sparkline/utils/helper';
import { createElement, isNullOrUndefined } from '@syncfusion/ej2-base';
import {profile , inMB, getMemoryProfile} from '../common.spec';
import { MouseEvents } from './events.spec';
Sparkline.Inject(SparklineTooltip);
describe('Sparkline tooltip and tracker checking 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 tracker Spec', () => {
let trigger: MouseEvents = new MouseEvents();
let element: Element;
let sparkline: Sparkline;
let id: string = 'sparks';
let ele: Element;
let rect: Rect;
let d: string[];
beforeAll(() => {
element = createElement('div', { id: id });
document.body.appendChild(element);
sparkline = new Sparkline({
width: '400', height: '100',
type: 'Column',
fill: '#5af02c',
dataSource: [
{ id: 10, value: 50 },
{ id: 20, value: 30 },
{ id: 30, value: -40 },
{ id: 40, value: 10 },
{ id: 50, value: -60 },
{ id: 60, value: 20 },
{ id: 70, value: 70 },
{ id: 80, value: -55 },
{ id: 90, value: 80 },
{ id: 100, value: 45 }
], yName: 'value', xName: 'id',
tooltipSettings: {
trackLineSettings: {
visible: true,
color: 'red', width: 2
}
}
});
});
afterAll(() => {
sparkline.destroy();
removeElement(id);
});
it('Sparkline tracker line checking', () => {
sparkline.loaded = (args: ISparklineLoadedEventArgs) => {
args.sparkline.loaded = () => { /* null function */ };
ele = getIdElement(id + '_sparkline_column_1');
trigger.mousemoveEvent(ele, 0, 0, 30, 30);
ele = getIdElement(id + '_sparkline_tracker');
let path: string[] = ele.getAttribute('d').split(' ');
expect(path[1]).toBe('24.5');
expect(path[2]).toBe('5');
expect(path[4]).toBe('24.5');
expect(path[5]).toBe('95');
expect(ele.getAttribute('fill')).toBe('#000000');
expect(ele.getAttribute('stroke')).toBe('#000000');
expect(ele.getAttribute('stroke-width')).toBe('2');
};
sparkline.appendTo('#' + id);
});
it('Sparkline tracker line move to other point checking', () => {
ele = getIdElement(id);
trigger.mousemoveEvent(ele, 0, 0, 80, 30);
ele = getIdElement(id + '_sparkline_tracker');
let path: string[] = ele.getAttribute('d').split(' ');
expect(path[1]).toBe('63.5');
expect(path[2]).toBe('5');
expect(path[4]).toBe('63.5');
expect(path[5]).toBe('95');
expect(ele.getAttribute('fill')).toBe('#000000');
expect(ele.getAttribute('stroke')).toBe('#000000');
expect(ele.getAttribute('stroke-width')).toBe('2');
});
it('Sparkline tracker line move to other point checking', () => {
ele = getIdElement(id);
trigger.mousemoveEvent(ele, 0, 0, 200, 30);
ele = getIdElement(id + '_sparkline_tracker');
let path: string[] = ele.getAttribute('d').split(' ');
expect(path[1]).toBe('180.5');
expect(path[2]).toBe('5');
expect(path[4]).toBe('180.5');
expect(path[5]).toBe('95');
expect(ele.getAttribute('fill')).toBe('#000000');
expect(ele.getAttribute('stroke')).toBe('#000000');
expect(ele.getAttribute('stroke-width')).toBe('2');
});
it('Sparkline tracker line move out of container checking', () => {
ele = getIdElement(id);
trigger.mouseLeaveEvent(ele);
ele = getIdElement(id + '_sparkline_tracker');
expect(isNullOrUndefined(ele)).toBe(true);
});
it('Sparkline tracker line visible false checking', () => {
sparkline.tooltipSettings.trackLineSettings.visible = false;
sparkline.dataBind();
ele = getIdElement(id);
trigger.mousemoveEvent(ele, 0, 0, 200, 30);
ele = getIdElement(id + '_sparkline_tracker');
expect(isNullOrUndefined(ele)).toBe(true);
ele = getIdElement(id);
trigger.mouseLeaveEvent(ele);
sparkline.sparklineTooltipModule['removeTracker']();
});
});
describe('Sparkline tooltip Spec', () => {
let trigger: MouseEvents = new MouseEvents();
let element: Element;
let sparkline: Sparkline;
let id: string = 'sparks';
let ele: Element;
let rect: Rect;
let d: string[];
beforeAll(() => {
element = createElement('div', { id: id });
document.body.appendChild(element);
sparkline = new Sparkline({
width: '600', height: '300',
type: 'Column',
fill: '#5af02c',
markerSettings: {
visible: ['All']
},
dataSource: [
{ id: 10, value: 50 },
{ id: 20, value: 30 },
{ id: 30, value: -40 },
{ id: 40, value: 10 },
{ id: 50, value: -60 },
{ id: 60, value: 20 },
{ id: 70, value: 70 },
{ id: 80, value: -55 },
{ id: 90, value: 80 },
{ id: 100, value: 45 }
], yName: 'value', xName: 'id',
tooltipSettings: {
visible: true,
trackLineSettings: {
visible: true,
},
textStyle : {
color: 'white'
},
fill: 'transparent'
}
});
});
afterAll(() => {
sparkline.destroy();
removeElement(id);
});
it('Sparkline tracker line checking', () => {
sparkline.loaded = (args: ISparklineLoadedEventArgs) => {
args.sparkline.loaded = () => { /* null function */ };
ele = getIdElement(id + '_sparkline_column_1');
trigger.mousemoveEvent(ele, 0, 0, 30, 30);
ele = getIdElement(id + '_sparkline_tooltip_div_text');
expect(ele.firstChild.textContent).toBe('50');
expect(ele.lastChild.textContent).toBe('50');
ele = getIdElement(id + '_sparkline_tracker');
expect(ele.getAttribute('fill')).toBe('#000000');
expect(ele.getAttribute('stroke')).toBe('#000000');
expect(ele.getAttribute('stroke-width')).toBe('1');
};
sparkline.appendTo('#' + id);
});
it('Sparkline tooltip moving same point checking', () => {
sparkline.markerSettings.visible = [];
sparkline.dataBind();
ele = getIdElement(id + '_sparkline_column_1');
trigger.mousemoveEvent(ele, 0, 0, 30, 20);
ele = getIdElement(id + '_sparkline_tooltip_div_text');
expect(ele.firstChild.textContent).toBe('50');
expect(ele.lastChild.textContent).toBe('50');
});
it('Sparkline tooltip moving other point checking', () => {
ele = getIdElement(id + '_sparkline_column_6');
trigger.mousemoveEvent(ele, 0, 0, 400, 50);
ele = getIdElement(id + '_sparkline_tooltip_div_text');
expect(ele.firstChild.textContent).toBe('70');
expect(ele.lastChild.textContent).toBe('70');
});
it('Sparkline tooltip moving negative point checking', () => {
ele = getIdElement(id + '_sparkline_column_7');
trigger.mousemoveEvent(ele, 0, 0, 470, 150);
ele = getIdElement(id + '_sparkline_tooltip_div_text');
expect(ele.firstChild.textContent).toBe('-55');
expect(ele.lastChild.textContent).toBe('-55');
ele = getIdElement(id);
trigger.mouseLeaveEvent(ele);
ele = getIdElement(id + '_sparkline_tooltip_div_text');
expect(isNullOrUndefined(ele)).toBe(true);
});
it('Sparkline tooltip moving for pie series checking', () => {
sparkline.type = 'Pie';
sparkline.format = 'c0';
sparkline.useGroupingSeparator = false;
sparkline.dataBind();
ele = getIdElement(id + '_sparkline_pie_4');
trigger.mousemoveEvent(ele, 0, 0, 400, 150);
ele = getIdElement(id + '_sparkline_tooltip_div_text');
expect(ele.firstChild.textContent).toBe('-$60');
expect(ele.lastChild.textContent).toBe('-$60');
ele = getIdElement(id + '_sparkline_pie_4');
trigger.mouseupEvent(ele, 400, 150, 400, 150);
});
it('Sparkline tooltip moving for not valid pie point checking', () => {
ele = getIdElement(id);
trigger.mousemoveEvent(ele, 0, 0, 400, 150);
ele = getIdElement(id + '_sparkline_tooltip_div_text');
expect(isNullOrUndefined(ele)).toBe(true);
});
it('Sparkline tooltip format checking', () => {
sparkline.tooltipSettings.format = '${id} : ${value}$';
sparkline.format = null;
sparkline.dataBind();
ele = getIdElement(id + '_sparkline_pie_4');
trigger.mousemoveEvent(ele, 0, 0, 400, 150);
ele = getIdElement(id + '_sparkline_tooltip_div_text');
expect(ele.firstChild.textContent).toBe('50 ');
expect(ele.lastChild.textContent).toBe(' -60$');
});
it('Sparkline tooltip template checking', () => {
sparkline.tooltipSettings.template = '<div style="border: 2px solid green;background: #a0e99680">${id}<br>${value}$</div>';
sparkline.dataBind();
ele = getIdElement(id + '_sparkline_pie_4');
sparkline.isTouch = true;
sparkline.mouseX = 400;
sparkline.mouseY = 150;
sparkline.sparklineTooltipModule['mouseUpHandler']({ target: ele} as any);
ele = getIdElement(id + '_sparkline_tooltip_divparent_template');
expect(ele.textContent).toBe('50-60$');
ele = getIdElement(id + '_sparkline_tooltip_div');
expect(ele.children[0].innerHTML.indexOf('<div style="border: 2px solid green;background: #a0e99680">50<br>-60$</div>') > -1).toBe(true);
});
});
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);
});
});