|
| 1 | +import { async, TestBed, fakeAsync } from '@angular/core/testing'; |
| 2 | +import { IgxHierarchicalGridModule, IgxHierarchicalGridComponent } from './public_api'; |
| 3 | +import { configureTestSuite } from '../../test-utils/configure-suite'; |
| 4 | +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
| 5 | +import { IgxActionStripModule, IgxActionStripComponent } from '../../action-strip/public_api'; |
| 6 | +import { IgxHierarchicalGridActionStripComponent } from '../../test-utils/hierarchical-grid-components.spec'; |
| 7 | +import { wait } from '../../test-utils/ui-interactions.spec'; |
| 8 | + |
| 9 | +describe('IgxHierarchicalGrid - Add Row UI #tGrid', () => { |
| 10 | + configureTestSuite(); |
| 11 | + let fixture; |
| 12 | + let hierarchicalGrid: IgxHierarchicalGridComponent; |
| 13 | + let actionStrip: IgxActionStripComponent; |
| 14 | + beforeAll(async(() => { |
| 15 | + TestBed.configureTestingModule({ |
| 16 | + declarations: [ |
| 17 | + IgxHierarchicalGridActionStripComponent |
| 18 | + ], |
| 19 | + imports: [IgxHierarchicalGridModule, NoopAnimationsModule, IgxActionStripModule] |
| 20 | + }) |
| 21 | + .compileComponents(); |
| 22 | + })); |
| 23 | + |
| 24 | + describe(' Basic', () => { |
| 25 | + beforeEach(fakeAsync(/** height/width setter rAF */() => { |
| 26 | + fixture = TestBed.createComponent(IgxHierarchicalGridActionStripComponent); |
| 27 | + fixture.detectChanges(); |
| 28 | + hierarchicalGrid = fixture.componentInstance.hgrid; |
| 29 | + actionStrip = fixture.componentInstance.actionStrip; |
| 30 | + })); |
| 31 | + |
| 32 | + it('Should collapse an expanded record when beginAddRow is called for it', () => { |
| 33 | + const row = hierarchicalGrid.rowList.first; |
| 34 | + hierarchicalGrid.expandRow(row.rowID); |
| 35 | + fixture.detectChanges(); |
| 36 | + expect(row.expanded).toBeTrue(); |
| 37 | + |
| 38 | + row.beginAddRow(); |
| 39 | + fixture.detectChanges(); |
| 40 | + expect(row.expanded).toBeFalse(); |
| 41 | + expect(hierarchicalGrid.getRowByIndex(1).addRow).toBeTrue(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('Should allow the expansion of a newly added (commited) record', async() => { |
| 45 | + const row = hierarchicalGrid.rowList.first; |
| 46 | + hierarchicalGrid.expandRow(row.rowID); |
| 47 | + fixture.detectChanges(); |
| 48 | + expect(row.expanded).toBeTrue(); |
| 49 | + |
| 50 | + row.beginAddRow(); |
| 51 | + fixture.detectChanges(); |
| 52 | + expect(row.expanded).toBeFalse(); |
| 53 | + expect(hierarchicalGrid.getRowByIndex(1).addRow).toBeTrue(); |
| 54 | + hierarchicalGrid.endEdit(true); |
| 55 | + fixture.detectChanges(); |
| 56 | + hierarchicalGrid.addRowSnackbar.triggerAction(); |
| 57 | + fixture.detectChanges(); |
| 58 | + |
| 59 | + await wait(100); |
| 60 | + fixture.detectChanges(); |
| 61 | + |
| 62 | + const newRowData = hierarchicalGrid.data[hierarchicalGrid.data.length - 1]; |
| 63 | + const newRow = hierarchicalGrid.rowList.find(r => r.rowID === newRowData[hierarchicalGrid.primaryKey]); |
| 64 | + expect(newRow.expanded).toBeFalse(); |
| 65 | + hierarchicalGrid.expandRow(newRow.rowID); |
| 66 | + fixture.detectChanges(); |
| 67 | + expect(newRow.expanded).toBeTrue(); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments