|
1 | | -import { Component, ViewChild, OnInit, ElementRef, ViewChildren, QueryList, ChangeDetectorRef, DOCUMENT, ChangeDetectionStrategy } from '@angular/core'; |
| 1 | +import { Component, ViewChild, OnInit, ElementRef, ViewChildren, QueryList, ChangeDetectorRef, DOCUMENT, ChangeDetectionStrategy, provideZonelessChangeDetection } from '@angular/core'; |
2 | 2 | import { fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; |
3 | 3 | import { By } from '@angular/platform-browser'; |
4 | 4 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
@@ -46,7 +46,7 @@ describe('IgxDropDown ', () => { |
46 | 46 | const mockCdr = jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck', 'detectChanges']); |
47 | 47 | mockSelection.get.and.returnValue(new Set([])); |
48 | 48 | const mockForOf = jasmine.createSpyObj('IgxForOfDirective', ['totalItemCount']); |
49 | | - const mockDocument = jasmine.createSpyObj('DOCUMENT', [], { 'defaultView': { getComputedStyle: () => null }}); |
| 49 | + const mockDocument = jasmine.createSpyObj('DOCUMENT', [], { 'defaultView': { getComputedStyle: () => null } }); |
50 | 50 |
|
51 | 51 | beforeEach(() => { |
52 | 52 | TestBed.configureTestingModule({ |
@@ -855,7 +855,7 @@ describe('IgxDropDown ', () => { |
855 | 855 |
|
856 | 856 | const itemToClick = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_ITEM}`))[0]; |
857 | 857 |
|
858 | | - const event = new Event('mousedown', { }); |
| 858 | + const event = new Event('mousedown', {}); |
859 | 859 | spyOn(event, 'preventDefault'); |
860 | 860 | itemToClick.triggerEventHandler('mousedown', event); |
861 | 861 |
|
@@ -1032,6 +1032,98 @@ describe('IgxDropDown ', () => { |
1032 | 1032 | expect(expectedScroll - acceptableDelta < scrollTop && expectedScroll + acceptableDelta > scrollTop).toBe(true); |
1033 | 1033 | }); |
1034 | 1034 | }); |
| 1035 | + describe('Zoneless virtualization tests', () => { |
| 1036 | + let scroll: IgxForOfDirective<any>; |
| 1037 | + beforeEach(async () => { |
| 1038 | + TestBed.resetTestingModule(); |
| 1039 | + await TestBed.configureTestingModule({ |
| 1040 | + imports: [ |
| 1041 | + NoopAnimationsModule, |
| 1042 | + VirtualizedDropDownComponent |
| 1043 | + ], |
| 1044 | + providers: [provideZonelessChangeDetection()] |
| 1045 | + }).compileComponents(); |
| 1046 | + fixture = TestBed.createComponent(VirtualizedDropDownComponent); |
| 1047 | + fixture.detectChanges(); |
| 1048 | + dropdown = fixture.componentInstance.dropdown; |
| 1049 | + scroll = fixture.componentInstance.virtualScroll; |
| 1050 | + }); |
| 1051 | + it('should not throw when scrolling after selecting an item', async () => { |
| 1052 | + const preSelected = { value: fixture.componentInstance.items[0], index: 0 } as IgxDropDownItemBaseDirective; |
| 1053 | + dropdown.selectItem(preSelected); |
| 1054 | + |
| 1055 | + dropdown.toggle(); |
| 1056 | + await wait(50); |
| 1057 | + fixture.detectChanges(); |
| 1058 | + |
| 1059 | + scroll.getScroll().scrollTop = scroll.getScroll().scrollHeight; |
| 1060 | + await wait(50); |
| 1061 | + |
| 1062 | + expect(() => fixture.detectChanges()).not.toThrow(); |
| 1063 | + }); |
| 1064 | + |
| 1065 | + it('should update aria-activedescendant to the id of the focused item in virtualized dropdown when navigating', async () => { |
| 1066 | + const preSelected = { value: fixture.componentInstance.items[0], index: 0 } as IgxDropDownItemBaseDirective; |
| 1067 | + dropdown.selectItem(preSelected); |
| 1068 | + dropdown.toggle(); |
| 1069 | + await wait(50); |
| 1070 | + fixture.detectChanges(); |
| 1071 | + |
| 1072 | + const targetElement = fixture.debugElement.query(By.directive(IgxButtonDirective)).nativeElement; |
| 1073 | + let focusedItem = fixture.debugElement.query(By.css(`.${CSS_CLASS_FOCUSED}`)).nativeElement; |
| 1074 | + |
| 1075 | + expect(focusedItem).toBeTruthy(); |
| 1076 | + let focusedItemId = focusedItem.getAttribute('id'); |
| 1077 | + expect(focusedItemId).toBeTruthy(); |
| 1078 | + expect(targetElement.getAttribute('aria-activedescendant')).toBe(focusedItemId); |
| 1079 | + |
| 1080 | + dropdown.navigateNext(); |
| 1081 | + await wait(50); |
| 1082 | + fixture.detectChanges(); |
| 1083 | + |
| 1084 | + focusedItem = fixture.debugElement.query(By.css(`.${CSS_CLASS_FOCUSED}`)).nativeElement; |
| 1085 | + focusedItemId = focusedItem.getAttribute('id'); |
| 1086 | + expect(targetElement.getAttribute('aria-activedescendant')).toBe(focusedItemId); |
| 1087 | + |
| 1088 | + dropdown.navigateFirst(); |
| 1089 | + await wait(50); |
| 1090 | + fixture.detectChanges(); |
| 1091 | + focusedItem = fixture.debugElement.query(By.css(`.${CSS_CLASS_FOCUSED}`)).nativeElement; |
| 1092 | + focusedItemId = focusedItem.getAttribute('id'); |
| 1093 | + expect(targetElement.getAttribute('aria-activedescendant')).toBe(focusedItemId); |
| 1094 | + }); |
| 1095 | + |
| 1096 | + it('should update aria-activedescendant to the id of the focused item in virtualized dropdown when navigating with scrolling', async () => { |
| 1097 | + const preSelected = { value: fixture.componentInstance.items[0], index: 0 } as IgxDropDownItemBaseDirective; |
| 1098 | + dropdown.selectItem(preSelected); |
| 1099 | + dropdown.toggle(); |
| 1100 | + await wait(50); |
| 1101 | + fixture.detectChanges(); |
| 1102 | + |
| 1103 | + const targetElement = fixture.debugElement.query(By.directive(IgxButtonDirective)).nativeElement; |
| 1104 | + let focusedItem = fixture.debugElement.query(By.css(`.${CSS_CLASS_FOCUSED}`)).nativeElement; |
| 1105 | + |
| 1106 | + expect(focusedItem).toBeTruthy(); |
| 1107 | + let focusedItemId = focusedItem.getAttribute('id'); |
| 1108 | + expect(focusedItemId).toBeTruthy(); |
| 1109 | + expect(targetElement.getAttribute('aria-activedescendant')).toBe(focusedItemId); |
| 1110 | + |
| 1111 | + dropdown.navigateLast(); |
| 1112 | + await wait(50); |
| 1113 | + fixture.detectChanges(); |
| 1114 | + |
| 1115 | + focusedItem = fixture.debugElement.query(By.css(`.${CSS_CLASS_FOCUSED}`)).nativeElement; |
| 1116 | + focusedItemId = focusedItem.getAttribute('id'); |
| 1117 | + expect(targetElement.getAttribute('aria-activedescendant')).toBe(focusedItemId); |
| 1118 | + |
| 1119 | + dropdown.navigateFirst(); |
| 1120 | + await wait(50); |
| 1121 | + fixture.detectChanges(); |
| 1122 | + focusedItem = fixture.debugElement.query(By.css(`.${CSS_CLASS_FOCUSED}`)).nativeElement; |
| 1123 | + focusedItemId = focusedItem.getAttribute('id'); |
| 1124 | + expect(targetElement.getAttribute('aria-activedescendant')).toBe(focusedItemId); |
| 1125 | + }); |
| 1126 | + }); |
1035 | 1127 | describe('Rendering', () => { |
1036 | 1128 | describe('Accessibility', () => { |
1037 | 1129 | beforeEach(waitForAsync(() => { |
|
0 commit comments