This repository has been archived by the owner on Jun 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
tableDirective.spec.ts
628 lines (517 loc) · 28.1 KB
/
tableDirective.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
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
'use strict';
import * as ng from 'angular';
describe('tableDirective: <uif-table />', () => {
let element: JQuery;
let scope: any;
beforeEach(() => {
angular.mock.module('officeuifabric.core');
angular.mock.module('officeuifabric.components.table');
});
beforeEach(inject(($rootScope: ng.IRootScopeService, $compile: Function) => {
scope = $rootScope;
}));
it('should render table using a table tag', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.prop('tagName')).toEqual('TABLE');
}));
it('should set correct Office UI Fabric classes on the table', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element).toHaveClass('ms-Table');
}));
it('should set correct Office UI Fabric fixed class on the table for the \'uif-table-type\' attribute',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-table-type="fixed"></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element).toHaveClass('ms-Table--fixed');
}));
it('should set correct Office UI Fabric fluid class on the table for the \'uif-table-type\' attribute',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-table-type="fluid"></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element).not.toHaveClass('ms-Table--fixed');
}));
it('should throw an error on an invalid value for the \'uif-table-type\' attribute',
inject(($compile: Function, $rootScope: ng.IRootScopeService, $log: ng.ILogService) => {
element = ng.element('<uif-table uif-table-type="invalid"></uif-table>');
$compile(element)(scope);
scope.$digest();
expect($log.error.logs.length).toEqual(1);
}));
it('should render the row using a tr tag', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.children().eq(0).prop('tagName')).toEqual('TR');
}));
it('should set no Office UI Fabric classes on the row', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.children().eq(0)).not.toHaveClass('ms-Table-row');
}));
it('should set correct Office UI Fabric classes on the selected and unselected rows',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row></uif-table-row>\
<uif-table-row uif-selected="true"></uif-table-row><uif-table-row uif-selected="false"></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
let rows: JQuery = element.children();
expect(rows.length).toEqual(3);
expect(rows.eq(0)).not.toHaveClass('is-selected');
expect(rows.eq(1)).toHaveClass('is-selected');
expect(rows.eq(2)).not.toHaveClass('is-selected');
}));
it('should throw an error on an invalid value for the \'uif-selected\' attribute',
inject(($compile: Function, $rootScope: ng.IRootScopeService, $log: ng.ILogService) => {
element = ng.element('<uif-table><uif-table-row uif-selected="invalid"></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect($log.error.logs.length).toEqual(1);
}));
it('should render table row select using the td tag', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.children().eq(0).children().eq(0).prop('tagName')).toEqual('TD');
}));
it('should render table row select using the th tag in thead', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table>\
<uif-table-head><uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table-head>\
<uif-table-body><uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table-body>\
</uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.children().eq(0) // thead
.children().eq(0) // tr
.children().eq(0) // table-row-select
.prop('tagName')).toEqual('TH');
}));
it('should render table row select using the td tag in tbody', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table>\
<uif-table-head><uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table-head>\
<uif-table-body><uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table-body>\
</uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.children().eq(1) // tbody
.children().eq(0) // tr
.children().eq(0) // table-row-select
.prop('tagName')).toEqual('TD');
}));
it('should set correct Office UI Fabric classes on the table row select',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.children().eq(0).children().eq(0)).toHaveClass('ms-Table-rowCheck');
}));
it('should render the cell using a td tag', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table-cell></uif-table-cell>');
$compile(element)(scope);
scope.$digest();
expect(element.prop('tagName')).toEqual('TD');
}));
it('should set no Office UI Fabric classes on the table cell', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table-cell></uif-table-cell>');
$compile(element)(scope);
scope.$digest();
expect(element).not.toHaveClass('ms-Table-cell');
}));
it('should render the table header using a th tag', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.children().eq(0).children().eq(0).prop('tagName')).toEqual('TH');
}));
it('should set no Office UI Fabric classes on the table header', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(element.children().eq(0).children().eq(0)).not.toHaveClass('ms-Table-cell');
}));
it('should trigger sorting only on enabled header cells', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header></uif-table-header>\
<uif-table-header uif-order-by="fileName"></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let headerCells: JQuery = element.children().eq(0).children();
headerCells.eq(0).click(); // sorting disabled for this column; do nothing
expect(scope.orderBy).toBeNull();
headerCells.eq(1).click(); // sort fileName:asc
expect(scope.orderBy).toEqual('fileName');
}));
it('should render the data in its originally declared order by default',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header></uif-table-header>\
<uif-table-header uif-order-by="fileName"></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(scope.orderBy).toBeNull();
expect(scope.orderAsc).toBeTruthy();
}));
it('should correctly indicate column used for sorting', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header></uif-table-header>\
<uif-table-header uif-order-by="fileName"></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let fileNameHeader: JQuery = element.children().eq(0).children().eq(1);
fileNameHeader.click();
expect(fileNameHeader.children().length).toEqual(1, 'Sorting indicator not added to column');
let sortingIndicatorWrapper: JQuery = fileNameHeader.children().eq(0);
expect(sortingIndicatorWrapper.prop('tagName')).toEqual('SPAN');
expect(sortingIndicatorWrapper).toHaveClass('uif-sort-order');
let sortingIndicator: JQuery = sortingIndicatorWrapper.children().eq(0);
expect(sortingIndicator.prop('tagName')).toEqual('I');
expect(sortingIndicator).toHaveClass('ms-Icon');
expect(sortingIndicator).toHaveClass('ms-Icon--caretDown');
}));
it('should correctly indicate reversed sorting order', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header>ID</uif-table-header>\
<uif-table-header uif-order-by="fileName">File name</uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let fileNameHeader: JQuery = element.children().eq(0).children().eq(1);
fileNameHeader.click();
fileNameHeader.click();
let sortingIndicatorWrapper: JQuery = fileNameHeader.children().eq(1);
let sortingIndicator: JQuery = sortingIndicatorWrapper.children().eq(0);
expect(sortingIndicator).toHaveClass('ms-Icon--caretUp');
}));
it('should sort data ascending after selecting a column for sorting', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header></uif-table-header>\
<uif-table-header uif-order-by="fileName"></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let fileNameHeader: JQuery = element.children().eq(0).children().eq(1);
fileNameHeader.click();
expect(scope.orderAsc).toBeTruthy();
}));
it('should reverse the sorting order when selecting the same column for sorting',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header></uif-table-header>\
<uif-table-header uif-order-by="fileName"></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let fileNameHeader: JQuery = element.children().eq(0).children().eq(1);
fileNameHeader.click();
expect(scope.orderAsc).toBeTruthy();
fileNameHeader.click();
expect(scope.orderAsc).toBeFalsy();
fileNameHeader.click();
expect(scope.orderAsc).toBeTruthy();
}));
it('should clear the sorting indicator after selecting another column for sorting',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header uif-order-by="id">ID</uif-table-header>\
<uif-table-header uif-order-by="fileName">File name</uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let idHeader: JQuery = element.children().eq(0).children().eq(0);
let fileNameHeader: JQuery = element.children().eq(0).children().eq(1);
idHeader.click(); // sort id:asc
fileNameHeader.click(); // sort fileName:asc
expect(idHeader.children().length).toEqual(1, 'Sorting indicator not removed from column previously used for sorting');
expect(fileNameHeader.children().length).toEqual(2, 'Sorting indicator not added to the column used for sorting');
}));
it('should change the sorting order to ascending after selecting another column for sorting',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header uif-order-by="id"></uif-table-header>\
<uif-table-header uif-order-by="fileName"></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let idHeader: JQuery = element.children().eq(0).children().eq(0);
let fileNameHeader: JQuery = element.children().eq(0).children().eq(1);
idHeader.click(); // sort id:asc
idHeader.click(); // sort id:desc
fileNameHeader.click(); // sort fileName:asc
expect(scope.orderAsc).toBeTruthy();
}));
it('should keep the sorting data intact after selecting another column for which sorting hasn\'t been enabled',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table><uif-table-row><uif-table-header></uif-table-header>\
<uif-table-header uif-order-by="fileName"></uif-table-header></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let firstHeader: JQuery = element.children().eq(0).children().eq(0);
let fileNameHeader: JQuery = element.children().eq(0).children().eq(1);
fileNameHeader.click(); // sort fileName:asc
firstHeader.click(); // sorting disabled; do nothing
expect(scope.orderBy).toEqual('fileName');
expect(scope.orderAsc).toBeTruthy();
}));
it('should not allow to select rows by default', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table>' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(scope.rowSelectMode).toEqual('none');
}));
it('should allow to explicitly disable row selecting', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="none">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect(scope.rowSelectMode).toEqual('none');
}));
it('for row select mode \'single\' should allow to select single row',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="single">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
expect(scope.rowSelectMode).toEqual('single');
let firstDataRow: JQuery = element.children().eq(1);
let secondDataRow: JQuery = element.children().eq(2);
firstDataRow.click();
secondDataRow.click();
let numSelectedItems: number = 0;
for (let i: number = 0; i < scope.rows.length; i++) {
if (scope.rows[i].selected === true) {
numSelectedItems++;
}
}
expect(numSelectedItems).toEqual(1);
}));
it('for row mode select \'multiple\' should allow to select multiple rows',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="multiple">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
expect(scope.rowSelectMode).toEqual('multiple');
let firstDataRow: JQuery = element.children().eq(1);
let secondDataRow: JQuery = element.children().eq(2);
firstDataRow.click();
secondDataRow.click();
let numSelectedItems: number = 0;
for (let i: number = 0; i < scope.rows.length; i++) {
if (scope.rows[i].selected === true) {
numSelectedItems++;
}
}
expect(numSelectedItems).toEqual(2);
}));
it('should throw an error on an invalid row select mode',
inject(($compile: Function, $rootScope: ng.IRootScopeService, $log: ng.ILogService) => {
element = ng.element('<uif-table uif-row-select-mode="invalid">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
expect($log.error.logs.length).toEqual(1);
}));
it('shouldn\'t allow selecting the header row', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="single">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let headerRow: JQuery = element.children().eq(0);
headerRow.click();
expect(headerRow).not.toHaveClass('is-selected');
let numSelectedItems: number = 0;
for (let i: number = 0; i < scope.rows.length; i++) {
if (scope.rows[i].selected === true) {
numSelectedItems++;
}
}
expect(numSelectedItems).toEqual(0);
}));
it('for row select mode \'none\' should use default mouse cursor', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="none">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
let tableRow: JQuery = element.children().eq(1);
expect(tableRow.css('cursor')).toEqual('default');
}));
it('for row select mode \'none\' shouldn\'t select a row on mouse click',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="none">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let tableRow: JQuery = element.children().eq(1);
tableRow.click();
expect(tableRow).not.toHaveClass('is-selected');
expect(scope.rows[1].selected).toBeFalsy();
}));
it('for row select mode \'none\' shouldn\'t select all rows when clicking the table row selector in the header',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="none">' +
'<uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let tableRowSelect: JQuery = element.children().eq(0).children().eq(0);
tableRowSelect.click();
let numSelectedItems: number = 0;
for (let i: number = 0; i < scope.rows.length; i++) {
if (scope.rows[i].selected === true) {
numSelectedItems++;
}
}
expect(numSelectedItems).toEqual(0);
}));
it('for row select mode \'single\' should use hand mouse cursor', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="single">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
let tableRow: JQuery = element.children().eq(1);
// already set to hand by Office UI Fabric
expect(tableRow.css('cursor')).toEqual('');
}));
it('for row select mode \'single\' when clicking a row should select that row and deselect other selected row',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="single">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let firstDataRow: JQuery = element.children().eq(1);
let secondDataRow: JQuery = element.children().eq(2);
firstDataRow.click(); // select first row
secondDataRow.click(); // select second row
expect(firstDataRow).not.toHaveClass('is-selected');
expect(secondDataRow).toHaveClass('is-selected');
expect(scope.rows[0].selected).toBeFalsy();
expect(scope.rows[1].selected).toBeTruthy();
}));
it('for row select mode \'single\' when clicking an already selected row should unselect that row',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="single">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let firstDataRow: JQuery = element.children().eq(1);
firstDataRow.click(); // select first row
firstDataRow.click(); // unselect first row
expect(firstDataRow).not.toHaveClass('is-selected');
expect(scope.rows[0].selected).toBeFalsy();
}));
it('for row select mode \'single\' when clicking the row selector in the header shouldn\'t do anything',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="single">' +
'<uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let tableRowSelectInHeader: JQuery = element.children().eq(0).children().eq(0);
tableRowSelectInHeader.click();
let numSelectedItems: number = 0;
for (let i: number = 0; i < scope.rows.length; i++) {
if (scope.rows[i].selected === true) {
numSelectedItems++;
}
}
expect(numSelectedItems).toEqual(0);
}));
it('for row select mode \'multiple\' should use hand mouse cursor', inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="multiple">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
scope.$digest();
let tableRow: JQuery = element.children().eq(1);
// already set to hand by Office UI Fabric
expect(tableRow.css('cursor')).toEqual('');
}));
it('for row select mode \'multiple\' clicking an unselected row should select that row',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="multiple">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let tableRow: JQuery = element.children().eq(1);
tableRow.click();
expect(tableRow).toHaveClass('is-selected');
expect(scope.rows[0].selected).toBeTruthy();
}));
it('for row select mode \'multiple\' clicking an already selected row should unselect that row',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="multiple">' +
'<uif-table-row></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let tableRow: JQuery = element.children().eq(1);
tableRow.click(); // select row
tableRow.click(); // unselect row
expect(tableRow).not.toHaveClass('is-selected');
expect(scope.rows[0].selected).toBeFalsy();
}));
it('for row select mode \'multiple\' clicking the row selected in the header should select all rows if not all rows are selected',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="multiple">' +
'<uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
let tableRowSelect: JQuery = element.children().eq(0).children().eq(0);
tableRowSelect.click();
let numSelectedItems: number = 0;
for (let i: number = 0; i < scope.rows.length; i++) {
if (scope.rows[i].selected === true) {
numSelectedItems++;
}
}
expect(numSelectedItems).toEqual(3);
}));
it('for row select mode \'multiple\' clicking the row selected in the header should unselect all rows if all rows are selected',
inject(($compile: Function, $rootScope: ng.IRootScopeService) => {
element = ng.element('<uif-table uif-row-select-mode="multiple">' +
'<uif-table-row><uif-table-row-select></uif-table-row-select></uif-table-row>' +
'<uif-table-row ng-repeat="n in [1, 2, 3]" uif-item="n"><uif-table-row-select></uif-table-row-select></uif-table-row></uif-table>');
$compile(element)(scope);
element = jQuery(element[0]);
scope.$digest();
// select all rows
element.children().eq(1).click();
element.children().eq(2).click();
element.children().eq(3).click();
let tableRowSelect: JQuery = element.children().eq(0).children().eq(0);
tableRowSelect.click();
let numSelectedItems: number = 0;
for (let i: number = 0; i < scope.rows.length; i++) {
if (scope.rows[i].selected === true) {
numSelectedItems++;
}
}
expect(numSelectedItems).toEqual(0);
}));
});