forked from highcharts/highcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-utilities.js
132 lines (132 loc) · 3.86 KB
/
test-utilities.js
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
/*!*
*
* Copyright (c) Highsoft AS. All rights reserved.
*
*!*/
/**
* Useful functions for test purposes.
*/
var TestUtilities = /** @class */ (function () {
function TestUtilities() {
}
/* *
*
* Functions
*
* */
/**
* Calls a function only, if the system is set to specific timezones.
*
* @param timezones
* Possible values are CET, CEST, etc.
*
* @param fn
* The function to call. First argument is the matching timezone string.
*/
TestUtilities.ifTimezone = function (timezones, fn) {
var timezoneString;
for (var i = 0, ie = timezones.length; i < ie; ++i) {
if (TestUtilities.timeString.indexOf(timezones[i]) >= 0) {
timezoneString = timezones[i];
break;
}
}
if (timezoneString) {
return fn(timezoneString);
}
};
/**
* Convenient wrapper for installing lolex and bypassing
* requestAnimationFrame. Returns a clock object.
*
* @param lolexConfig
* Config supplied to lolex.install
*/
TestUtilities.lolexInstall = function (lolexConfig) {
if (!lolex) {
return;
}
var win = window;
win.backupRequestAnimationFrame = win.requestAnimationFrame;
win.requestAnimationFrame = null;
// Abort running animations, otherwise they will take over
Highcharts.timers.length = 0;
return lolex.install(lolexConfig);
};
/**
* Convenient wrapper for uninstalling lolex.
*
* @param clock
* The clock object
*/
TestUtilities.lolexUninstall = function (clock) {
if (!clock || !lolex) {
return;
}
var win = window;
clock.uninstall();
// Reset native requestAnimationFrame
win.requestAnimationFrame = win.backupRequestAnimationFrame;
delete win.backupRequestAnimationFrame;
};
/**
* Convenience wrapper for running timeouts and uninstalling lolex.
*
* @param clock
* The clock object
*/
TestUtilities.lolexRunAndUninstall = function (clock) {
if (!clock || !lolex) {
return;
}
clock.runAll();
TestUtilities.lolexUninstall(clock);
};
/* *
*
* Constants
*
* */
TestUtilities.timeString = new Date().toTimeString();
/**
* A string representation for the current browser. Possible values are
* `Chrome`, `Edge`, `Firefox`, `MSIE`, `Netscape`, `Opera`, `PhantomJS`,
* `Safari`, and an empty string for unknown browsers.
*/
TestUtilities.browser = (function () {
var userAgent = window.navigator.userAgent;
if ((new RegExp('MSIE|Trident', 'i')).test(userAgent) &&
!(new RegExp('Opera', 'i')).test(userAgent)) {
return 'MSIE';
}
if ((new RegExp('Firefox', 'i')).test(userAgent)) {
return 'Firefox';
}
if ((new RegExp('Edge', 'i')).test(userAgent)) {
return 'Edge';
}
if ((new RegExp('Chrome', 'i')).test(userAgent)) {
return 'Chrome';
}
if ((new RegExp('PhantomJS', 'i')).test(userAgent)) {
return 'PhantomJS';
}
if ((new RegExp('Safari', 'i')).test(userAgent)) {
return 'Safari';
}
if ((new RegExp('Opera', 'i')).test(userAgent)) {
return 'Opera';
}
if ((new RegExp('Netscape', 'i')).test(userAgent)) {
return 'Netscape';
}
return '';
}());
/**
* Indiciates, if system time runs in CET timezone.
*/
TestUtilities.isCET = (TestUtilities.timeString.indexOf('CET') !== -1 ||
TestUtilities.timeString.indexOf('CEST') !== -1 ||
TestUtilities.timeString.indexOf('W. Europe Standard Time') !== -1);
return TestUtilities;
}());