From d485d5c71d3d788fdcb06fcd3b7b2b5cf40f1786 Mon Sep 17 00:00:00 2001 From: NikolayAlipiev Date: Thu, 1 Aug 2019 18:12:15 +0300 Subject: [PATCH] test(grid): initial test spec file #4998 --- .../grid/grid-row-custom-selectors.spec.ts | 253 ++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 projects/igniteui-angular/src/lib/grids/grid/grid-row-custom-selectors.spec.ts diff --git a/projects/igniteui-angular/src/lib/grids/grid/grid-row-custom-selectors.spec.ts b/projects/igniteui-angular/src/lib/grids/grid/grid-row-custom-selectors.spec.ts new file mode 100644 index 00000000000..1230327fea4 --- /dev/null +++ b/projects/igniteui-angular/src/lib/grids/grid/grid-row-custom-selectors.spec.ts @@ -0,0 +1,253 @@ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { async, TestBed } from '@angular/core/testing'; +import { Calendar } from '../../calendar'; +import { IgxGridComponent } from './grid.component'; +import { IgxGridModule, IgxColumnComponent } from './index'; +import { SampleTestData } from '../../test-utils/sample-test-data.spec'; +import { IgxHierarchicalGridMultiLayoutComponent } from '../hierarchical-grid/hierarchical-grid.spec'; +import { IgxHierarchicalGridModule } from '../hierarchical-grid/hierarchical-grid.module'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { configureTestSuite } from '../../test-utils/configure-suite'; + +describe('IgxGrid - Custom Row Selectors', () => { + configureTestSuite(); + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + GridWithPagingAndSelectionComponent, + GridWithSelectionFilteringComponent, + GridSummaryComponent, + GridCancelableComponent, + GridFeaturesComponent, + HierarchicalGridRowSelectableIslandComponent + ], + imports: [ + NoopAnimationsModule, + IgxGridModule, + IgxHierarchicalGridModule + ] + }) + .compileComponents(); + })); + + + // Events + it('Firing onRowSelectionChange event', () => { }); + it('Canceling onRowSelectionChange event', () => { }); + it('Firing onHeaderSelectionChange event???', () => { }); + it('Canceling onHeaderSelectionChange event???', () => { }); + + // Testing with different row selector templates + it('Row selector template and header selector template with different sizes', () => { }); + + // API + it('', () => { }); + + // Feature integration + it('Pinned columns', () => { }); + it('Multi-column headers', () => { }); + it('Multi-row layout', () => { }); + + // Aplication scenario test + it('Conditional row selectors', () => { }); + + it('', + () => { + // fakeAsync(() => { + // async () => { + const fix = TestBed.createComponent(GridWithPagingAndSelectionComponent); + fix.detectChanges(); + const grid = fix.componentInstance.gridSelection2; + expect(true).toBeTruthy(); + expect(10).toEqual(10, '10'); + const checkboxElement1: HTMLElement = grid.getRowByIndex(5).nativeElement.querySelector('.igx-checkbox__input'); + + spyOn(grid, 'triggerRowSelectionChange').and.callThrough(); + spyOn(grid.onRowSelectionChange, 'emit').and.callThrough(); + expect(grid.triggerRowSelectionChange).toHaveBeenCalledTimes(0); + expect(grid.onRowSelectionChange.emit).toHaveBeenCalledTimes(0); + + }); + +}); + +@Component({ + template: ` + + + + + ` +}) +export class GridWithPagingAndSelectionComponent implements OnInit { + public data = []; + + @ViewChild('gridSelection2', { read: IgxGridComponent, static: true }) + public gridSelection2: IgxGridComponent; + + ngOnInit() { + const bigData = []; + for (let i = 0; i < 100; i++) { + for (let j = 0; j < 5; j++) { + bigData.push({ + ID: i.toString() + '_' + j.toString(), + Column1: i * j, + Column2: i * j * Math.pow(10, i), + Column3: i * j * Math.pow(100, i) + }); + } + } + this.data = bigData; + } + + public ChangePage(val) { + switch (val) { + case -1: + this.gridSelection2.previousPage(); + break; + case 1: + this.gridSelection2.nextPage(); + break; + default: + this.gridSelection2.paginate(val); + break; + } + } +} + +@Component({ + template: ` + + + + + + + + ` +}) +export class GridWithSelectionFilteringComponent { + + public timeGenerator: Calendar = new Calendar(); + public today: Date = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 0, 0); + + @ViewChild('gridSelection4', { read: IgxGridComponent, static: true }) + public gridSelection4: IgxGridComponent; + + public data = SampleTestData.productInfoData(); + + @ViewChild(IgxGridComponent, { static: true }) public grid: IgxGridComponent; +} + + + +@Component({ + template: ` + + + + + + + + + + + + + ` +}) +export class GridSummaryComponent { + public data = SampleTestData.foodProductData(); + @ViewChild('grid1', { read: IgxGridComponent, static: true }) + public gridSummaries: IgxGridComponent; +} + +@Component({ + template: ` + + + + + + + + + + + + + ` +}) +export class GridCancelableComponent { + public data = SampleTestData.foodProductData(); + @ViewChild('gridCancelable', { read: IgxGridComponent, static: true }) + public gridCancelable: IgxGridComponent; + + public cancelClick(evt) { + if (evt.row && (evt.row.index + 1) % 2 === 0) { + evt.newSelection = evt.oldSelection || []; + } + } +} + +@Component({ + template: ` + + + ` +}) +export class GridFeaturesComponent { + + @ViewChild('grid1', { read: IgxGridComponent, static: true }) public grid: IgxGridComponent; + public data = [ + { + Name: 'Alice', + Age: 25 + }, + { + Name: 'Bob', + Age: 23 + } + ]; + + public initColumns(column: IgxColumnComponent) { + column.filterable = true; + column.sortable = true; + column.editable = true; + column.resizable = true; + } +} + +@Component({ + template: ` + + + + + + + + + + + + + ` +}) +export class HierarchicalGridRowSelectableIslandComponent extends IgxHierarchicalGridMultiLayoutComponent { }