Skip to content

Commit bbed683

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Adding basic API tests.
1 parent 0ce0048 commit bbed683

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid.master-detail.spec.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,77 @@ describe('IgxGrid Master Detail', () => {
5757
expect(firstRowIcon.innerText).toEqual(EXPANDED_ICON_NAME);
5858
expect(firstRowDetail.querySelector('.addressArea').innerText).toEqual('Obere Str. 57');
5959
}));
60+
61+
it('Should expand and collapse a row in view by using the expand(rowID) and collapse(rowID) methods.', () => {
62+
grid.expand(fix.componentInstance.data[0].ID);
63+
fix.detectChanges();
64+
let firstRowIcon = grid.rowList.first.element.nativeElement.querySelector('igx-icon');
65+
expect(grid.expansionStates.size).toEqual(1);
66+
expect(grid.expansionStates.has(grid.rowList.first.rowID)).toBeTruthy();
67+
expect(grid.rowList.toArray()[0].expanded).toBeTruthy();
68+
expect(firstRowIcon.innerText).toEqual(EXPANDED_ICON_NAME);
69+
grid.collapse(fix.componentInstance.data[0].ID);
70+
fix.detectChanges();
71+
firstRowIcon = grid.rowList.first.element.nativeElement.querySelector('igx-icon');
72+
expect(grid.expansionStates.get(fix.componentInstance.data[0].ID)).toBeFalsy();
73+
expect(grid.rowList.toArray()[0].expanded).toBeFalsy();
74+
expect(firstRowIcon.innerText).toEqual(COLLAPSED_ICON_NAME);
75+
});
76+
77+
it('Should expand a row out of view by using the collapse() method and update expansionStates.', () => {
78+
const lastIndex = fix.componentInstance.data.length - 1;
79+
const lastDataRecID = fix.componentInstance.data[lastIndex].ID;
80+
grid.expand(lastDataRecID);
81+
fix.detectChanges();
82+
expect(grid.expansionStates.size).toEqual(1);
83+
expect(grid.expansionStates.get(lastDataRecID)).toBeTruthy();
84+
});
85+
86+
it('Should collapse a row out of view by using the collapse() method and update expansionStates.', () => {
87+
GridFunctions.setAllExpanded(grid, fix.componentInstance.data);
88+
fix.detectChanges();
89+
const lastIndex = fix.componentInstance.data.length - 1;
90+
const lastDataRecID = fix.componentInstance.data[lastIndex].ID;
91+
grid.collapse(lastDataRecID);
92+
fix.detectChanges();
93+
expect(grid.expansionStates.size).toEqual(fix.componentInstance.data.length);
94+
expect(grid.expansionStates.get(lastDataRecID)).toBeFalsy();
95+
});
96+
97+
it('Should toggle a row expand state by using the toggleRow(rowID) method.', () => {
98+
grid.toggleRow(fix.componentInstance.data[0].ID);
99+
fix.detectChanges();
100+
expect(grid.expansionStates.size).toEqual(1);
101+
expect(grid.expansionStates.has(grid.rowList.first.rowID)).toBeTruthy();
102+
expect(grid.rowList.toArray()[0].expanded).toBeTruthy();
103+
grid.toggleRow(fix.componentInstance.data[0].ID);
104+
fix.detectChanges();
105+
expect(grid.expansionStates.get(fix.componentInstance.data[0].ID)).toBeFalsy();
106+
expect(grid.rowList.toArray()[0].expanded).toBeFalsy();
107+
});
108+
109+
it('Should expand all rows using the expandAll() method and the expansion state should be updated.', () => {
110+
grid.expandAll();
111+
fix.detectChanges();
112+
expect(grid.expansionStates.size).toEqual(fix.componentInstance.data.length);
113+
grid.rowList.toArray().forEach(row => {
114+
expect(row.expanded).toBeTruthy();
115+
});
116+
});
117+
118+
it('Should collapse all rows using the collapseAll() method and the expansion state should be updated.', () => {
119+
GridFunctions.setAllExpanded(grid, fix.componentInstance.data);
120+
fix.detectChanges();
121+
grid.rowList.toArray().forEach(row => {
122+
expect(row.expanded).toBeTruthy();
123+
});
124+
grid.collapseAll();
125+
fix.detectChanges();
126+
expect(grid.expansionStates.size).toEqual(0);
127+
grid.rowList.toArray().forEach(row => {
128+
expect(row.expanded).toBeFalsy();
129+
});
130+
});
60131
});
61132
});
62133

projects/igniteui-angular/src/lib/test-utils/grid-functions.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ export class GridFunctions {
163163
return null;
164164
}
165165

166+
public static setAllExpanded(grid, data) {
167+
const allExpanded = new Map<any, boolean>();
168+
data.forEach(item => {
169+
allExpanded.set(item['ID'], true);
170+
});
171+
grid.expansionStates = allExpanded;
172+
}
173+
166174
public static expandMasterRowByClick = (fix, row: IgxGridRowComponent) => new Promise(async (resolve, reject) => {
167175
const icon = row.element.nativeElement.querySelector('igx-icon');
168176
UIInteractions.clickElement(icon.parentElement);

0 commit comments

Comments
 (0)