-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathexport.spec.ts
192 lines (189 loc) · 8.23 KB
/
export.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
/**
* Specifies the print spec.
*/
import { createElement, remove } from '@syncfusion/ej2-base';
import { LinearGauge, ILoadedEventArgs, Print, ImageExport, PdfExport } from '../../src/index';
import { IPrintEventArgs } from '../../src/linear-gauge/model/interface';
import { PdfPageOrientation } from '@syncfusion/ej2-pdf-export';
import { beforePrint } from '../../src/linear-gauge/model/constant';
import {profile , inMB, getMemoryProfile} from '../common.spec';
LinearGauge.Inject(Print, ImageExport, PdfExport);
export function getElementByID(id: string): Element {
return document.getElementById(id);
}
describe('Lineargauge axis testing', () => {
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('Lineargauge axis testing with print and export', () => {
let linearGaugeObj: LinearGauge;
let mapElement: Element;
let temp: Element;
mapElement = createElement('div', { id: 'container' });
temp = createElement('div', { id: 'tempElement' });
(<any>window).open = () => {
return {
document: { write: () => { }, close: () => { } },
close: () => { }, print: () => { }, focus: () => { }, moveTo: () => { }, resizeTo: () => { }
};
};
beforeAll(() => {
document.body.appendChild(mapElement);
document.body.appendChild(temp);
linearGaugeObj = new LinearGauge({
allowPrint: true,
allowImageExport: true,
allowPdfExport : true,
width: "400px",
height: "300px",
axes: [{ }],
loaded: (args: Object): void => {
linearGaugeObj.print();
}
});
linearGaugeObj.appendTo('#container');
});
afterAll((): void => {
remove(mapElement);
linearGaugeObj.destroy();
});
it('checking a print', (done: Function) => {
linearGaugeObj.beforePrint = (args: IPrintEventArgs): void => {
expect((args.htmlContent.outerHTML.indexOf('<div id="container" class="e-lib e-control e-lineargauge" style="user-select: none; position: relative; touch-action: none; cursor: auto;">')) > -1).toBe(true);
done();
};
linearGaugeObj.print();
});
it('Checking argument cancel', (done: Function) => {
linearGaugeObj.beforePrint = (args: IPrintEventArgs): void => {
args.cancel = true;
expect((args.htmlContent.outerHTML.indexOf('<div id="container" class="e-lib e-control e-lineargauge" style="user-select: none; position: relative; touch-action: none; cursor: auto;">')) > -1).toBe(true);
done();
};
linearGaugeObj.print();
linearGaugeObj.refresh();
});
it('Checking to print in multiple element', (done: Function) => {
linearGaugeObj.loaded = (args: Object): void => {
linearGaugeObj.print(['container', 'tempElement']);
};
linearGaugeObj.beforePrint = (args: IPrintEventArgs): void => {
expect(args.htmlContent.outerHTML.indexOf('tempElement') > -1).toBe(true);
done();
};
linearGaugeObj.refresh();
});
it('Checking to print direct element', (done: Function) => {
linearGaugeObj.loaded = (args: Object): void => {
linearGaugeObj.print(document.getElementById('container'));
};
linearGaugeObj.beforePrint = (args: IPrintEventArgs): void => {
expect((args.htmlContent.outerHTML.indexOf('<div id="container" class="e-lib e-control e-lineargauge" style="user-select: none; position: relative; touch-action: none; cursor: auto;">')) > -1).toBe(true);
done();
};
linearGaugeObj.refresh();
});
it('Checking to print single element', (done: Function) => {
linearGaugeObj.loaded = (args: Object): void => {
linearGaugeObj.print('tempElement');
};
linearGaugeObj.beforePrint = (args: IPrintEventArgs): void => {
expect(args.htmlContent.outerHTML.indexOf('<div id="tempElement"') > -1).toBe(true);
done();
};
linearGaugeObj.refresh();
});
it('Checking Image export- JPEG', (done: Function) => {
linearGaugeObj.export('JPEG', 'map');
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking Image export - SVG', (done: Function) => {
linearGaugeObj.export('SVG', 'map');
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking Image export - PNG', (done: Function) => {
linearGaugeObj.export('PNG', 'map');
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking PDG export - PDF', (done: Function) => {
linearGaugeObj.export('PDF', 'map');
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking If PDF orientation is null - PDF', (done: Function) => {
linearGaugeObj.export('PDF', 'map');
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking export - PDF - Potrait', (done: Function) => {
linearGaugeObj.export('PDF', 'map', PdfPageOrientation.Portrait);
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking base64 string for SVG', (done: Function) => {
linearGaugeObj.export('SVG', 'map',PdfPageOrientation.Portrait, false);
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking base64 string for PNG', (done: Function) => {
linearGaugeObj.export('PNG', 'map',PdfPageOrientation.Portrait, false);
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking base64 string for JPEG', (done: Function) => {
linearGaugeObj.export('JPEG', 'map',PdfPageOrientation.Portrait, false);
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking base64 string for PDF', (done: Function) => {
linearGaugeObj.export('PDF', 'map',PdfPageOrientation.Portrait, false);
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
it('Checking PDF export in SVG format', (done: Function) => {
linearGaugeObj.allowImageExport = false;
linearGaugeObj.export('SVG', 'map',PdfPageOrientation.Portrait, false);
setTimeout(() => {
expect('').toBe('');
done();
}, 500);
});
});
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);
});
});