Skip to content

Commit 737caaa

Browse files
committed
test(IgxSummary): add test that verify that can assess all grid data #5754
1 parent a7f1db4 commit 737caaa

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

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

+50
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,37 @@ describe('IgxGrid - Summaries #grid', () => {
287287
'summary cell and data cell are not right aligned');
288288
}));
289289

290+
it('should be able to access alldata from each summary', fakeAsync(() => {
291+
const fixture = TestBed.createComponent(CustomSummariesComponent);
292+
const grid = fixture.componentInstance.grid1;
293+
fixture.detectChanges();
294+
295+
const summaryRow = fixture.debugElement.query(By.css(SUMMARY_ROW));
296+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Sum', 'Avg'], ['10', '39,004', '3,900.4']);
297+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4, ['Earliest'], ['5/17/1990']);
298+
GridSummaryFunctions.verifyVisibleSummariesHeight(fixture, 3, grid.defaultSummaryHeight);
299+
grid.getColumnByName('UnitsInStock').summaries = fixture.componentInstance.inStockSummary;
300+
tick(100);
301+
fixture.detectChanges();
302+
303+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'],
304+
['10', '0', '20,000', '39,004', '3,900.4', '6']);
305+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4, ['Earliest'], ['5/17/1990']);
306+
307+
grid.getCellByColumn(4, 'InStock').update(true);
308+
tick();
309+
fixture.detectChanges();
310+
311+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'],
312+
['10', '0', '20,000', '39,004', '3,900.4', '7']);
313+
314+
grid.filter('UnitsInStock', 0, IgxNumberFilteringOperand.instance().condition('equals'));
315+
fixture.detectChanges();
316+
317+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'],
318+
['3', '0', '0', '0', '0', '1']);
319+
}));
320+
290321
describe('', () => {
291322
let fix;
292323
let grid: IgxGridComponent;
@@ -2441,6 +2472,24 @@ class EarliestSummary extends IgxDateSummaryOperand {
24412472
}
24422473
}
24432474

2475+
class InStockSummary extends IgxNumberSummaryOperand {
2476+
constructor() {
2477+
super();
2478+
}
2479+
2480+
public operate(summaries?: any[], allData = [], field?): IgxSummaryResult[] {
2481+
const result = super.operate(summaries);
2482+
if (field && field === 'UnitsInStock') {
2483+
result.push({
2484+
key: 'test',
2485+
label: 'Items InStock',
2486+
summaryResult: allData.filter((rec) => rec.InStock).length
2487+
});
2488+
}
2489+
return result;
2490+
}
2491+
}
2492+
24442493
@Component({
24452494
template: `
24462495
<igx-grid #grid1 [data]="data" [primaryKey]="'ProductID'" [allowFiltering]="true">
@@ -2466,6 +2515,7 @@ export class CustomSummariesComponent {
24662515
public dealsSummary = DealsSummary;
24672516
public dealsSummaryMinMax = DealsSummaryMinMax;
24682517
public earliest = EarliestSummary;
2518+
public inStockSummary = InStockSummary;
24692519
}
24702520

24712521
@Component({

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

+38
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,44 @@ describe('IgxTreeGrid - Summaries #tGrid', () => {
16091609
verifySummaryForRow847(fix, 6);
16101610
}));
16111611

1612+
it('should be able to access alldata from each summary', fakeAsync(() => {
1613+
const fix = TestBed.createComponent(IgxTreeGridCustomSummariesComponent);
1614+
fix.detectChanges();
1615+
const treeGrid = fix.componentInstance.treeGrid;
1616+
1617+
treeGrid.expandAll();
1618+
fix.detectChanges();
1619+
1620+
let summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6);
1621+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['2']);
1622+
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7);
1623+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['3']);
1624+
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0);
1625+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['4']);
1626+
1627+
treeGrid.getColumnByName('Name').summaries = fix.componentInstance.ptoSummary;
1628+
tick();
1629+
fix.detectChanges();
1630+
1631+
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6);
1632+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['2', '1']);
1633+
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7);
1634+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['3', '1']);
1635+
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0);
1636+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['4', '0']);
1637+
1638+
treeGrid.getCellByColumn(5, 'OnPTO').update(true);
1639+
tick();
1640+
fix.detectChanges();
1641+
1642+
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6);
1643+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['2', '2']);
1644+
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7);
1645+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['3', '1']);
1646+
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0);
1647+
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['4', '0']);
1648+
}));
1649+
16121650
it('should render rows correctly after collapse and expand', async () => {
16131651
const fix = TestBed.createComponent(IgxTreeGridSummariesScrollingComponent);
16141652
const treeGrid = fix.componentInstance.treeGrid;

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, ViewChild, OnInit } from '@angular/core';
22
import { IgxTreeGridComponent } from '../grids/tree-grid/tree-grid.component';
33
import { SampleTestData } from './sample-test-data.spec';
4-
import { IgxNumberSummaryOperand, IgxSummaryResult } from '../grids';
4+
import { IgxSummaryOperand, IgxNumberSummaryOperand, IgxSummaryResult } from '../grids';
55
import { IgxGridTransaction } from '../grids/grid-base.component';
66
import { IgxTransactionService } from '../services/transaction/igx-transaction';
77
import { IgxHierarchicalTransactionService } from '../services/transaction/igx-hierarchical-transaction';
@@ -400,6 +400,24 @@ class AgeSummaryTest extends IgxNumberSummaryOperand {
400400
}
401401
}
402402

403+
class PTOSummary extends IgxSummaryOperand {
404+
constructor() {
405+
super();
406+
}
407+
408+
public operate(summaries?: any[], allData = [], field?): IgxSummaryResult[] {
409+
const result = super.operate(summaries);
410+
if (field && field === 'Name') {
411+
result.push({
412+
key: 'test',
413+
label: 'People on PTO',
414+
summaryResult: allData.filter((rec) => rec.OnPTO).length
415+
});
416+
}
417+
return result;
418+
}
419+
}
420+
403421
@Component({
404422
template: `
405423
<igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID" [rowEditable]="true" width="900px" height="600px">
@@ -433,6 +451,7 @@ export class IgxTreeGridCustomSummariesComponent {
433451
public data = SampleTestData.employeeTreeData();
434452
public ageSummary = AgeSummary;
435453
public ageSummaryTest = AgeSummaryTest;
454+
public ptoSummary = PTOSummary;
436455
}
437456

438457
@Component({

0 commit comments

Comments
 (0)