-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
427 lines (386 loc) · 16.4 KB
/
tests.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
QUnit.config.reorder = false;
(function() {
'use strict';
//////////////////////////////////
// reporting
// log results to console for PhantomJS
QUnit.log(function(details) {
if (details.result === true) {
return;
}
console.log(
'TEST FAILURE. ' +
'MODULE: ' + details.module + ', ' +
'NAME: ' + details.name + ', ' +
'MESSAGE: ' + details.message
);
});
// log results to console for PhantomJS
QUnit.done(function(details) {
console.log(
'Total: ' + details.total + ', ' +
'Failed: ' + details.failed + ', ' +
'Passed: ' + details.passed + ', ' +
'Time: ' + details.runtime + 'ms'
);
});
var iHowManyButtons = window._ui5query_numOfEachType,
iHowManyTexts = window._ui5query_numOfEachType,
iHowManyDatePickers = window._ui5query_numOfEachType,
iHowManyLabels = window._ui5query_numOfEachType,
iTotalMatches = iHowManyButtons + iHowManyTexts + iHowManyDatePickers + iHowManyLabels;
//////////////////////////////////
// utility functions
function howManyPopups() {
return jQuery('.ui5query_label').length;
}
function howManyHighlighting() {
return jQuery('.ui5query_match').length;
}
function getPopupTextMatch(i) {
i = (i !== undefined) ? i : 0;
return jQuery('.ui5query_label').eq(i)
.find('strong')
.toArray()
.map(function($strong) {
return $strong.innerHTML;
})
.join(',');
}
//////////////////////////////////
// setup
function beforeEach() {
ui$.reset();
ui$.config({
standoutDelay: iDelay
});
}
function afterEach(assert) {
var done = assert.async();
setTimeout(function() {
ui$.reset();
done();
}, iDelay * 2);
}
// configure how long each test should take
// take into consideration the highlighting setTimeout
var iDelay = starparam.get('delay') || 500;
iDelay = parseInt(iDelay, 10);
//////////////////////////////////
// tests
QUnit.module('search', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('no match', function(assert) {
assert.strictEqual(ui$.search('zzz').length, 0, '0 results');
});
QUnit.test('string match', function(assert) {
assert.strictEqual(ui$.search('button').length, iHowManyButtons, 'all buttons returned');
});
QUnit.test('regex match', function(assert) {
assert.strictEqual(ui$.search(/bu.*on/).length, iHowManyButtons, 'all buttons returned');
});
QUnit.test('all regex', function(assert) {
assert.strictEqual(ui$.search(/.*/).length, iTotalMatches, 'all results');
});
QUnit.test('no args matches everythin', function(assert) {
assert.strictEqual(ui$.search().length, iTotalMatches, 'all results');
});
QUnit.test('by control type', function(assert) {
assert.strictEqual(ui$.search('sap.m.Button').length, iHowManyButtons, 'all buttons returned');
});
QUnit.test('returns control types', function(assert) {
var oFirstButton = ui$.search('button1')[0];
assert.strictEqual(oFirstButton.getMetadata().getName(), 'sap.m.Button', 'button found');
});
QUnit.module('"all" api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('smoke', function(assert) {
assert.strictEqual(ui$.all().length, iTotalMatches, 'all controls found');
});
QUnit.test('returns control types', function(assert) {
assert.strictEqual(typeof ui$.all()[0].getMetadata, 'function', 'control was returned');
});
QUnit.test('in sync with search api', function(assert) {
assert.expect(iTotalMatches);
var aSearchResults = ui$.search(/.*/),
aAllResults = ui$.all();
for (var i = 0; i < iTotalMatches; i++) {
assert.strictEqual(aSearchResults[i].getId(), aAllResults[i].getId(), 'record ' + i + ' in sync');
}
});
QUnit.module('popup', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('via search api', function(assert) {
ui$.popup(ui$.search('button'));
assert.strictEqual(howManyPopups(), iHowManyButtons, 'all buttons given popups');
});
QUnit.test('via all api', function(assert) {
ui$.popup(ui$.all());
assert.strictEqual(howManyPopups(), iTotalMatches, 'all popups appear');
});
QUnit.test('via pipe api with sub-set (string) of matches', function(assert) {
ui$.pipe('button').popup();
assert.strictEqual(howManyPopups(), iHowManyButtons, 'all button popups appear');
});
QUnit.test('via pipe api with sub-set (regexp) of matches', function(assert) {
ui$.pipe(/bu\w\won/).popup();
assert.strictEqual(howManyPopups(), iHowManyButtons, 'all button popups appear');
});
QUnit.test('via pipe api with all matches', function(assert) {
ui$.pipe(/.*/).popup();
assert.strictEqual(howManyPopups(), iTotalMatches, 'all popups appear');
});
QUnit.module('highlighting', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('via search api', function(assert) {
ui$.highlight(ui$.search('button'));
assert.strictEqual(howManyHighlighting(), iHowManyButtons, 'all buttons given highlighting');
});
QUnit.test('via all api', function(assert) {
ui$.highlight(ui$.all());
assert.strictEqual(howManyHighlighting(), iTotalMatches, 'all highlighting appear');
});
QUnit.test('via pipe api with sub-set (string) of matches', function(assert) {
ui$.pipe('button').highlight();
assert.strictEqual(howManyHighlighting(), iHowManyButtons, 'all button highlighting appear');
});
QUnit.test('via pipe api with sub-set (regexp) of matches', function(assert) {
ui$.pipe(/bu\w\won/).highlight();
assert.strictEqual(howManyHighlighting(), iHowManyButtons, 'all button highlighting appear');
});
QUnit.test('via pipe api with all matches', function(assert) {
ui$.pipe(/.*/).highlight();
assert.strictEqual(howManyHighlighting(), iTotalMatches, 'all highlighting appear');
});
QUnit.module('inProgress flag', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('inProgress flag', function(assert) {
ui$.popup(ui$.search('button'));
ui$.popup(ui$.search('button'));
assert.strictEqual(howManyPopups(), iHowManyButtons, 'correct number of button popups are shown (not double)');
});
QUnit.module('target variables', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('target variables populated', function(assert) {
ui$.search(/.*/);
assert.strictEqual(ui$.target.getId(), '__button0', 'target is populated');
assert.strictEqual(ui$.target0, ui$.target, 'target0 is populated');
assert.strictEqual(ui$.target1.getId(), '__button1', 'target1 is populated');
assert.strictEqual(ui$.target9.getId(), '__label0', 'target9 is populated');
});
QUnit.test('target variables are reset', function(assert) {
ui$.search(/.*/);
ui$.search('zzz'); // there should be no "zzz" match
assert.strictEqual(ui$.target, undefined, 'target was reset');
assert.strictEqual(ui$.target0, undefined, 'target0 was reset');
assert.strictEqual(ui$.target1, undefined, 'target1 was reset');
assert.strictEqual(ui$.target2, undefined, 'target1 was reset');
assert.strictEqual(ui$.target9, undefined, 'target1 was reset');
});
QUnit.test('targets that should never be set', function(assert) {
ui$.search(/.*/);
assert.strictEqual(ui$.target10, undefined, 'target10 should never be set');
assert.strictEqual(ui$.target11, undefined, 'target11 should never be set');
});
QUnit.test('set after all api', function(assert) {
ui$.all();
assert.strictEqual(ui$.target0.getId(), '__button0', 'target 0 is populated');
assert.strictEqual(ui$.target9.getId(), '__label0', 'target 9 is populated');
});
QUnit.test('set after all pipe api (all)', function(assert) {
ui$.pipe(/.*/);
assert.strictEqual(ui$.target0.getId(), '__button0', 'target 0 is populated');
assert.strictEqual(ui$.target9.getId(), '__label0', 'target 9 is populated');
});
QUnit.test('set after all pipe api (subset)', function(assert) {
ui$.pipe('button');
assert.strictEqual(ui$.target0.getId(), '__button0', 'target 0 is populated');
assert.strictEqual(ui$.target9, undefined, 'target 9 is undefined');
});
QUnit.test('set after all highlight api (all)', function(assert) {
ui$.highlight(/.*/);
assert.strictEqual(ui$.target0.getId(), '__button0', 'target 0 is populated');
assert.strictEqual(ui$.target9.getId(), '__label0', 'target 9 is populated');
});
QUnit.test('set after all highlight api (subset)', function(assert) {
ui$.highlight('button');
assert.strictEqual(ui$.target0.getId(), '__button0', 'target 0 is populated');
assert.strictEqual(ui$.target9, undefined, 'target 9 is undefined');
});
QUnit.test('set after all popup api (all)', function(assert) {
ui$.popup(/.*/);
assert.strictEqual(ui$.target0.getId(), '__button0', 'target 0 is populated');
assert.strictEqual(ui$.target9.getId(), '__label0', 'target 9 is populated');
});
QUnit.test('set after all popup api (subset)', function(assert) {
ui$.popup('button');
assert.strictEqual(ui$.target0.getId(), '__button0', 'target 0 is populated');
assert.strictEqual(ui$.target9, undefined, 'target 9 is undefined');
});
QUnit.module('config api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('api returns config', function(assert) {
assert.strictEqual(typeof ui$.config().standoutDelay, 'number', 'config object is returned');
});
QUnit.test('api alters config', function(assert) {
ui$.config({ standoutDelay: 10 });
assert.strictEqual(ui$.config().standoutDelay, 10, 'config object is correct');
});
QUnit.test('reset', function(assert) {
ui$.config({ standoutDelay: 10 });
ui$.reset();
assert.ok(ui$.config().standoutDelay !== 10, 'config object was reset');
});
QUnit.module('controlStyle config api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('custom control style', function(assert) {
ui$.config({
controlStyle: { fontSize: '5px' }
});
ui$.highlight(ui$.all());
assert.strictEqual(ui$.search('button')[0].$().css('fontSize'), '5px', 'custom styling applied');
});
QUnit.module('labelStyle config api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('custom label style', function(assert) {
ui$.config({
labelStyle: { display: 'none' }
});
ui$.popup(ui$.all());
assert.strictEqual(jQuery('.ui5query_label:first').css('display'), 'none', 'custom styling applied');
});
QUnit.module('pipe api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('pipe toArray', function(assert) {
assert.strictEqual(ui$.pipe(/.*/).toArray().length, iTotalMatches, 'all returned matches');
});
QUnit.test('pipe no args', function(assert) {
assert.strictEqual(ui$.pipe().toArray().length, iTotalMatches, 'all returned matches');
});
QUnit.test('pipe toArray -> correct type', function(assert) {
assert.strictEqual(ui$.pipe(/.*/).toArray()[0].hasAttribute('data-sap-ui'), true, 'correct type');
});
QUnit.test('pipe just match button -> toArray', function(assert) {
assert.strictEqual(ui$.pipe(/bu\w\won/).toArray().length, iHowManyButtons, 'all buttons returned');
});
QUnit.test('pipe highlighted and popup', function(assert) {
ui$.pipe(/.*/).highlight().popup();
assert.strictEqual(howManyHighlighting(), iTotalMatches, 'all matches highlighted');
assert.strictEqual(howManyPopups(), iTotalMatches, 'all popups visible');
});
QUnit.test('pipe standout', function(assert) {
ui$.pipe(/.*/).standout();
assert.strictEqual(howManyHighlighting(), iTotalMatches, 'all matches highlighted');
assert.strictEqual(howManyPopups(), iTotalMatches, 'all popups visible');
});
QUnit.test('target variables', function(assert) {
assert.strictEqual(ui$.pipe('button').target0.getId(), '__button0', 'target 0 is populated');
});
QUnit.test('borrowed filter', function(assert) {
var aResults = ui$.pipe('button').filter(function(oResult) {
return oResult.getId() === '__button0';
});
assert.strictEqual(aResults.length, 1, 'filter worked');
});
QUnit.test('borrowed map', function(assert) {
var aResults = ui$.pipe('button').map(function(oResult) {
return oResult.getId();
});
assert.strictEqual(aResults[0], '__button0', 'map worked');
});
QUnit.test('length', function(assert) {
assert.strictEqual(ui$.pipe('button').length, iHowManyButtons, 'correct length');
});
QUnit.module('toPipeline api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('toPipeline toArray', function(assert) {
assert.strictEqual(ui$.toPipeline(ui$.all()).toArray().length, iTotalMatches, 'all matches returned');
});
QUnit.test('toPipeline toArray', function(assert) {
var aResults_button = ui$.search('button');
var aResults_all = ui$.search(/.*/);
assert.strictEqual(ui$.toPipeline(aResults_button).toArray().length, iHowManyButtons, 'only buttons returned');
});
QUnit.module('popup query api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('smoke', function(assert) {
ui$.popup(/.*/);
assert.strictEqual(howManyPopups(), iTotalMatches, 'all popups appear');
});
QUnit.test('subset', function(assert) {
ui$.popup(/button/);
assert.strictEqual(howManyPopups(), iHowManyButtons, 'all buttons have popups');
});
QUnit.module('highlight query api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('smoke', function(assert) {
ui$.highlight(/.*/);
assert.strictEqual(howManyHighlighting(), iTotalMatches, 'all matches highlighted');
});
QUnit.test('subset', function(assert) {
ui$.highlight(/button/);
assert.strictEqual(howManyHighlighting(), iHowManyButtons, 'all buttons highlighted');
});
// standout api
QUnit.module('standout query api', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('smoke', function(assert) {
ui$.standout(/.*/);
assert.strictEqual(howManyPopups(), iTotalMatches, 'all popups shown');
assert.strictEqual(howManyHighlighting(), iTotalMatches, 'all matches highlighted');
});
QUnit.test('subset', function(assert) {
ui$.standout(/button/);
assert.strictEqual(howManyPopups(), iHowManyButtons, 'all button popups shown');
assert.strictEqual(howManyHighlighting(), iHowManyButtons, 'all buttons highlighted');
});
QUnit.module('jQuery-like design', {
beforeEach: beforeEach,
afterEach: afterEach
});
QUnit.test('find all', function(assert) {
assert.strictEqual(ui$(/.*/).toArray().length, iTotalMatches, 'all controls found');
});
QUnit.test('other forms', function(assert) {
assert.strictEqual(ui5Query(/.*/).toArray().length, iTotalMatches, 'all controls found');
});
QUnit.test('empty arg', function(assert) {
assert.strictEqual(ui$().toArray().length, iTotalMatches, 'all controls found');
});
QUnit.test('subset', function(assert) {
assert.strictEqual(ui$(/button/).toArray().length, iHowManyButtons, 'all buttons found');
});
QUnit.test('use pipeline', function(assert) {
ui$(/button/).popup().highlight();
assert.strictEqual(howManyPopups(), iHowManyButtons, 'all button popups shown');
assert.strictEqual(howManyHighlighting(), iHowManyButtons, 'all buttons highlighted');
});
}());