Skip to content

Commit f22404c

Browse files
committed
feat(combo): add tests for selection events, #5523
1 parent 9d55525 commit f22404c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,64 @@ describe('igxCombo', () => {
15761576
// onSelectionChange fires and overrides the selection to be [];
15771577
expect(combo.selectedItems()).toEqual([]);
15781578
}));
1579+
1580+
it('Should properly emit added and removed values in change event - single values', () => {
1581+
const fixture = TestBed.createComponent(IgxComboSampleComponent);
1582+
fixture.detectChanges();
1583+
const combo = fixture.componentInstance.combo;
1584+
const selectionSpy = spyOn(fixture.componentInstance, 'onSelectionChange');
1585+
const expectedResults = {
1586+
newSelection: [combo.data[0]],
1587+
oldSelection: [],
1588+
added: [combo.data[0]],
1589+
removed: [],
1590+
event: undefined,
1591+
cancel: false
1592+
};
1593+
combo.selectItems([combo.data[0]]);
1594+
expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
1595+
Object.assign(expectedResults, {
1596+
newSelection: [],
1597+
oldSelection: [combo.data[0]],
1598+
added: [],
1599+
removed: [combo.data[0]]
1600+
});
1601+
combo.deselectItems([combo.data[0]]);
1602+
expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
1603+
});
1604+
1605+
it('Should properly emit added and removed values in change event - multiple values', () => {
1606+
const fixture = TestBed.createComponent(IgxComboSampleComponent);
1607+
fixture.detectChanges();
1608+
const combo = fixture.componentInstance.combo;
1609+
const selectionSpy = spyOn(fixture.componentInstance, 'onSelectionChange');
1610+
const expectedResults = {
1611+
newSelection: [combo.data[0], combo.data[1], combo.data[2]],
1612+
oldSelection: [],
1613+
added: [combo.data[0], combo.data[1], combo.data[2]],
1614+
removed: [],
1615+
event: undefined,
1616+
cancel: false
1617+
};
1618+
combo.selectItems([combo.data[0], combo.data[1], combo.data[2]]);
1619+
expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
1620+
combo.deselectItems([combo.data[0]]);
1621+
Object.assign(expectedResults, {
1622+
newSelection: [combo.data[1], combo.data[2]],
1623+
oldSelection: [combo.data[0], combo.data[1], combo.data[2]],
1624+
added: [],
1625+
removed: [combo.data[0]]
1626+
});
1627+
expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
1628+
Object.assign(expectedResults, {
1629+
newSelection: [combo.data[4], combo.data[5], combo.data[6]],
1630+
oldSelection: [combo.data[1], combo.data[2]],
1631+
added: [combo.data[4], combo.data[5], combo.data[6]],
1632+
removed: [combo.data[1], combo.data[2]]
1633+
});
1634+
combo.selectItems([combo.data[4], combo.data[5], combo.data[6]], true);
1635+
expect(selectionSpy).toHaveBeenCalledWith(expectedResults);
1636+
});
15791637
});
15801638

15811639
describe('Rendering tests: ', () => {

0 commit comments

Comments
 (0)