Skip to content

Commit 28e7032

Browse files
committed
test(IgxGrid): Added colum groups pinning test. #488
1 parent 90712e2 commit 28e7032

File tree

1 file changed

+140
-3
lines changed

1 file changed

+140
-3
lines changed

Diff for: projects/igniteui-angular/src/lib/grid/column-group.spec.ts

+140-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ describe('IgxGrid - multi-column headers', () => {
2424
BlueWhaleGridComponent,
2525
ColumnGroupTestComponent,
2626
ColumnGroupFourLevelTestComponent,
27+
<<<<<<< Updated upstream
2728
ThreeGroupsThreeColumnsGridComponent
29+
=======
30+
ColumnGroupTwoGroupsTestComponent
31+
>>>>>>> Stashed changes
2832
],
2933
imports: [
3034
NoopAnimationsModule,
@@ -615,11 +619,24 @@ describe('IgxGrid - multi-column headers', () => {
615619
const grGeneralInf = getColGroup(grid, 'General Information');
616620
expect(grGeneralInf.allChildren.every(c => c.pinned === true)).toEqual(true);
617621

618-
expect(colContactTitle.visibleIndex).toEqual(5);
619-
expect(grid.getColumnByName('CompanyName').visibleIndex).toEqual(0);
622+
// expect(grGeneralInf.visibleIndex).toEqual(-1);
623+
// expect(grid.getColumnByName('ID').visibleIndex).toEqual(0);
620624

621625
expect(grid.pinnedColumns.length).toEqual(5);
622626
expect(grid.unpinnedColumns.length).toEqual(13);
627+
628+
// Unpin a column
629+
grid.getColumnByName('CompanyName').pinned = false;
630+
fixture.detectChanges();
631+
632+
// Verify the topParent group is not pinned
633+
expect(grGeneralInf.allChildren.every(c => c.pinned === false)).toEqual(true);
634+
635+
//expect(grGeneralInf.visibleIndex).toEqual(0);
636+
//expect(grid.getColumnByName('ID').visibleIndex).toEqual(0);
637+
638+
expect(grid.pinnedColumns.length).toEqual(0);
639+
expect(grid.unpinnedColumns.length).toEqual(18);
623640
});
624641

625642
it('column pinning - Pin a group in level one', () => {
@@ -629,19 +646,107 @@ describe('IgxGrid - multi-column headers', () => {
629646
expect(grid.pinnedColumns.length).toEqual(0);
630647
expect(grid.unpinnedColumns.length).toEqual(18);
631648

632-
// Try to pin a column in a group
649+
// Pin top group
633650
const grGeneralInf = getColGroup(grid, 'General Information');
634651
grGeneralInf.pinned = true;
635652
fixture.detectChanges();
636653

637654
// Verify group and all its children are pinned
638655
expect(grGeneralInf.allChildren.every(c => c.pinned === true)).toEqual(true);
656+
<<<<<<< Updated upstream
639657

640658
expect(grGeneralInf.visibleIndex).toEqual(-1);
641659
expect(grid.getColumnByName('CompanyName').visibleIndex).toEqual(0);
660+
=======
661+
662+
//expect(grGeneralInf.visibleIndex).toEqual(-1);
663+
//expect(grid.getColumnByName('CompanyName').visibleIndex).toEqual(0);
664+
>>>>>>> Stashed changes
642665

643666
expect(grid.pinnedColumns.length).toEqual(5);
644667
expect(grid.unpinnedColumns.length).toEqual(13);
668+
669+
// Unpin top group
670+
grGeneralInf.pinned = false;
671+
fixture.detectChanges();
672+
673+
// Verify group and all its children are not pinned
674+
expect(grGeneralInf.allChildren.every(c => c.pinned === false)).toEqual(true);
675+
676+
//expect(grGeneralInf.visibleIndex).toEqual(0);
677+
expect(grid.getColumnByName('ID').visibleIndex).toEqual(0);
678+
679+
expect(grid.pinnedColumns.length).toEqual(0);
680+
expect(grid.unpinnedColumns.length).toEqual(18);
681+
});
682+
683+
it('column pinning - Try to pin column or group which not match in the view', () => {
684+
const fixture = TestBed.createComponent(ColumnGroupFourLevelTestComponent);
685+
fixture.detectChanges();
686+
const grid = fixture.componentInstance.grid;
687+
expect(grid.pinnedColumns.length).toEqual(0);
688+
expect(grid.unpinnedColumns.length).toEqual(18);
689+
690+
// Try to pin top group
691+
const grAdressInf = getColGroup(grid, 'Address Information');
692+
grAdressInf.pinned = true;
693+
fixture.detectChanges();
694+
695+
// Verify group and all its children are not pinned
696+
expect(grAdressInf.allChildren.every(c => c.pinned === false)).toEqual(true);
697+
698+
expect(grid.getColumnByName('ID').visibleIndex).toEqual(0);
699+
700+
expect(grid.pinnedColumns.length).toEqual(0);
701+
expect(grid.unpinnedColumns.length).toEqual(18);
702+
703+
// Try to pin a column
704+
grid.getColumnByName('Fax').pinned = true;
705+
fixture.detectChanges();
706+
707+
// Verify group and all its children are not pinned
708+
expect(grAdressInf.allChildren.every(c => c.pinned === false)).toEqual(true);
709+
710+
expect(grid.getColumnByName('ID').visibleIndex).toEqual(0);
711+
712+
expect(grid.pinnedColumns.length).toEqual(0);
713+
expect(grid.unpinnedColumns.length).toEqual(18);
714+
715+
// Try to pin child group
716+
getColGroup(grid, 'Contact Information').pinned = true;
717+
fixture.detectChanges();
718+
719+
// Verify group and all its children are not pinned
720+
expect(grAdressInf.allChildren.every(c => c.pinned === false)).toEqual(true);
721+
722+
expect(grid.getColumnByName('ID').visibleIndex).toEqual(0);
723+
724+
expect(grid.pinnedColumns.length).toEqual(0);
725+
expect(grid.unpinnedColumns.length).toEqual(18);
726+
});
727+
728+
it('column pinning - Verify pin a not fully visble group', () => {
729+
const fixture = TestBed.createComponent(ColumnGroupTwoGroupsTestComponent);
730+
fixture.detectChanges();
731+
const grid = fixture.componentInstance.grid;
732+
expect(grid.pinnedColumns.length).toEqual(0);
733+
expect(grid.unpinnedColumns.length).toEqual(13);
734+
735+
// Pin a Group which is not fully visble
736+
const grAdressInf = getColGroup(grid, 'Address Information');
737+
grAdressInf.pinned = true;
738+
fixture.detectChanges();
739+
740+
// Verify group and all its children are not pinned
741+
expect(grAdressInf.allChildren.every(c => c.pinned === true)).toEqual(true);
742+
743+
expect(grid.getCellByColumn(0, 'ID')).toBeDefined();
744+
expect(grid.getCellByColumn(0, 'Country')).toBeDefined();
745+
expect(grid.getCellByColumn(0, 'City')).toBeDefined();
746+
747+
//expect(grid.getCellByColumn(0, 'ID').value).toEqual("ALFKI");
748+
//expect(grid.getCellByColumn(0, 'Country').value).toEqual("Germany");
749+
//expect(grid.getCellByColumn(0, 'City').value).toEqual("Berlin");
645750
});
646751

647752
xit('Should move column group.', () => {
@@ -766,6 +871,38 @@ export class ColumnGroupFourLevelTestComponent {
766871
data = DATASOURCE;
767872
}
768873

874+
875+
@Component({
876+
template: `
877+
<igx-grid #grid [data]="data" height="600px" width="800px">
878+
<igx-column field="ID"></igx-column>
879+
<igx-column-group header="General Information">
880+
<igx-column field="CompanyName"></igx-column>
881+
<igx-column-group header="Person Details">
882+
<igx-column field="ContactName"></igx-column>
883+
<igx-column field="ContactTitle"></igx-column>
884+
</igx-column-group>
885+
</igx-column-group>
886+
<igx-column-group header="Address Information">
887+
<igx-column field="Region"></igx-column>
888+
<igx-column-group header="Location">
889+
<igx-column field="Country"></igx-column>
890+
<igx-column-group header="Location City">
891+
<igx-column field="City"></igx-column>
892+
<igx-column field="Address"></igx-column>
893+
</igx-column-group>
894+
</igx-column-group>
895+
</igx-column-group>
896+
</igx-grid>
897+
`
898+
})
899+
export class ColumnGroupTwoGroupsTestComponent {
900+
@ViewChild(IgxGridComponent, { read: IgxGridComponent })
901+
grid: IgxGridComponent;
902+
903+
data = DATASOURCE;
904+
}
905+
769906
@Component({
770907
template: `
771908
<igx-grid #grid [data]="data" height="600px" width="1000px">

0 commit comments

Comments
 (0)