Skip to content

Commit f95d5bc

Browse files
committed
chore(*): fixing tests, better code approach
1 parent ba9a816 commit f95d5bc

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
@@ -471,7 +471,7 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
471471

472472
public get_all_data(includeTransactions = false): any[] {
473473
const grid = this.grid;
474-
let data = grid.data ? grid.data : [];
474+
let data = grid && grid.data ? grid.data : [];
475475
data = includeTransactions ? grid.dataWithAddedInTransactionRows : data;
476476
return data;
477477
}

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6771,22 +6771,33 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
67716771
* @hidden @internal
67726772
*/
67736773
public get template(): TemplateRef<any> {
6774-
const hasZeroResultFilter = this.filteredData && this.filteredData.length === 0;
6775-
const hasNoData = !this.data || this.dataLength === 0;
6776-
6777-
if (this.isLoading && (hasZeroResultFilter || hasNoData)) {
6774+
if (this.isLoading && (this.hasZeroResultFilter || this.hasNoData)) {
67786775
return this.loadingGridTemplate ? this.loadingGridTemplate : this.loadingGridDefaultTemplate;
67796776
}
67806777

6781-
if (hasZeroResultFilter) {
6778+
if (this.hasZeroResultFilter) {
67826779
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyFilteredGridTemplate;
67836780
}
67846781

6785-
if (hasNoData) {
6782+
if (this.hasNoData) {
67866783
return this.emptyGridTemplate ? this.emptyGridTemplate : this.emptyGridDefaultTemplate;
67876784
}
67886785
}
67896786

6787+
/**
6788+
* @hidden @internal
6789+
*/
6790+
private get hasZeroResultFilter(): boolean {
6791+
return this.filteredData && this.filteredData.length === 0;
6792+
}
6793+
6794+
/**
6795+
* @hidden @internal
6796+
*/
6797+
private get hasNoData(): boolean {
6798+
return !this.data || this.dataLength === 0;
6799+
}
6800+
67906801
/**
67916802
* @hidden @internal
67926803
*/
@@ -6825,7 +6836,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
68256836
* @hidden @internal
68266837
*/
68276838
get shouldOverlayLoading(): boolean {
6828-
return this.isLoading && this.data && this.data.length > 0;
6839+
return this.isLoading && !this.hasNoData && !this.hasZeroResultFilter;
68296840
}
68306841

68316842
/**

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

2931
describe('IgxGrid Component Tests #grid', () => {
@@ -347,7 +349,7 @@ describe('IgxGrid Component Tests #grid', () => {
347349
grid.filter(columns[0].field, 546000, IgxNumberFilteringOperand.instance().condition('equals'));
348350
fixture.detectChanges();
349351
tick(100);
350-
expect(gridBody.nativeElement.textContent).toEqual(grid.emptyFilteredGridMessage);
352+
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
351353
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(548);
352354

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

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

0 commit comments

Comments
 (0)