Skip to content

Commit f13e67c

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Add value API tests.
1 parent bd2fb16 commit f13e67c

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11771177
}
11781178
this.setupColumns();
11791179
this.pipeTrigger++;
1180+
this.cdr.detectChanges();
11801181
this.valuesChange.emit({ values });
11811182
}
11821183

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PivotDimensionType } from './pivot-grid.interface';
1212
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component';
1313
import { IgxPivotDateDimension, IgxPivotGridModule } from './public_api';
1414
import { IgxPivotRowDimensionHeaderComponent } from './pivot-row-dimension-header.component';
15+
import { IgxPivotDateAggregate } from './pivot-grid-aggregate';
1516
const CSS_CLASS_DROP_DOWN_BASE = 'igx-drop-down';
1617
const CSS_CLASS_LIST = 'igx-drop-down__list';
1718
const CSS_CLASS_ITEM = 'igx-drop-down__item';
@@ -1241,7 +1242,7 @@ describe('IgxPivotGrid Resizing #pivotGrid', () => {
12411242
}));
12421243
});
12431244

1244-
fdescribe('IgxPivotGrid APIs #pivotGrid', () => {
1245+
describe('IgxPivotGrid APIs #pivotGrid', () => {
12451246
let fixture: ComponentFixture<any>;
12461247
let pivotGrid: IgxPivotGridComponent;
12471248

@@ -1433,4 +1434,71 @@ fdescribe('IgxPivotGrid APIs #pivotGrid', () => {
14331434
const first = rowHeaders.map(x => x.componentInstance.column.header)[0];
14341435
expect(first).toBe('All Cities');
14351436
});
1437+
1438+
it('should allow inserting new value at index.', () => {
1439+
const value = {
1440+
member: 'Date',
1441+
aggregate: {
1442+
aggregator: IgxPivotDateAggregate.latest,
1443+
key: 'LATEST',
1444+
label: 'Latest'
1445+
},
1446+
enabled: true
1447+
};
1448+
pivotGrid.insertValueAt(value, 1);
1449+
fixture.detectChanges();
1450+
expect(pivotGrid.values.length).toBe(3);
1451+
expect(pivotGrid.values[1].member).toBe('Date');
1452+
expect(pivotGrid.columns.length).toBe(20);
1453+
});
1454+
1455+
it('should allow removing value.', () => {
1456+
pivotGrid.removeValue(pivotGrid.values[1]);
1457+
fixture.detectChanges();
1458+
expect(pivotGrid.pivotConfiguration.values.length).toBe(1);
1459+
expect(pivotGrid.values[0].member).toBe('UnitsSold');
1460+
expect(pivotGrid.columns.length).toBe(5);
1461+
});
1462+
1463+
it('should allow toggling value.', () => {
1464+
// toggle off
1465+
pivotGrid.toggleValue(pivotGrid.pivotConfiguration.values[1]);
1466+
fixture.detectChanges();
1467+
expect(pivotGrid.pivotConfiguration.values.length).toBe(2);
1468+
expect(pivotGrid.values.length).toBe(1);
1469+
expect(pivotGrid.values[0].member).toBe('UnitsSold');
1470+
expect(pivotGrid.columns.length).toBe(5);
1471+
// toggle on
1472+
pivotGrid.toggleValue(pivotGrid.pivotConfiguration.values[1]);
1473+
fixture.detectChanges();
1474+
expect(pivotGrid.pivotConfiguration.values.length).toBe(2);
1475+
expect(pivotGrid.values.length).toBe(2);
1476+
expect(pivotGrid.values[0].member).toBe('UnitsSold');
1477+
expect(pivotGrid.values[1].member).toBe('AmountOfSale');
1478+
expect(pivotGrid.columns.length).toBe(15);
1479+
});
1480+
1481+
it('should allow moving value.', () => {
1482+
const val = pivotGrid.pivotConfiguration.values[0];
1483+
// move after
1484+
pivotGrid.moveValue(val, 1);
1485+
fixture.detectChanges();
1486+
1487+
expect(pivotGrid.values[0].member).toBe('AmountOfSale');
1488+
expect(pivotGrid.values[1].member).toBe('UnitsSold');
1489+
1490+
let valueCols = pivotGrid.columns.filter(x => x.level === 1);
1491+
expect(valueCols[0].header).toBe('Amount of Sale');
1492+
expect(valueCols[1].header).toBe('UnitsSold');
1493+
1494+
// move before
1495+
pivotGrid.moveValue(val, 0);
1496+
fixture.detectChanges();
1497+
1498+
expect(pivotGrid.values[0].member).toBe('UnitsSold');
1499+
expect(pivotGrid.values[1].member).toBe('AmountOfSale');
1500+
valueCols = pivotGrid.columns.filter(x => x.level === 1);
1501+
expect(valueCols[0].header).toBe('UnitsSold');
1502+
expect(valueCols[1].header).toBe('Amount of Sale');
1503+
});
14361504
});

0 commit comments

Comments
 (0)