Skip to content

Commit 3a35605

Browse files
committed
chore(*): fixing tests, better code approach
1 parent d3e2fe0 commit 3a35605

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

projects/igniteui-angular/src/lib/grids/api.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
443443

444444
public get_all_data(includeTransactions = false): any[] {
445445
const grid = this.grid;
446-
let data = grid.data ? grid.data : [];
446+
let data = grid && grid.data ? grid.data : [];
447447
data = includeTransactions ? grid.dataWithAddedInTransactionRows : data;
448448
return data;
449449
}

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6490,22 +6490,33 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
64906490
* @hidden @internal
64916491
*/
64926492
public get template(): TemplateRef<any> {
6493-
const hasZeroResultFilter = this.filteredData && this.filteredData.length === 0;
6494-
const hasNoData = !this.data || this.dataLength === 0;
6495-
6496-
if (this.isLoading && (hasZeroResultFilter || hasNoData)) {
6493+
if (this.isLoading && (this.hasZeroResultFilter || this.hasNoData)) {
64976494
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
64986495
}
64996496

6500-
if (hasZeroResultFilter) {
6497+
if (this.hasZeroResultFilter) {
65016498
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
65026499
}
65036500

6504-
if (hasNoData) {
6501+
if (this.hasNoData) {
65056502
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
65066503
}
65076504
}
65086505

6506+
/**
6507+
* @hidden @internal
6508+
*/
6509+
private get hasZeroResultFilter(): boolean {
6510+
return this.filteredData && this.filteredData.length === 0;
6511+
}
6512+
6513+
/**
6514+
* @hidden @internal
6515+
*/
6516+
private get hasNoData(): boolean {
6517+
return !this.data || this.dataLength === 0;
6518+
}
6519+
65096520
/**
65106521
* @hidden @internal
65116522
*/
@@ -6544,7 +6555,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
65446555
* @hidden @internal
65456556
*/
65466557
get shouldOverlayLoading(): boolean {
6547-
return this.isLoading && this.data && this.data.length > 0;
6558+
return this.isLoading && !this.hasNoData && !this.hasZeroResultFilter;
65486559
}
65496560

65506561
/**

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { IgxTabsModule, IgxTabsComponent } from '../../tabs/public_api';
2424
import { GridSelectionMode } from '../common/enums';
2525
import { registerLocaleData } from '@angular/common';
2626
import localeDE from '@angular/common/locales/de';
27+
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
28+
import { FilteringLogic } from '../../data-operations/filtering-expression.interface';
2729

2830
describe('IgxGrid Component Tests #grid', () => {
2931
const MIN_COL_WIDTH = '136px';
@@ -346,7 +348,7 @@ describe('IgxGrid Component Tests #grid', () => {
346348
grid.filter(columns[0].field, 546000, IgxNumberFilteringOperand.instance().condition('equals'));
347349
fixture.detectChanges();
348350
tick(100);
349-
expect(gridBody.nativeElement.textContent).toEqual(grid.emptyFilteredGridMessage);
351+
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
350352
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(548);
351353

352354
// Clear filter and check if grid's body height is restored based on all loaded rows
@@ -398,7 +400,7 @@ describe('IgxGrid Component Tests #grid', () => {
398400
grid.filter(columns[0].field, 546000, IgxNumberFilteringOperand.instance().condition('equals'));
399401
fixture.detectChanges();
400402
tick(100);
401-
expect(gridBody.nativeElement.textContent).toEqual(grid.emptyFilteredGridMessage);
403+
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
402404

403405
// Clear filter and check if grid's body height is restored based on all loaded rows
404406
grid.clearFilter(columns[0].field);
@@ -485,7 +487,14 @@ describe('IgxGrid Component Tests #grid', () => {
485487
it('should render loading indicator when loading is enabled and the grid has empty filtering pre-applied', fakeAsync(() => {
486488
const fixture = TestBed.createComponent(IgxGridTestComponent);
487489
const grid = fixture.componentInstance.grid;
488-
grid.filter('index', 0, IgxNumberFilteringOperand.instance().condition('equals'), true);
490+
grid.filteringExpressionsTree = new FilteringExpressionsTree(FilteringLogic.And);
491+
grid.filteringExpressionsTree.filteringOperands = [
492+
{
493+
condition: IgxNumberFilteringOperand.instance().condition('equals'),
494+
fieldName: 'index',
495+
searchVal: 0
496+
}
497+
];
489498
grid.isLoading = true;
490499
fixture.detectChanges();
491500
tick(16);

0 commit comments

Comments
 (0)