Skip to content

Commit da9d1b7

Browse files
prx-lmomportuga
authored andcommitted
[feature/4850]
- added tests for get getUnSelectedRows, getUnSelectedGridRows and getSelectedGridRows
1 parent e17ceb0 commit da9d1b7

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

packages/selection/test/uiGridSelectionService.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ describe('ui.grid.selection uiGridSelectionService', function() {
123123
it('should utilize public apis', function() {
124124
grid.api.selection.toggleRowSelection(grid.rows[0].entity);
125125
expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(1);
126+
expect(uiGridSelectionService.getUnSelectedRows(grid).length).toBe(9);
126127
grid.api.selection.clearSelectedRows();
127128
expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(0);
129+
expect(uiGridSelectionService.getUnSelectedRows(grid).length).toBe(10);
128130
});
129131
});
130132

@@ -368,6 +370,11 @@ describe('ui.grid.selection uiGridSelectionService', function() {
368370
});
369371

370372
describe('getSelectedRows function', function() {
373+
it('should retrieve empty array if nothing selected', function() {
374+
expect(grid.api.selection.getSelectedRows().length).toBe(0);
375+
expect(grid.api.selection.getSelectedGridRows().length).toBe(0);
376+
});
377+
371378
it('should retrieve the selected rows that have a $$hashKey property', function() {
372379
grid.rows.forEach(function(row) {
373380
row.isSelected = false;
@@ -387,6 +394,56 @@ describe('ui.grid.selection uiGridSelectionService', function() {
387394
};
388395

389396
expect(grid.api.selection.getSelectedRows().length).toEqual(2);
397+
expect(grid.api.selection.getSelectedGridRows().length).toEqual(2);
398+
});
399+
400+
it('should retrieve correct data', function() {
401+
grid.rows[0].isSelected = true;
402+
grid.rows[0].entity = {
403+
$$hashKey: '1234'
404+
};
405+
406+
expect(grid.api.selection.getSelectedRows()[0].$$hashKey).toEqual('1234');
407+
expect(grid.api.selection.getSelectedGridRows()[0].entity).toEqual({
408+
$$hashKey: '1234'
409+
});
410+
});
411+
});
412+
413+
describe('getUnSelectedRows function', function() {
414+
it('should retrieve every row if nothing selected', function() {
415+
expect(grid.api.selection.getUnSelectedRows().length).toEqual(10);
416+
expect(grid.api.selection.getUnSelectedGridRows().length).toEqual(10);
417+
});
418+
419+
it('should retrieve the unselected rows that have a $$hashKey property', function() {
420+
grid.rows.forEach(function(row) {
421+
row.isSelected = false;
422+
row.entity = {
423+
$$hashKey: '1234'
424+
};
425+
});
426+
427+
grid.rows[0].isSelected = true;
428+
grid.rows[1].isSelected = true;
429+
grid.rows[2].isSelected = true;
430+
grid.rows[2].entity = {};
431+
grid.rows[3].entity = {};
432+
433+
expect(grid.api.selection.getUnSelectedRows().length).toEqual(8);
434+
expect(grid.api.selection.getUnSelectedGridRows().length).toEqual(7);
435+
});
436+
437+
it('should retrieve correct data', function() {
438+
grid.rows[0].isSelected = false;
439+
grid.rows[0].entity = {
440+
$$hashKey: '1234'
441+
};
442+
443+
expect(grid.api.selection.getUnSelectedRows()[0].$$hashKey).toEqual('1234');
444+
expect(grid.api.selection.getUnSelectedGridRows()[0].entity).toEqual({
445+
$$hashKey: '1234'
446+
});
390447
});
391448
});
392449

0 commit comments

Comments
 (0)