-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtest.js
306 lines (265 loc) · 15.1 KB
/
test.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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* eslint sourceType: module */
const test = require('ava');
const devices = require('./index');
test('deviceTypes()', t => {
t.is(typeof devices.deviceTypes, 'function');
t.truthy(Array.isArray(devices.deviceTypes()));
t.is(devices.deviceTypes().length, 10);
});
test('devices()', t => {
t.is(typeof devices.devices, 'function');
t.truthy(Array.isArray(devices.devices()));
});
test('devices() device', t => {
let d1 = devices.deviceByModel('MD523')[0]; // 100th MD523
let d2 = devices.deviceByModel('MF135')[0]; // 500th MF135
t.is(typeof d1.Type, 'string');
t.is(typeof d1.Generation, 'string');
t.is(typeof d1.ANumber, 'string');
t.is(typeof d1.Bootrom, 'string');
t.is(typeof d1.FCCID, 'string');
t.is(typeof d1.InternalName, 'string');
t.is(typeof d1.Identifier, 'string');
t.is(typeof d1.Color, 'string');
t.is(typeof d1.Storage, 'string');
t.is(typeof d1.Model, 'string');
t.is(typeof d2.Type, 'string');
t.is(typeof d2.Generation, 'string');
t.is(Array.isArray(d2.ANumber), true);
t.is(Array.isArray(d2.Bootrom), true);
t.is(Array.isArray(d2.FCCID) || typeof d2.FCCID === 'string', true);
t.is(typeof d2.InternalName, 'string');
t.is(typeof d2.Identifier, 'string');
t.is(typeof d2.Color, 'string');
t.is(typeof d2.Storage, 'string');
t.is(typeof d2.Model, 'string');
});
test('generations()', t => {
t.is(typeof devices.generations, 'function');
t.truthy(Array.isArray(devices.generations()));
t.is(devices.generations().length, 99);
t.is(devices.generations('iphone').length, 38);
t.throws(function() { devices.generations('invalidType'); });
});
test('anumbers()', t => {
t.is(typeof devices.anumbers, 'function');
t.truthy(Array.isArray(devices.anumbers()));
t.is(devices.anumbers().length, 293);
t.is(devices.anumbers('iphone').length, 126);
t.throws(function() { devices.anumbers('invalidType'); });
});
test('fccids()', t => {
t.is(typeof devices.fccids, 'function');
t.truthy(Array.isArray(devices.fccids()));
t.is(devices.fccids().length, 196);
t.is(devices.fccids('iphone').length, 56);
t.throws(function() { devices.fccids('invalidType'); });
});
test('internalNames()', t => {
t.is(typeof devices.internalNames, 'function');
t.truthy(Array.isArray(devices.internalNames()));
t.is(devices.internalNames().length, 185);
t.is(devices.internalNames('iphone').length, 54);
t.throws(function() { devices.internalNames('invalidType'); });
});
test('identifiers()', t => {
t.is(typeof devices.identifiers, 'function');
t.truthy(Array.isArray(devices.identifiers()));
t.is(devices.identifiers().length, 177);
t.is(devices.identifiers('iphone').length, 49);
t.throws(function() { devices.identifiers('invalidType'); });
});
test('colors()', t => {
t.is(typeof devices.colors, 'function');
t.truthy(Array.isArray(devices.colors()));
t.is(devices.colors().length, 31);
t.is(devices.colors('iphone').length, 23);
t.throws(function() { devices.colors('invalidType'); });
});
test('storages()', t => {
t.is(typeof devices.storages, 'function');
t.truthy(Array.isArray(devices.storages()));
t.is(devices.storages().length, 14);
t.is(devices.storages('iphone').length, 9);
t.throws(function() { devices.storages('invalidType'); });
});
test('models()', t => {
t.is(typeof devices.models, 'function');
t.truthy(Array.isArray(devices.models()));
t.is(devices.models().length, 4150);
t.is(devices.models('iphone').length, 2652);
t.throws(function() { devices.models('invalidType'); });
});
test('deviceByGeneration()', t => {
let find = 'iPhone 6s Plus';
t.is(typeof devices.deviceByGeneration, 'function');
t.throws(function() { devices.deviceByGeneration(); });
t.is(typeof devices.deviceByGeneration(find), 'object');
t.is(devices.deviceByGeneration(find).length > 0, true);
t.is(devices.deviceByGeneration(find, 'iphone').length > 0, true);
t.is(devices.deviceByGeneration(find, 'ipad').length, 0);
t.throws(function() { devices.deviceByGeneration(find, 'invalidType'); });
t.is(devices.deviceByGeneration(find.substring(0, 11)).length, 0);
t.is(devices.deviceByGeneration(find.substring(0, 11), null, { contains: true }).length > 0, true);
t.is(devices.deviceByGeneration(find.toLowerCase()).length, 0);
t.is(devices.deviceByGeneration(find.toLowerCase(), null, { caseInsensitive: true }).length > 0, true);
t.is(devices.deviceByGeneration(find.toLowerCase()).length, 0);
t.is(devices.deviceByGeneration(find.substring(0, 11).toLowerCase()).length, 0);
t.is(devices.deviceByGeneration(find.substring(0, 11).toLowerCase(), null, { contains: true }).length, 0);
t.is(devices.deviceByGeneration(find.substring(0, 11).toLowerCase(), null, { caseInsensitive: true }).length, 0);
t.is(devices.deviceByGeneration(find.substring(0, 11).toLowerCase(), null, { contains: true, caseInsensitive: true }).length > 0, true);
});
test('deviceByANumber()', t => {
let find = 'A1634';
t.is(typeof devices.deviceByANumber, 'function');
t.throws(function() { devices.deviceByANumber(); });
t.is(typeof devices.deviceByANumber(find), 'object');
t.is(devices.deviceByANumber(find).length > 0, true);
t.is(devices.deviceByANumber(find, 'iphone').length > 0, true);
t.is(devices.deviceByANumber(find, 'ipad').length, 0);
t.throws(function() { devices.deviceByANumber(find, 'invalidType'); });
t.is(devices.deviceByANumber(find.substring(0, 4)).length, 0);
t.is(devices.deviceByANumber(find.substring(0, 4), null, { contains: true }).length > 0, true);
t.is(devices.deviceByANumber(find.toLowerCase()).length, 0);
t.is(devices.deviceByANumber(find.toLowerCase(), null, { caseInsensitive: true }).length > 0, true);
t.is(devices.deviceByANumber(find.toLowerCase()).length, 0);
t.is(devices.deviceByANumber(find.substring(0, 4).toLowerCase()).length, 0);
t.is(devices.deviceByANumber(find.substring(0, 4).toLowerCase(), null, { contains: true }).length, 0);
t.is(devices.deviceByANumber(find.substring(0, 4).toLowerCase(), null, { caseInsensitive: true }).length, 0);
t.is(devices.deviceByANumber(find.substring(0, 4).toLowerCase(), null, { contains: true, caseInsensitive: true }).length > 0, true);
});
test('deviceByFCCID()', t => {
let find = 'BCG-E2944A';
t.is(typeof devices.deviceByFCCID, 'function');
t.throws(function() { devices.deviceByFCCID(); });
t.is(typeof devices.deviceByFCCID(find), 'object');
t.is(devices.deviceByFCCID(find).length > 0, true);
t.is(devices.deviceByFCCID(find, 'iphone').length > 0, true);
t.is(devices.deviceByFCCID(find, 'ipad').length, 0);
t.throws(function() { devices.deviceByFCCID(find, 'invalidType'); });
t.is(devices.deviceByFCCID(find.substring(0, 8)).length, 0);
// t.is(devices.deviceByFCCID(find.substring(0, 8), null, { contains: true }).length, 48);
t.is(devices.deviceByFCCID(find.substring(0, 8), null, { contains: true }).length > 0, true);
t.is(devices.deviceByFCCID(find.toLowerCase()).length, 0);
t.is(devices.deviceByFCCID(find.toLowerCase(), null, { caseInsensitive: true }).length > 0, true);
t.is(devices.deviceByFCCID(find.toLowerCase()).length, 0);
t.is(devices.deviceByFCCID(find.substring(0, 8).toLowerCase()).length, 0);
t.is(devices.deviceByFCCID(find.substring(0, 8).toLowerCase(), null, { contains: true }).length, 0);
t.is(devices.deviceByFCCID(find.substring(0, 8).toLowerCase(), null, { caseInsensitive: true }).length, 0);
// t.is(devices.deviceByFCCID(find.substring(0, 8).toLowerCase(), null, { contains: true, caseInsensitive: true }).length, 48);
t.is(devices.deviceByFCCID(find.substring(0, 8).toLowerCase(), null, { contains: true, caseInsensitive: true }).length > 0, true);
});
test('deviceByInternalName()', t => {
let find = 'N66AP';
t.is(typeof devices.deviceByInternalName, 'function');
t.throws(function() { devices.deviceByInternalName(); });
t.is(typeof devices.deviceByInternalName(find), 'object');
t.is(devices.deviceByInternalName(find).length > 0, true);
t.is(devices.deviceByInternalName(find, 'iphone').length > 0, true);
t.is(devices.deviceByInternalName(find, 'ipad').length, 0);
t.throws(function() { devices.deviceByInternalName(find, 'invalidType'); });
t.is(devices.deviceByInternalName(find.substring(0, 4)).length, 0);
t.is(devices.deviceByInternalName(find.substring(0, 4), null, { contains: true }).length > 0, true);
t.is(devices.deviceByInternalName(find.toLowerCase()).length, 0);
t.is(devices.deviceByInternalName(find.toLowerCase(), null, { caseInsensitive: true }).length > 0, true);
t.is(devices.deviceByInternalName(find.toLowerCase()).length, 0);
t.is(devices.deviceByInternalName(find.substring(0, 4).toLowerCase()).length, 0);
t.is(devices.deviceByInternalName(find.substring(0, 4).toLowerCase(), null, { contains: true }).length, 0);
t.is(devices.deviceByInternalName(find.substring(0, 4).toLowerCase(), null, { caseInsensitive: true }).length, 0);
t.is(devices.deviceByInternalName(find.substring(0, 4).toLowerCase(), null, { contains: true, caseInsensitive: true }).length > 0, true);
});
test('deviceByIdentifier()', t => {
let find = 'iPhone8,2';
t.is(typeof devices.deviceByIdentifier, 'function');
t.throws(function() { devices.deviceByIdentifier(); });
t.is(typeof devices.deviceByIdentifier(find), 'object');
t.is(devices.deviceByIdentifier(find).length > 0, true);
t.is(devices.deviceByIdentifier(find, 'iphone').length > 0, true);
t.is(devices.deviceByIdentifier(find, 'ipad').length, 0);
t.throws(function() { devices.deviceByIdentifier(find, 'invalidType'); });
t.is(devices.deviceByIdentifier(find.substring(0, 8)).length, 0);
// t.is(devices.deviceByIdentifier(find.substring(0, 8), null, { contains: true }).length, 56);
t.is(devices.deviceByIdentifier(find.substring(0, 8), null, { contains: true }).length > 0, true);
t.is(devices.deviceByIdentifier(find.toLowerCase()).length, 0);
t.is(devices.deviceByIdentifier(find.toLowerCase(), null, { caseInsensitive: true }).length > 0, true);
t.is(devices.deviceByIdentifier(find.toLowerCase()).length, 0);
t.is(devices.deviceByIdentifier(find.substring(0, 8).toLowerCase()).length, 0);
t.is(devices.deviceByIdentifier(find.substring(0, 8).toLowerCase(), null, { contains: true }).length, 0);
t.is(devices.deviceByIdentifier(find.substring(0, 8).toLowerCase(), null, { caseInsensitive: true }).length, 0);
// t.is(devices.deviceByIdentifier(find.substring(0, 8).toLowerCase(), null, { contains: true, caseInsensitive: true }).length, 56);
t.is(devices.deviceByIdentifier(find.substring(0, 8).toLowerCase(), null, { contains: true, caseInsensitive: true }).length > 0, true);
});
test('deviceByColor()', t => {
let find = 'Rose Gold';
t.is(typeof devices.deviceByColor, 'function');
t.throws(function() { devices.deviceByColor(); });
t.is(typeof devices.deviceByColor(find), 'object');
t.is(devices.deviceByColor(find).length > 0, true);
t.is(devices.deviceByColor(find, 'iphone').length > 0, true);
t.is(devices.deviceByColor(find, 'ipad').length > 0, false);
t.throws(function() { devices.deviceByColor(find, 'invalidType'); });
t.is(devices.deviceByColor(find.substring(0, 8)).length, 0);
t.is(devices.deviceByColor(find.substring(0, 8), null, { contains: true }).length > 0, true);
t.is(devices.deviceByColor(find.toLowerCase()).length, 0);
t.is(devices.deviceByColor(find.toLowerCase(), null, { caseInsensitive: true }).length > 0, true);
t.is(devices.deviceByColor(find.toLowerCase()).length, 0);
t.is(devices.deviceByColor(find.substring(0, 8).toLowerCase()).length, 0);
t.is(devices.deviceByColor(find.substring(0, 8).toLowerCase(), null, { contains: true }).length, 0);
t.is(devices.deviceByColor(find.substring(0, 8).toLowerCase(), null, { caseInsensitive: true }).length, 0);
t.is(devices.deviceByColor(find.substring(0, 8).toLowerCase(), null, { contains: true, caseInsensitive: true }).length > 0, true);
});
test('deviceByStorage()', t => {
let find = '128 GB';
t.is(typeof devices.deviceByStorage, 'function');
t.throws(function() { devices.deviceByStorage(); });
t.is(typeof devices.deviceByStorage(find), 'object');
t.is(devices.deviceByStorage(find).length > 0, true);
t.is(devices.deviceByStorage(find, 'iphone').length > 0, true);
t.is(devices.deviceByStorage(find, 'ipad').length > 0, true);
t.throws(function() { devices.deviceByStorage(find, 'invalidType'); });
t.is(devices.deviceByStorage(find.substring(0, 4)).length, 0);
t.is(devices.deviceByStorage(find.substring(0, 4), null, { contains: true }).length > 0, true);
t.is(devices.deviceByStorage(find.toLowerCase()).length, 0);
t.is(devices.deviceByStorage(find.toLowerCase(), null, { caseInsensitive: true }).length > 0, true);
t.is(devices.deviceByStorage(find.toLowerCase()).length, 0);
t.is(devices.deviceByStorage(find.substring(0, 4).toLowerCase()).length, 0);
t.is(devices.deviceByStorage(find.substring(0, 4).toLowerCase(), null, { contains: true }).length > 0, true);
t.is(devices.deviceByStorage(find.substring(0, 4).toLowerCase(), null, { caseInsensitive: true }).length, 0);
t.is(devices.deviceByStorage(find.substring(0, 4).toLowerCase(), null, { contains: true, caseInsensitive: true }).length > 0, true);
});
test('deviceByModel()', t => {
let find = 'MKU52';
t.is(typeof devices.deviceByModel, 'function');
t.throws(function() { devices.deviceByModel(); });
t.is(typeof devices.deviceByModel(find), 'object');
t.is(devices.deviceByModel(find).length, 1);
t.is(devices.deviceByModel(find, 'iphone').length, 1);
t.is(devices.deviceByModel(find, 'ipad').length, 0);
t.throws(function() { devices.deviceByModel(find, 'invalidType'); });
t.is(devices.deviceByModel(find.substring(0, 3)).length, 0);
t.is(devices.deviceByModel(find.substring(0, 3), null, { contains: true }).length > 0, true);
t.is(devices.deviceByModel(find.toLowerCase()).length, 0);
t.is(devices.deviceByModel(find.toLowerCase(), null, { caseInsensitive: true }).length, 1);
t.is(devices.deviceByModel(find.toLowerCase()).length, 0);
t.is(devices.deviceByModel(find.substring(0, 3).toLowerCase()).length, 0);
t.is(devices.deviceByModel(find.substring(0, 3).toLowerCase(), null, { contains: true }).length, 0);
t.is(devices.deviceByModel(find.substring(0, 3).toLowerCase(), null, { caseInsensitive: true }).length, 0);
t.is(devices.deviceByModel(find.substring(0, 3).toLowerCase(), null, { contains: true, caseInsensitive: true }).length > 0, true);
});
test('generationByIdentifier()', t => {
let find = 'iPhone8,2';
t.is(typeof devices.generationByIdentifier, 'function');
t.throws(function() { devices.generationByIdentifier(); });
t.is(typeof devices.generationByIdentifier(find), 'string');
t.is(devices.generationByIdentifier(find), 'iPhone 6s Plus');
t.is(devices.generationByIdentifier(find, 'iphone'), 'iPhone 6s Plus');
t.is(devices.generationByIdentifier(find, 'ipad'), undefined);
t.throws(function() { devices.generationByIdentifier(find, 'invalidType'); });
});
test('Issue 23: iPad Pro (12.9-inch) (5th generation) which does not have any Model', t => {
let find = 'iPad13,8';
const ipadPros = devices.devices('ipad_pro');
t.is(typeof ipadPros, 'object');
t.is(ipadPros.filter(t => t.Identifier === find).length, 1);
t.is(ipadPros.filter(t => t.Identifier === find)[0].Generation, 'iPad Pro (12.9-inch) (5th generation)');
});