Skip to content

Commit a9a69e8

Browse files
committed
test(elements): add test for grid columns dom manipulation
1 parent 4979d5e commit a9a69e8

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

projects/igniteui-angular-elements/src/app/custom-strategy.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
IgcColumnComponent,
1212
IgcPaginatorComponent,
1313
IgcGridStateComponent,
14+
IgcColumnLayoutComponent,
1415
} from './components';
1516
import { defineComponents } from '../utils/register';
1617

@@ -23,6 +24,7 @@ describe('Elements: ', () => {
2324
IgcHierarchicalGridComponent,
2425
IgcPivotGridComponent,
2526
IgcColumnComponent,
27+
IgcColumnLayoutComponent,
2628
IgcPaginatorComponent,
2729
IgcGridStateComponent,
2830
);
@@ -181,5 +183,52 @@ describe('Elements: ', () => {
181183
await firstValueFrom(timer(10 /* SCHEDULE_DELAY */ * 2));
182184
expect(() => stateComponent.getStateAsString()).not.toThrow();
183185
});
186+
187+
it(`should allow manipulating projected columns through the DOM`, async () => {
188+
const innerHtml = `
189+
<igc-grid id="testGrid" primary-key="ProductID">
190+
<igc-column-layout header="Product ID">
191+
<igc-column row-start="1" col-start="1" row-end="3" field="ProductID" header="Product ID" width="25%"></igc-column>
192+
</igc-column-layout>
193+
<igc-column-layout header="Product Details">
194+
<igc-column row-start="1" col-start="1" col-end="3" field="ProductName" header="Product Name"></igc-column>
195+
<igc-column row-start="2" col-start="1" col-end="2" field="CategoryName" header="Category Name" groupable="true"></igc-column>
196+
<igc-column row-start="2" col-start="2" col-end="3" field="ImageUrl"></igc-column>
197+
</igc-column-layout>
198+
<igc-column-layout header="Product Stock">
199+
<igc-column row-start="1" col-start="1" col-end="3" field="InStock" header="In Stock" width="25%"></igc-column>
200+
</igc-column-layout>
201+
</igc-grid>`;
202+
testContainer.innerHTML = innerHtml;
203+
204+
// TODO: Better way to wait - potentially expose the queue or observable for update on the strategy
205+
await firstValueFrom(timer(10 /* SCHEDULE_DELAY */ * 3));
206+
207+
const grid = document.querySelector<IgcNgElement & InstanceType<typeof IgcGridComponent>>('#testGrid');
208+
const thirdGroup = document.querySelector<IgcNgElement>('igc-column-layout[header="Product Stock"]');
209+
const secondGroup = document.querySelector<IgcNgElement>('igc-column-layout[header="Product Details"]');
210+
211+
expect(grid.columns.length).toEqual(8);
212+
expect(grid.getColumnByName('ProductID')).toBeTruthy();
213+
expect(grid.getColumnByVisibleIndex(1).field).toEqual('ProductName');
214+
215+
grid.removeChild(secondGroup);
216+
await firstValueFrom(timer(10 /* SCHEDULE_DELAY */ * 3));
217+
218+
expect(grid.columns.length).toEqual(4);
219+
expect(grid.getColumnByName('ProductID')).toBeTruthy();
220+
expect(grid.getColumnByVisibleIndex(1).field).toEqual('InStock');
221+
222+
// TODO: secondGroup can't be re-used
223+
const newGroup = document.createElement('igc-column-layout');
224+
const newColumn = document.createElement('igc-column');
225+
newColumn.setAttribute('field', 'ProductName');
226+
newGroup.appendChild(newColumn);
227+
grid.insertBefore(newGroup, thirdGroup);
228+
await firstValueFrom(timer(10 /* SCHEDULE_DELAY */ * 3));
229+
230+
expect(grid.columns.length).toEqual(6);
231+
expect(grid.getColumnByVisibleIndex(1).field).toEqual('ProductName');
232+
});
184233
});
185234
});

0 commit comments

Comments
 (0)