|
1 |
| -import {ComponentFixture, TestBed, waitForAsync, fakeAsync, tick} from '@angular/core/testing'; |
| 1 | +import {ComponentFixture, fakeAsync, TestBed, tick, waitForAsync} from '@angular/core/testing'; |
2 | 2 | import {
|
3 | 3 | Component,
|
4 |
| - ViewChild, |
5 | 4 | ElementRef,
|
6 |
| - ViewChildren, |
7 |
| - QueryList, |
8 | 5 | EventEmitter,
|
| 6 | + QueryList, |
| 7 | + ViewChild, |
| 8 | + ViewChildren, |
9 | 9 | } from '@angular/core';
|
10 | 10 | import {By} from '@angular/platform-browser';
|
11 | 11 | import {
|
12 |
| - TAB, |
13 |
| - RIGHT_ARROW, |
14 |
| - LEFT_ARROW, |
| 12 | + D, |
15 | 13 | DOWN_ARROW,
|
16 |
| - UP_ARROW, |
17 |
| - SPACE, |
18 |
| - HOME, |
19 |
| - END, |
20 | 14 | E,
|
21 |
| - D, |
| 15 | + END, |
22 | 16 | ESCAPE,
|
23 |
| - S, |
24 | 17 | H,
|
| 18 | + HOME, |
| 19 | + LEFT_ARROW, |
| 20 | + RIGHT_ARROW, |
| 21 | + S, |
| 22 | + SPACE, |
| 23 | + TAB, |
| 24 | + UP_ARROW, |
25 | 25 | } from '@angular/cdk/keycodes';
|
26 | 26 | import {
|
27 |
| - dispatchKeyboardEvent, |
28 | 27 | createKeyboardEvent,
|
29 | 28 | dispatchEvent,
|
| 29 | + dispatchKeyboardEvent, |
30 | 30 | dispatchMouseEvent,
|
| 31 | + triggerFocus, |
31 | 32 | } from '../../cdk/testing/private';
|
32 | 33 | import {CdkMenuBar} from './menu-bar';
|
33 | 34 | import {CdkMenuModule} from './menu-module';
|
@@ -802,7 +803,7 @@ describe('MenuBar', () => {
|
802 | 803 |
|
803 | 804 | /** set the menus and triggers arrays. */
|
804 | 805 | function grabElementsForTesting() {
|
805 |
| - popoutMenus = fixture.componentInstance.menus.toArray().filter(el => !el._isInline()); |
| 806 | + popoutMenus = fixture.componentInstance.menus.toArray().filter(el => !el._isInline); |
806 | 807 | triggers = fixture.componentInstance.triggers.toArray();
|
807 | 808 | nativeInlineMenuItem = fixture.componentInstance.nativeInlineMenuItem.nativeElement;
|
808 | 809 | }
|
@@ -923,6 +924,7 @@ describe('MenuBar', () => {
|
923 | 924 | dispatchMouseEvent(menuBarNativeItems[0], 'mouseenter');
|
924 | 925 | dispatchMouseEvent(menuBarNativeItems[0], 'click');
|
925 | 926 | dispatchMouseEvent(menuBarNativeItems[0], 'mouseenter');
|
| 927 | + triggerFocus(menuBarNativeItems[0]); |
926 | 928 | detectChanges();
|
927 | 929 | }
|
928 | 930 |
|
@@ -1063,19 +1065,17 @@ describe('MenuBar', () => {
|
1063 | 1065 | expect(nativeMenus.length).toBe(0);
|
1064 | 1066 | });
|
1065 | 1067 |
|
1066 |
| - it( |
1067 |
| - 'should allow keyboard down arrow to focus next item after mouse sets focus to' + |
1068 |
| - ' initial item', |
1069 |
| - () => { |
1070 |
| - openFileMenu(); |
1071 |
| - dispatchMouseEvent(fileMenuNativeItems[0], 'mouseenter'); |
1072 |
| - detectChanges(); |
| 1068 | + it('should allow keyboard down arrow to focus next item after focusing initial item', () => { |
| 1069 | + openFileMenu(); |
1073 | 1070 |
|
1074 |
| - dispatchKeyboardEvent(nativeMenus[0], 'keydown', DOWN_ARROW); |
| 1071 | + dispatchKeyboardEvent(nativeMenus[0], 'keydown', DOWN_ARROW); |
| 1072 | + detectChanges(); |
| 1073 | + expect(document.activeElement).toEqual(fileMenuNativeItems[0]); |
1075 | 1074 |
|
1076 |
| - expect(document.activeElement).toEqual(fileMenuNativeItems[1]); |
1077 |
| - }, |
1078 |
| - ); |
| 1075 | + dispatchKeyboardEvent(nativeMenus[0], 'keydown', DOWN_ARROW); |
| 1076 | + detectChanges(); |
| 1077 | + expect(document.activeElement).toEqual(fileMenuNativeItems[1]); |
| 1078 | + }); |
1079 | 1079 |
|
1080 | 1080 | it(
|
1081 | 1081 | 'should not re-open a menu when hovering over the trigger in the menubar after clicking to ' +
|
@@ -1103,49 +1103,41 @@ describe('MenuBar', () => {
|
1103 | 1103 | },
|
1104 | 1104 | );
|
1105 | 1105 |
|
1106 |
| - it( |
1107 |
| - 'should set the tabindex of the opened trigger to 0 and toggle tabindex' + |
1108 |
| - ' when hovering between items', |
1109 |
| - () => { |
1110 |
| - openFileMenu(); |
| 1106 | + it('should not change the tabindex when hovering between items', () => { |
| 1107 | + openFileMenu(); |
1111 | 1108 |
|
1112 |
| - expect(menuBarNativeItems[0].tabIndex).toBe(0); |
| 1109 | + expect(menuBarNativeItems[0].tabIndex).toBe(0); |
1113 | 1110 |
|
1114 |
| - dispatchMouseEvent(menuBarNativeItems[1], 'mouseenter'); |
1115 |
| - detectChanges(); |
| 1111 | + dispatchMouseEvent(menuBarNativeItems[1], 'mouseenter'); |
| 1112 | + detectChanges(); |
1116 | 1113 |
|
1117 |
| - expect(menuBarNativeItems[0].tabIndex).toBe(-1); |
1118 |
| - expect(menuBarNativeItems[1].tabIndex).toBe(0); |
| 1114 | + expect(menuBarNativeItems[0].tabIndex).toBe(0); |
| 1115 | + expect(menuBarNativeItems[1].tabIndex).toBe(-1); |
1119 | 1116 |
|
1120 |
| - dispatchMouseEvent(menuBarNativeItems[0], 'mouseenter'); |
1121 |
| - detectChanges(); |
| 1117 | + dispatchMouseEvent(menuBarNativeItems[0], 'mouseenter'); |
| 1118 | + detectChanges(); |
1122 | 1119 |
|
1123 |
| - expect(menuBarNativeItems[0].tabIndex).toBe(0); |
1124 |
| - expect(menuBarNativeItems[1].tabIndex).toBe(-1); |
1125 |
| - }, |
1126 |
| - ); |
| 1120 | + expect(menuBarNativeItems[0].tabIndex).toBe(0); |
| 1121 | + expect(menuBarNativeItems[1].tabIndex).toBe(-1); |
| 1122 | + }); |
1127 | 1123 |
|
1128 |
| - it( |
1129 |
| - 'should set the tabindex to 0 on the active item and reset the previous active items ' + |
1130 |
| - 'to -1 when navigating down to a submenu and within it using a mouse', |
1131 |
| - () => { |
1132 |
| - openFileMenu(); |
1133 |
| - expect(menuBarNativeItems[0].tabIndex).toBe(0); |
| 1124 | + it('should not change the tabindex when navigating down to a submenu and within it using a mouse', () => { |
| 1125 | + openFileMenu(); |
| 1126 | + expect(menuBarNativeItems[0].tabIndex).toBe(0); |
1134 | 1127 |
|
1135 |
| - dispatchMouseEvent(fileMenuNativeItems[0], 'mouseenter'); |
1136 |
| - dispatchMouseEvent(menuBarNativeItems[0], 'mouseout'); |
1137 |
| - detectChanges(); |
| 1128 | + dispatchMouseEvent(fileMenuNativeItems[0], 'mouseenter'); |
| 1129 | + dispatchMouseEvent(menuBarNativeItems[0], 'mouseout'); |
| 1130 | + detectChanges(); |
1138 | 1131 |
|
1139 |
| - expect(menuBarNativeItems[0].tabIndex).toBe(-1); |
1140 |
| - expect(fileMenuNativeItems[0].tabIndex).toBe(0); |
| 1132 | + expect(menuBarNativeItems[0].tabIndex).toBe(0); |
| 1133 | + expect(fileMenuNativeItems[0].tabIndex).toBe(-1); |
1141 | 1134 |
|
1142 |
| - dispatchMouseEvent(fileMenuNativeItems[1], 'mouseenter'); |
1143 |
| - detectChanges(); |
| 1135 | + dispatchMouseEvent(fileMenuNativeItems[1], 'mouseenter'); |
| 1136 | + detectChanges(); |
1144 | 1137 |
|
1145 |
| - expect(fileMenuNativeItems[0].tabIndex).toBe(-1); |
1146 |
| - expect(fileMenuNativeItems[1].tabIndex).toBe(0); |
1147 |
| - }, |
1148 |
| - ); |
| 1138 | + expect(fileMenuNativeItems[0].tabIndex).toBe(-1); |
| 1139 | + expect(fileMenuNativeItems[1].tabIndex).toBe(-1); |
| 1140 | + }); |
1149 | 1141 | });
|
1150 | 1142 | });
|
1151 | 1143 |
|
|
0 commit comments