Skip to content

Commit

Permalink
test(IgxSummary): add test that verify that can assess all grid data #…
Browse files Browse the repository at this point in the history
  • Loading branch information
ddincheva committed Oct 11, 2019
1 parent a7f1db4 commit 737caaa
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
50 changes: 50 additions & 0 deletions projects/igniteui-angular/src/lib/grids/grid/grid-summary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,37 @@ describe('IgxGrid - Summaries #grid', () => {
'summary cell and data cell are not right aligned');
}));

it('should be able to access alldata from each summary', fakeAsync(() => {
const fixture = TestBed.createComponent(CustomSummariesComponent);
const grid = fixture.componentInstance.grid1;
fixture.detectChanges();

const summaryRow = fixture.debugElement.query(By.css(SUMMARY_ROW));
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Sum', 'Avg'], ['10', '39,004', '3,900.4']);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4, ['Earliest'], ['5/17/1990']);
GridSummaryFunctions.verifyVisibleSummariesHeight(fixture, 3, grid.defaultSummaryHeight);
grid.getColumnByName('UnitsInStock').summaries = fixture.componentInstance.inStockSummary;
tick(100);
fixture.detectChanges();

GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'],
['10', '0', '20,000', '39,004', '3,900.4', '6']);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 4, ['Earliest'], ['5/17/1990']);

grid.getCellByColumn(4, 'InStock').update(true);
tick();
fixture.detectChanges();

GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'],
['10', '0', '20,000', '39,004', '3,900.4', '7']);

grid.filter('UnitsInStock', 0, IgxNumberFilteringOperand.instance().condition('equals'));
fixture.detectChanges();

GridSummaryFunctions.verifyColumnSummaries(summaryRow, 3, ['Count', 'Min', 'Max', 'Sum', 'Avg', 'Items InStock'],
['3', '0', '0', '0', '0', '1']);
}));

describe('', () => {
let fix;
let grid: IgxGridComponent;
Expand Down Expand Up @@ -2441,6 +2472,24 @@ class EarliestSummary extends IgxDateSummaryOperand {
}
}

class InStockSummary extends IgxNumberSummaryOperand {
constructor() {
super();
}

public operate(summaries?: any[], allData = [], field?): IgxSummaryResult[] {
const result = super.operate(summaries);
if (field && field === 'UnitsInStock') {
result.push({
key: 'test',
label: 'Items InStock',
summaryResult: allData.filter((rec) => rec.InStock).length
});
}
return result;
}
}

@Component({
template: `
<igx-grid #grid1 [data]="data" [primaryKey]="'ProductID'" [allowFiltering]="true">
Expand All @@ -2466,6 +2515,7 @@ export class CustomSummariesComponent {
public dealsSummary = DealsSummary;
public dealsSummaryMinMax = DealsSummaryMinMax;
public earliest = EarliestSummary;
public inStockSummary = InStockSummary;
}

@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,44 @@ describe('IgxTreeGrid - Summaries #tGrid', () => {
verifySummaryForRow847(fix, 6);
}));

it('should be able to access alldata from each summary', fakeAsync(() => {
const fix = TestBed.createComponent(IgxTreeGridCustomSummariesComponent);
fix.detectChanges();
const treeGrid = fix.componentInstance.treeGrid;

treeGrid.expandAll();
fix.detectChanges();

let summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['2']);
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['3']);
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count'], ['4']);

treeGrid.getColumnByName('Name').summaries = fix.componentInstance.ptoSummary;
tick();
fix.detectChanges();

summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['2', '1']);
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['3', '1']);
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['4', '0']);

treeGrid.getCellByColumn(5, 'OnPTO').update(true);
tick();
fix.detectChanges();

summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 6);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['2', '2']);
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 7);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['3', '1']);
summaryRow = GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, 0);
GridSummaryFunctions.verifyColumnSummaries(summaryRow, 1, ['Count', 'People on PTO'], ['4', '0']);
}));

it('should render rows correctly after collapse and expand', async () => {
const fix = TestBed.createComponent(IgxTreeGridSummariesScrollingComponent);
const treeGrid = fix.componentInstance.treeGrid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, ViewChild, OnInit } from '@angular/core';
import { IgxTreeGridComponent } from '../grids/tree-grid/tree-grid.component';
import { SampleTestData } from './sample-test-data.spec';
import { IgxNumberSummaryOperand, IgxSummaryResult } from '../grids';
import { IgxSummaryOperand, IgxNumberSummaryOperand, IgxSummaryResult } from '../grids';
import { IgxGridTransaction } from '../grids/grid-base.component';
import { IgxTransactionService } from '../services/transaction/igx-transaction';
import { IgxHierarchicalTransactionService } from '../services/transaction/igx-hierarchical-transaction';
Expand Down Expand Up @@ -400,6 +400,24 @@ class AgeSummaryTest extends IgxNumberSummaryOperand {
}
}

class PTOSummary extends IgxSummaryOperand {
constructor() {
super();
}

public operate(summaries?: any[], allData = [], field?): IgxSummaryResult[] {
const result = super.operate(summaries);
if (field && field === 'Name') {
result.push({
key: 'test',
label: 'People on PTO',
summaryResult: allData.filter((rec) => rec.OnPTO).length
});
}
return result;
}
}

@Component({
template: `
<igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID" [rowEditable]="true" width="900px" height="600px">
Expand Down Expand Up @@ -433,6 +451,7 @@ export class IgxTreeGridCustomSummariesComponent {
public data = SampleTestData.employeeTreeData();
public ageSummary = AgeSummary;
public ageSummaryTest = AgeSummaryTest;
public ptoSummary = PTOSummary;
}

@Component({
Expand Down

0 comments on commit 737caaa

Please sign in to comment.