From 0bd0eed0f6802520bf0888dc9709e72bc781634f Mon Sep 17 00:00:00 2001 From: IvayloG Date: Wed, 21 Nov 2018 12:16:07 +0200 Subject: [PATCH] test(IgxTreeGrid): Adding empty ChildDataKey test. #2921 --- .../tree-grid/tree-grid-integration.spec.ts | 64 +++++++++++++++---- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-integration.spec.ts b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-integration.spec.ts index 507a7cf5178..9a8ebbb3cce 100644 --- a/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-integration.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-integration.spec.ts @@ -804,12 +804,10 @@ fdescribe('IgxTreeGrid - Integration', () => { const childRow = { ID: 12, ParentID: 11, Name: 'Tervel Pulev', JobTitle: 'wrestler', Age: 30 }; const grandChildRow = { ID: 13, ParentID: 12, Name: 'Asparuh Pulev', JobTitle: 'wrestler', Age: 14 }; const trans = treeGrid.transactions; - spyOn(trans, 'add').and.callThrough(); treeGrid.addRow(rootRow, 0); fix.detectChanges(); - const parentRow = treeGrid.getRowByIndex(10) as IgxTreeGridRowComponent; treeGrid.addRow(childRow, 11); fix.detectChanges(); @@ -829,16 +827,58 @@ fdescribe('IgxTreeGrid - Integration', () => { expect(treeGrid.getRowByKey(13).nativeElement.classList).toContain('igx-grid__tr--edited'); }); - it('Add a child node to a previously added parent node - Hierarchical DS', () => { - // TODO: - // 1. Add a row at level 0 to the grid - // 2. Add a child row to that parent - // 3. Verify the new rows are pending with the correct styles - // 4. Commit - // 5. verify the rows are committed, the styles are OK - // 6. Add another child row at level 2 (grand-child of the first row) - // 7. verify the pending styles is applied only to the newly added row - // and not to the previously added rows + it('Add a child node to a previously added parent node - Hierarchical DS - empty ChildDataKey -commit', () => { + fix = TestBed.createComponent(IgxTreeGridRowEditingHierarchicalDSTransactionComponent); + fix.detectChanges(); + treeGrid = fix.componentInstance.treeGrid as IgxTreeGridComponent; + const trans = treeGrid.transactions; + const rootRow = { + ID: 11, + Name: 'Kubrat Pulev', + HireDate: new Date(2018, 10, 20), + Age: 32, + OnPTO: false, + Employees: [] + }; + + const childRow = { + ID: 12, + Name: 'Tervel Pulev', + HireDate: new Date(2018, 10, 10), + Age: 30, + OnPTO: true, + Employees: [] + }; + + const grandChildRow = { + ID: 13, + Name: 'Asparuh Pulev', + HireDate: new Date(2017, 10, 10), + Age: 14, + OnPTO: true, + Employees: [] + }; + + treeGrid.addRow(rootRow); + treeGrid.addRow(childRow, 11); + + expect(treeGrid.getRowByKey(11).nativeElement.classList).toContain('igx-grid__tr--edited'); + expect(treeGrid.getRowByKey(12).nativeElement.classList).toContain('igx-grid__tr--edited'); + + trans.commit(treeGrid.data); + + expect(treeGrid.getRowByKey(11).nativeElement.classList).not.toContain('igx-grid__tr--edited'); + expect(treeGrid.getRowByKey(12).nativeElement.classList).not.toContain('igx-grid__tr--edited'); + + treeGrid.addRow(grandChildRow, 12); + + expect(treeGrid.getRowByKey(11).nativeElement.classList).not.toContain('igx-grid__tr--edited'); + expect(treeGrid.getRowByKey(12).nativeElement.classList).not.toContain('igx-grid__tr--edited'); + expect(treeGrid.getRowByKey(13).nativeElement.classList).toContain('igx-grid__tr--edited'); + expect(treeGrid.records.get(11).level).toBe(0); + expect(treeGrid.records.get(12).level).toBe(1); + expect(treeGrid.records.get(13).level).toBe(2); + }); it('Delete a pending parent node - Flat DS', () => {