Skip to content

Commit dd6c06b

Browse files
HristoP96HristoP96
authored andcommitted
chore(*): additional changes
1 parent e5d8cc4 commit dd6c06b

File tree

2 files changed

+52
-102
lines changed

2 files changed

+52
-102
lines changed

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

Lines changed: 52 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ function getCurrentCellFromGrid(grid, rowIndex, cellIndex) {
2424
return gridCell;
2525
}
2626

27-
function getValueFromCellElement(cell) {
28-
return cell.nativeElement.textContent.trim();
29-
}
30-
31-
describe('IgxGrid - Grid Sorting #grid', () => {
27+
fdescribe('IgxGrid - Grid Sorting #grid', () => {
3228

3329
configureTestSuite();
3430
let fixture;
@@ -45,7 +41,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
4541
}).compileComponents();
4642
}));
4743

48-
beforeEach(async(() => {
44+
beforeEach(fakeAsync(() => {
4945
fixture = TestBed.createComponent(GridDeclaredColumnsComponent);
5046
fixture.detectChanges();
5147
grid = fixture.componentInstance.grid;
@@ -61,21 +57,16 @@ describe('IgxGrid - Grid Sorting #grid', () => {
6157

6258
fixture.detectChanges();
6359

64-
let expectedResult = 'ALex';
65-
expect(grid.getCellByColumn(0, currentColumn).value).toEqual(expectedResult);
66-
expectedResult = 'Smith';
67-
expect(grid.getCellByColumn(0, lastNameColumn).value).toEqual(expectedResult);
68-
expectedResult = 'Rick';
69-
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).toEqual(expectedResult);
70-
expectedResult = 'BRown';
71-
expect(grid.getCellByColumn(grid.data.length - 1, lastNameColumn).value).toEqual(expectedResult);
60+
expect(grid.getCellByColumn(0, currentColumn).value).toEqual('ALex');
61+
expect(grid.getCellByColumn(0, lastNameColumn).value).toEqual('Smith');
62+
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).toEqual('Rick');
63+
expect(grid.getCellByColumn(grid.data.length - 1, lastNameColumn).value).toEqual('BRown');
7264

7365
// Ignore case on sorting set to true
7466
grid.sort({ fieldName: currentColumn, dir: SortingDirection.Asc, ignoreCase: true });
7567
fixture.detectChanges();
7668

77-
expectedResult = 'ALex';
78-
expect(grid.getCellByColumn(0, currentColumn).value).toEqual(expectedResult);
69+
expect(grid.getCellByColumn(0, currentColumn).value).toEqual('ALex');
7970
});
8071

8172
it('Should sort grid descending by column name', () => {
@@ -84,31 +75,25 @@ describe('IgxGrid - Grid Sorting #grid', () => {
8475
grid.sort({ fieldName: currentColumn, dir: SortingDirection.Desc, ignoreCase: false });
8576
fixture.detectChanges();
8677

87-
let expectedResult = 'Rick';
8878

89-
expect(grid.getCellByColumn(0, currentColumn).value).toEqual(expectedResult);
90-
expectedResult = 'ALex';
91-
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).toEqual(expectedResult);
79+
expect(grid.getCellByColumn(0, currentColumn).value).toEqual('Rick');
80+
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).toEqual('ALex');
9281

9382
// Ignore case on sorting set to true
9483
grid.sort({ fieldName: currentColumn, dir: SortingDirection.Desc, ignoreCase: true });
9584
fixture.detectChanges();
9685

97-
expectedResult = 'Rick';
98-
expect(grid.getCellByColumn(0, currentColumn).value).toEqual(expectedResult);
99-
expectedResult = 'ALex';
100-
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).not.toEqual(expectedResult);
86+
expect(grid.getCellByColumn(0, currentColumn).value).toEqual('Rick');
87+
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).not.toEqual('ALex');
10188

10289
});
10390

10491
it('Should not sort grid when trying to sort by invalid column', () => {
10592
const invalidColumn = 'Age';
10693
grid.sort({ fieldName: invalidColumn, dir: SortingDirection.Desc, ignoreCase: false });
10794

108-
let expectedResult = 'Jane';
109-
expect(grid.getCellByColumn(0, 'Name').value).toEqual(expectedResult);
110-
expectedResult = 'Connor';
111-
expect(grid.getCellByColumn(grid.data.length - 1, 'Name').value).toEqual(expectedResult);
95+
expect(grid.getCellByColumn(0, 'Name').value).toEqual('Jane');
96+
expect(grid.getCellByColumn(grid.data.length - 1, 'Name').value).toEqual('Connor');
11297
});
11398

11499
it('Should sort grid by current column by expression (Ascending)', () => {
@@ -133,8 +118,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
133118

134119
fixture.detectChanges();
135120

136-
const expectedResult = 'Alex';
137-
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).toEqual(expectedResult);
121+
expect(grid.getCellByColumn(grid.data.length - 1, currentColumn).value).toEqual('Alex');
138122
});
139123

140124
it('Should sort grid by multiple expressions and clear sorting through API', () => {
@@ -149,13 +133,10 @@ describe('IgxGrid - Grid Sorting #grid', () => {
149133

150134
fixture.detectChanges();
151135

152-
let expectedResult = 'ALex';
153-
expect(grid.getCellByColumn(0, secondColumn).value).toEqual(expectedResult);
154-
expectedResult = 'Rick';
155-
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual(expectedResult);
136+
expect(grid.getCellByColumn(0, secondColumn).value).toEqual('ALex');
137+
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual('Rick');
156138
expect(grid.getCellByColumn(grid.data.length - 1, firstColumn).value).toEqual(6);
157-
expectedResult = 'Jones';
158-
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual(expectedResult);
139+
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual('Jones');
159140

160141
// Clear sorting on a column
161142
grid.clearSort(firstColumn);
@@ -191,15 +172,11 @@ describe('IgxGrid - Grid Sorting #grid', () => {
191172
grid.sortingExpressions = exprs;
192173

193174
fixture.detectChanges();
194-
let expectedResult = 'ALex';
195-
expect(grid.getCellByColumn(0, secondColumn).value).toEqual(expectedResult);
196-
expectedResult = 'Smith';
197-
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual(expectedResult);
175+
expect(grid.getCellByColumn(0, secondColumn).value).toEqual('ALex');
176+
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual('Smith');
198177
expect(grid.getCellByColumn(0, firstColumn).value).toEqual(5);
199-
expectedResult = 'Rick';
200-
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual(expectedResult);
201-
expectedResult = 'BRown';
202-
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual(expectedResult);
178+
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual('Rick');
179+
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual('BRown');
203180
expect(grid.getCellByColumn(grid.data.length - 1, firstColumn).value).toEqual(7);
204181

205182
grid.clearSort();
@@ -210,15 +187,11 @@ describe('IgxGrid - Grid Sorting #grid', () => {
210187
grid.sort(exprs);
211188
fixture.detectChanges();
212189

213-
expectedResult = 'ALex';
214-
expect(grid.getCellByColumn(0, secondColumn).value).toEqual(expectedResult);
215-
expectedResult = 'Smith';
216-
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual(expectedResult);
190+
expect(grid.getCellByColumn(0, secondColumn).value).toEqual('ALex');
191+
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual('Smith');
217192
expect(grid.getCellByColumn(0, firstColumn).value).toEqual(5);
218-
expectedResult = 'Rick';
219-
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual(expectedResult);
220-
expectedResult = 'BRown';
221-
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual(expectedResult);
193+
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual('Rick');
194+
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual('BRown');
222195
expect(grid.getCellByColumn(grid.data.length - 1, firstColumn).value).toEqual(7);
223196
});
224197

@@ -237,15 +210,11 @@ describe('IgxGrid - Grid Sorting #grid', () => {
237210

238211
fixture.detectChanges();
239212

240-
let expectedResult = 'Rick';
241-
expect(grid.getCellByColumn(0, secondColumn).value).toEqual(expectedResult);
242-
expectedResult = 'Jones';
243-
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual(expectedResult);
213+
expect(grid.getCellByColumn(0, secondColumn).value).toEqual('Rick');
214+
expect(grid.getCellByColumn(0, thirdColumn).value).toEqual('Jones');
244215
expect(grid.getCellByColumn(0, firstColumn).value).toEqual(6);
245-
expectedResult = 'ALex';
246-
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual(expectedResult);
247-
expectedResult = 'Smith';
248-
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual(expectedResult);
216+
expect(grid.getCellByColumn(grid.data.length - 1, secondColumn).value).toEqual('ALex');
217+
expect(grid.getCellByColumn(grid.data.length - 1, thirdColumn).value).toEqual('Smith');
249218
expect(grid.getCellByColumn(grid.data.length - 1, firstColumn).value).toEqual(5);
250219
});
251220

@@ -277,28 +246,24 @@ describe('IgxGrid - Grid Sorting #grid', () => {
277246
describe('UI tests', () => {
278247

279248
it('Should sort grid ascending by clicking once on first header cell UI', () => {
280-
const firstHeaderCell = GridFunctions.getHeaderCellByIndex(fixture, 0);
249+
const firstHeaderCell = GridFunctions.getColumnHeader('ID', fixture);
281250

282251
GridFunctions.clickHeaderSortIcon(firstHeaderCell);
283252
fixture.detectChanges();
284253

285254
const firstRowFirstCell = getCurrentCellFromGrid(grid, 0, 0);
286255
const firstRowSecondCell = getCurrentCellFromGrid(grid, 0, 1);
287-
let expectedResult = 'Brad';
288-
expect(getValueFromCellElement(firstRowSecondCell)).toEqual(expectedResult);
289-
expectedResult = '1';
290-
expect(getValueFromCellElement(firstRowFirstCell)).toEqual(expectedResult);
256+
expect(GridFunctions.getValueFromCellElement(firstRowSecondCell)).toEqual('Brad');
257+
expect(GridFunctions.getValueFromCellElement(firstRowFirstCell)).toEqual('1');
291258

292259
const lastRowFirstCell = getCurrentCellFromGrid(grid, grid.data.length - 1, 0);
293260
const lastRowSecondCell = getCurrentCellFromGrid(grid, grid.data.length - 1, 1);
294-
expectedResult = (fixture.componentInstance.data.length).toString();
295-
expect(getValueFromCellElement(lastRowFirstCell)).toEqual(expectedResult);
296-
expectedResult = 'Rick';
297-
expect(getValueFromCellElement(lastRowSecondCell)).toEqual(expectedResult);
261+
expect(GridFunctions.getValueFromCellElement(lastRowFirstCell)).toEqual('7');
262+
expect(GridFunctions.getValueFromCellElement(lastRowSecondCell)).toEqual('Rick');
298263
});
299264

300265
it('Should sort grid descending by clicking twice on sort icon UI', () => {
301-
const firstHeaderCell = GridFunctions.getHeaderCellByIndex(fixture, 0);
266+
const firstHeaderCell = GridFunctions.getColumnHeader('ID', fixture);
302267

303268
GridFunctions.clickHeaderSortIcon(firstHeaderCell);
304269
fixture.detectChanges();
@@ -307,21 +272,17 @@ describe('IgxGrid - Grid Sorting #grid', () => {
307272

308273
const firstRowFirstCell = getCurrentCellFromGrid(grid, 0, 0);
309274
const firstRowSecondCell = getCurrentCellFromGrid(grid, 0, 1);
310-
let expectedResult = '7';
311-
expect(getValueFromCellElement(firstRowFirstCell)).toEqual(expectedResult);
312-
expectedResult = 'Rick';
313-
expect(getValueFromCellElement(firstRowSecondCell)).toEqual(expectedResult);
275+
expect(GridFunctions.getValueFromCellElement(firstRowFirstCell)).toEqual('7');
276+
expect(GridFunctions.getValueFromCellElement(firstRowSecondCell)).toEqual('Rick');
314277

315278
const lastRowFirstCell = getCurrentCellFromGrid(grid, grid.data.length - 1, 0);
316279
const lastRowSecondCell = getCurrentCellFromGrid(grid, grid.data.length - 1, 1);
317-
expectedResult = '1';
318-
expect(getValueFromCellElement(lastRowFirstCell)).toEqual(expectedResult);
319-
expectedResult = 'Brad';
320-
expect(getValueFromCellElement(lastRowSecondCell)).toEqual(expectedResult);
280+
expect(GridFunctions.getValueFromCellElement(lastRowFirstCell)).toEqual('1');
281+
expect(GridFunctions.getValueFromCellElement(lastRowSecondCell)).toEqual('Brad');
321282
});
322283

323284
it('Should sort grid none when we click three time on header sort icon UI', () => {
324-
const firstHeaderCell = GridFunctions.getHeaderCellByIndex(fixture, 0);
285+
const firstHeaderCell = GridFunctions.getColumnHeader('ID', fixture);
325286

326287
GridFunctions.clickHeaderSortIcon(firstHeaderCell);
327288
fixture.detectChanges();
@@ -331,17 +292,15 @@ describe('IgxGrid - Grid Sorting #grid', () => {
331292
fixture.detectChanges();
332293

333294
const firstRowSecondCell = getCurrentCellFromGrid(grid, 0, 1);
334-
let expectedResult = 'Jane';
335-
expect(getValueFromCellElement(firstRowSecondCell)).toEqual(expectedResult);
295+
expect(GridFunctions.getValueFromCellElement(firstRowSecondCell)).toEqual('Jane');
336296

337297
const lastRowSecondCell = getCurrentCellFromGrid(grid, grid.data.length - 1, 1);
338-
expectedResult = 'Connor';
339-
expect(getValueFromCellElement(lastRowSecondCell)).toEqual(expectedResult);
298+
expect(GridFunctions.getValueFromCellElement(lastRowSecondCell)).toEqual('Connor');
340299

341300
});
342301

343302
it('Should have a valid sorting icon when sorting using the API.', () => {
344-
const firstHeaderCell = GridFunctions.getHeaderCellByIndex(fixture, 0);
303+
const firstHeaderCell = GridFunctions.getColumnHeader('ID', fixture);
345304
const sortingIcon = GridFunctions.getHeaderSortIcon(firstHeaderCell);
346305

347306
expect(sortingIcon.nativeElement.textContent.trim()).toEqual(SORTING_ICON_ASC_CONTENT);
@@ -363,15 +322,10 @@ describe('IgxGrid - Grid Sorting #grid', () => {
363322
grid.allowFiltering = true;
364323
fixture.detectChanges();
365324

366-
const fistChip = ControlsFunction.getAllChipsFromAnElement(fixture.debugElement)[0];
367-
368-
UIInteractions.clickElement(fistChip);
369-
fixture.detectChanges();
370-
371-
const filteringRow = fixture.debugElement.query(By.directive(IgxGridFilteringRowComponent));
372-
expect(filteringRow).toBeDefined();
325+
GridFunctions.clickFilterCellChipUI(fixture, 'Name');
326+
expect(GridFunctions.getFilterRow(fixture)).toBeDefined();
373327

374-
const firstHeaderCell = GridFunctions.getHeaderCellByIndex(fixture, 0);
328+
const firstHeaderCell = GridFunctions.getColumnHeader('ID', fixture);
375329
UIInteractions.clickElement(firstHeaderCell);
376330

377331
expect(grid.headerGroups.toArray()[0].isFiltered).toBeTruthy();
@@ -386,7 +340,7 @@ describe('IgxGrid - Grid Sorting #grid', () => {
386340
expect(sortingIcon.nativeElement.textContent.trim()).toEqual(SORTING_ICON_DESC_CONTENT);
387341
expect(grid.getCellByColumn(0, 'ID').value).toEqual(7);
388342

389-
const secondHeaderCell = GridFunctions.getHeaderCellByIndex(fixture, 1);
343+
const secondHeaderCell = GridFunctions.getColumnHeader('Name', fixture);
390344
UIInteractions.clickElement(secondHeaderCell);
391345
fixture.detectChanges();
392346

@@ -397,22 +351,21 @@ describe('IgxGrid - Grid Sorting #grid', () => {
397351
grid.sortStrategy = NoopSortingStrategy.instance();
398352
fixture.detectChanges();
399353

400-
const gridData = fixture.componentInstance.data;
401-
const firstHeaderCell = GridFunctions.getHeaderCellByIndex(fixture, 0);
354+
const firstHeaderCell = GridFunctions.getColumnHeader('ID', fixture);
402355

403356
GridFunctions.clickHeaderSortIcon(firstHeaderCell);
404357
fixture.detectChanges();
405358

406359
// Verify that the grid is NOT sorted.
407-
expect(getValueFromCellElement(getCurrentCellFromGrid(grid, 0, 1))).toEqual('Jane');
408-
expect(getValueFromCellElement(getCurrentCellFromGrid(grid, grid.data.length - 1, 1))).toEqual('Connor');
360+
expect(GridFunctions.getValueFromCellElement(getCurrentCellFromGrid(grid, 0, 1))).toEqual('Jane');
361+
expect(GridFunctions.getValueFromCellElement(getCurrentCellFromGrid(grid, grid.data.length - 1, 1))).toEqual('Connor');
409362

410363
GridFunctions.clickHeaderSortIcon(firstHeaderCell);
411364
fixture.detectChanges();
412365

413366
// Verify that the grid is NOT sorted.
414-
expect(getValueFromCellElement(getCurrentCellFromGrid(grid, 0, 1))).toEqual('Jane');
415-
expect(getValueFromCellElement(getCurrentCellFromGrid(grid, grid.data.length - 1, 1))).toEqual('Connor');
367+
expect(GridFunctions.getValueFromCellElement(getCurrentCellFromGrid(grid, 0, 1))).toEqual('Jane');
368+
expect(GridFunctions.getValueFromCellElement(getCurrentCellFromGrid(grid, grid.data.length - 1, 1))).toEqual('Connor');
416369
});
417370
});
418371
});

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,9 +1814,6 @@ export class GridFunctions {
18141814
}
18151815
}
18161816

1817-
public static getHeaderCellByIndex(fix: ComponentFixture<any>, index: number) {
1818-
return fix.debugElement.queryAll(By.css('igx-grid-header'))[index];
1819-
}
18201817

18211818
public static getHeaderSortIcon(header: DebugElement): DebugElement {
18221819
return header.query(By.css(SORT_ICON_CLASS));

0 commit comments

Comments
 (0)