Skip to content

Commit f6e79a9

Browse files
committed
test(Search): #2530 Made most tests async.
1 parent 202c549 commit f6e79a9

File tree

1 file changed

+74
-46
lines changed

1 file changed

+74
-46
lines changed

projects/igniteui-angular/src/lib/grid/grid.search.spec.ts

+74-46
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { BasicGridSearchComponent } from '../test-utils/grid-base-components.spe
99
import { SampleTestData } from '../test-utils/sample-test-data.spec';
1010
import { GridWithAvatarComponent, GroupableGridSearchComponent, ScrollableGridSearchComponent } from '../test-utils/grid-samples.spec';
1111
import { IForOfState } from '../directives/for-of/for_of.directive';
12+
import { wait } from '../test-utils/ui-interactions.spec';
1213

1314
describe('IgxGrid - search API', () => {
1415
const CELL_CSS_CLASS = '.igx-grid__td';
@@ -639,8 +640,8 @@ describe('IgxGrid - search API', () => {
639640
});
640641

641642
/* ScrollableGrid */
642-
xdescribe('', () => {
643-
beforeEach(() => {
643+
describe('', () => {
644+
beforeEach(async () => {
644645
fix = TestBed.createComponent(ScrollableGridSearchComponent);
645646
fix.detectChanges();
646647

@@ -649,30 +650,31 @@ describe('IgxGrid - search API', () => {
649650
grid.data[29] = { ID: 30, Name: 'Eduardo Ramirez', JobTitle: 'Manager', HireDate: '1887-11-28T11:23:17.714Z' };
650651
grid.width = '500px';
651652
grid.height = '600px';
653+
await wait();
652654
fixNativeElement = fix.debugElement.nativeElement;
653655
fix.detectChanges();
654656
});
655657

656-
it('findNext scrolls to cells out of view', (done) => {
657-
findNext(grid, '30').then(() => {
658-
expect(isInView(29, grid.virtualizationState)).toBeTruthy();
658+
it('findNext scrolls to cells out of view', async () => {
659+
grid.findNext('30');
660+
await wait();
661+
expect(isInView(29, grid.virtualizationState)).toBeTruthy();
659662

660-
findNext(grid, '1887').then(() => {
661-
expect(isInView(3, grid.rowList.first.virtDirRow.state)).toBeTruthy();
662-
done();
663-
});
664-
});
663+
grid.findNext('1887');
664+
await wait();
665+
expect(isInView(3, grid.rowList.first.virtDirRow.state)).toBeTruthy();
665666
});
666667

667-
it('findPrev scrolls to cells out of view', (done) => {
668-
findNext(grid, '30').then(() => {
669-
expect(isInView(29, grid.virtualizationState)).toBeTruthy();
668+
it('findPrev scrolls to cells out of view', async () => {
669+
grid.findPrev('30');
670+
await wait();
671+
fix.detectChanges();
672+
expect(isInView(29, grid.virtualizationState)).toBeTruthy();
670673

671-
findNext(grid, '1887').then(() => {
672-
expect(isInView(3, grid.rowList.first.virtDirRow.state)).toBeTruthy();
673-
done();
674-
});
675-
});
674+
grid.findPrev('1887');
675+
await wait();
676+
fix.detectChanges();
677+
expect(isInView(3, grid.rowList.first.virtDirRow.state)).toBeTruthy();
676678
});
677679

678680
it('should keep the active highlight when active cell enters and exits edit mode', () => {
@@ -743,7 +745,7 @@ describe('IgxGrid - search API', () => {
743745
expect(activeHighlight).toBe(highlights[0]);
744746
});
745747

746-
it('should update highlights when the cell value is cleared', () => {
748+
it('should update highlights when the cell value is cleared', async () => {
747749
const rv = fix.debugElement.queryAll(By.css(CELL_CSS_CLASS))[1].nativeElement;
748750
const rv2 = fix.debugElement.queryAll(By.css(CELL_CSS_CLASS))[2].nativeElement;
749751
const cell = grid.getCellByColumn(0, 'Name');
@@ -754,6 +756,7 @@ describe('IgxGrid - search API', () => {
754756
cell.column.editable = true;
755757

756758
grid.findNext('c');
759+
await wait();
757760
fix.detectChanges();
758761

759762
activeHighlight = rv.querySelector('.' + component.activeClass);
@@ -780,31 +783,32 @@ describe('IgxGrid - search API', () => {
780783
expect(activeHighlight).toBe(highlights[0]);
781784
});
782785

783-
it('Should update highlight when setting perPage option', (done) => {
786+
it('Should update highlight when setting perPage option', async () => {
784787
grid.paging = true;
785788
fix.detectChanges();
786789

787790
const searchString = 'casey';
788791

789792
grid.findNext(searchString);
790-
findNextWithPaging(grid, searchString).then(() => {
791-
fix.detectChanges();
792-
let highlight = grid.nativeElement.querySelector('.' + component.activeClass);
793-
expect(highlight).not.toBeNull();
794-
expect(grid.page).toBe(0);
795-
grid.perPage = 10;
796-
fix.detectChanges();
797-
798-
highlight = grid.nativeElement.querySelector('.' + component.activeClass);
799-
expect(highlight).toBeNull();
800-
expect(grid.page).toBe(0);
801-
802-
grid.page = 1;
803-
fix.detectChanges();
804-
highlight = grid.nativeElement.querySelector('.' + component.activeClass);
805-
expect(highlight).not.toBeNull();
806-
done();
807-
});
793+
grid.findNext(searchString);
794+
await wait();
795+
fix.detectChanges();
796+
let highlight = grid.nativeElement.querySelector('.' + component.activeClass);
797+
expect(highlight).not.toBeNull();
798+
expect(grid.page).toBe(0);
799+
800+
grid.perPage = 10;
801+
fix.detectChanges();
802+
803+
highlight = grid.nativeElement.querySelector('.' + component.activeClass);
804+
expect(highlight).toBeNull();
805+
expect(grid.page).toBe(0);
806+
807+
grid.page = 1;
808+
await wait(30);
809+
fix.detectChanges();
810+
highlight = grid.nativeElement.querySelector('.' + component.activeClass);
811+
expect(highlight).not.toBeNull();
808812
});
809813
});
810814

@@ -819,12 +823,13 @@ describe('IgxGrid - search API', () => {
819823
fixNativeElement = fix.debugElement.nativeElement;
820824
});
821825

822-
it('Should be able to navigate through highlights with grouping enabled', () => {
826+
it('Should be able to navigate through highlights with grouping enabled', async () => {
823827
grid.groupBy({
824828
fieldName: 'JobTitle',
825829
dir: SortingDirection.Asc
826830
});
827831
grid.findNext('Software');
832+
await wait();
828833
fix.detectChanges();
829834

830835
let spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
@@ -834,13 +839,17 @@ describe('IgxGrid - search API', () => {
834839

835840
grid.findNext('Software');
836841
grid.findNext('Software');
842+
await wait();
843+
fix.detectChanges();
837844

838845
spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
839846
highlight = fixNativeElement.querySelector('.' + component.activeClass);
840847
expect(spans.length).toBe(5);
841848
expect(highlight).toBe(spans[2]);
842849

843850
grid.findPrev('Software');
851+
await wait();
852+
fix.detectChanges();
844853

845854
spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
846855
highlight = fixNativeElement.querySelector('.' + component.activeClass);
@@ -849,21 +858,25 @@ describe('IgxGrid - search API', () => {
849858

850859
grid.findPrev('Software');
851860
grid.findPrev('Software');
861+
await wait();
862+
fix.detectChanges();
852863

853864
spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
854865
highlight = fixNativeElement.querySelector('.' + component.activeClass);
855866
expect(spans.length).toBe(5);
856867
expect(highlight).toBe(spans[4]);
857868
});
858869

859-
it('Should be able to react to changes in grouping', () => {
870+
it('Should be able to react to changes in grouping', async () => {
860871
grid.groupBy({
861872
fieldName: 'JobTitle',
862873
dir: SortingDirection.Asc
863874
});
864875

865876
let cell = grid.getCellByColumn(1, 'JobTitle');
866877
grid.findNext('software');
878+
await wait();
879+
fix.detectChanges();
867880

868881
let highlight = cell.nativeElement.querySelector('.' + component.activeClass);
869882
expect(highlight !== null).toBeTruthy();
@@ -895,22 +908,24 @@ describe('IgxGrid - search API', () => {
895908
});
896909

897910
grid.findNext('software');
911+
await wait();
912+
fix.detectChanges();
898913
cell = grid.getCellByColumn(5, 'JobTitle');
899914
highlight = cell.nativeElement.querySelector('.' + component.activeClass);
900915
expect(highlight !== null).toBeTruthy();
901916
});
902917

903-
it('Should be able to navigate through highlights with grouping and paging enabled', () => {
918+
it('Should be able to navigate through highlights with grouping and paging enabled', async () => {
904919
grid.groupBy({
905920
fieldName: 'JobTitle',
906921
dir: SortingDirection.Asc
907922
});
908923
grid.paging = true;
909924
grid.perPage = 6;
910925

911-
fix.detectChanges();
912-
913926
grid.findNext('Software');
927+
await wait();
928+
fix.detectChanges();
914929

915930
let spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
916931
let highlight = fixNativeElement.querySelector('.' + component.activeClass);
@@ -920,6 +935,7 @@ describe('IgxGrid - search API', () => {
920935
expect(grid.page).toBe(0);
921936

922937
grid.findPrev('Software');
938+
await wait();
923939
fix.detectChanges();
924940

925941
spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
@@ -931,6 +947,8 @@ describe('IgxGrid - search API', () => {
931947

932948
grid.findPrev('Software');
933949
grid.findPrev('Software');
950+
await wait();
951+
fix.detectChanges();
934952

935953
spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
936954
highlight = fixNativeElement.querySelector('.' + component.activeClass);
@@ -940,7 +958,7 @@ describe('IgxGrid - search API', () => {
940958
expect(grid.page).toBe(1);
941959
});
942960

943-
it('Should be able to properly handle perPage changes with gouping and paging', () => {
961+
it('Should be able to properly handle perPage changes with gouping and paging', async () => {
944962
grid.groupBy({
945963
fieldName: 'JobTitle',
946964
dir: SortingDirection.Asc
@@ -951,6 +969,7 @@ describe('IgxGrid - search API', () => {
951969
grid.findNext('Software');
952970
grid.findNext('Software');
953971
grid.findNext('Software');
972+
await wait();
954973
fix.detectChanges();
955974

956975
let spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
@@ -971,6 +990,7 @@ describe('IgxGrid - search API', () => {
971990
expect(grid.page).toBe(0);
972991

973992
grid.page = 1;
993+
await wait();
974994
fix.detectChanges();
975995

976996
spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
@@ -981,7 +1001,7 @@ describe('IgxGrid - search API', () => {
9811001
expect(grid.page).toBe(1);
9821002
});
9831003

984-
it('Should be able to properly handle navigating through collapsed rows', () => {
1004+
it('Should be able to properly handle navigating through collapsed rows', async () => {
9851005
grid.groupBy({
9861006
fieldName: 'JobTitle',
9871007
dir: SortingDirection.Asc
@@ -992,6 +1012,8 @@ describe('IgxGrid - search API', () => {
9921012
grid.findNext('software');
9931013

9941014
grid.toggleGroup(grid.groupsRecords[0]);
1015+
await wait();
1016+
fix.detectChanges();
9951017

9961018
let spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
9971019
let highlight = fixNativeElement.querySelector('.' + component.activeClass);
@@ -1002,6 +1024,8 @@ describe('IgxGrid - search API', () => {
10021024
grid.findNext('software');
10031025
grid.findNext('software');
10041026
grid.findNext('software');
1027+
await wait();
1028+
fix.detectChanges();
10051029

10061030
spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
10071031
highlight = fixNativeElement.querySelector('.' + component.activeClass);
@@ -1011,7 +1035,7 @@ describe('IgxGrid - search API', () => {
10111035
expect(grid.isExpandedGroup(grid.groupsRecords[0])).toBeTruthy();
10121036
});
10131037

1014-
it('Should be able to properly handle navigating through collapsed rows with paging', () => {
1038+
it('Should be able to properly handle navigating through collapsed rows with paging', async () => {
10151039
grid.groupBy({
10161040
fieldName: 'JobTitle',
10171041
dir: SortingDirection.Asc
@@ -1023,10 +1047,13 @@ describe('IgxGrid - search API', () => {
10231047

10241048
grid.findNext('software');
10251049
grid.findNext('software');
1050+
await wait();
1051+
fix.detectChanges();
10261052

10271053
grid.toggleGroup(grid.groupsRecords[0]);
10281054
grid.findNext('software');
10291055

1056+
await wait();
10301057
fix.detectChanges();
10311058
let spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);
10321059
let highlight = fixNativeElement.querySelector('.' + component.activeClass);
@@ -1038,6 +1065,7 @@ describe('IgxGrid - search API', () => {
10381065
grid.findNext('software');
10391066
grid.findNext('software');
10401067
grid.findNext('software');
1068+
await wait();
10411069
fix.detectChanges();
10421070

10431071
spans = fixNativeElement.querySelectorAll('.' + component.highlightClass);

0 commit comments

Comments
 (0)