Skip to content

Commit 488895b

Browse files
authored
test(material/menu): resolve test failures (#20988)
Fixes some test failures that were in master. Also adds some missing tests to the MDC menu.
1 parent db7ff98 commit 488895b

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/material-experimental/mdc-menu/menu.spec.ts

+38
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,27 @@ describe('MDC-based MatMenu', () => {
617617
expect(items.every(item => item.getAttribute('role') === 'menuitemcheckbox')).toBe(true);
618618
});
619619

620+
it('should not change focus origin if origin not specified for menu items', () => {
621+
const fixture = createComponent(MenuWithCheckboxItems);
622+
fixture.detectChanges();
623+
fixture.componentInstance.trigger.openMenu();
624+
fixture.detectChanges();
625+
626+
let [firstMenuItemDebugEl, secondMenuItemDebugEl] =
627+
fixture.debugElement.queryAll(By.css('.mat-mdc-menu-item'))!;
628+
629+
const firstMenuItemInstance = firstMenuItemDebugEl.componentInstance as MatMenuItem;
630+
const secondMenuItemInstance = secondMenuItemDebugEl.componentInstance as MatMenuItem;
631+
632+
firstMenuItemDebugEl.nativeElement.blur();
633+
firstMenuItemInstance.focus('mouse');
634+
secondMenuItemDebugEl.nativeElement.blur();
635+
secondMenuItemInstance.focus();
636+
637+
expect(secondMenuItemDebugEl.nativeElement.classList).toContain('cdk-focused');
638+
expect(secondMenuItemDebugEl.nativeElement.classList).toContain('cdk-mouse-focused');
639+
});
640+
620641
it('should not throw an error on destroy', () => {
621642
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
622643
expect(fixture.destroy.bind(fixture)).not.toThrow();
@@ -2028,6 +2049,23 @@ describe('MDC-based MatMenu', () => {
20282049
.toContain('mat-elevation-z4', 'Expected menu to have the proper updated elevation.');
20292050
}));
20302051

2052+
it('should not change focus origin if origin not specified for trigger', fakeAsync(() => {
2053+
compileTestComponent();
2054+
2055+
instance.levelOneTrigger.openMenu();
2056+
instance.levelOneTrigger.focus('mouse');
2057+
fixture.detectChanges();
2058+
2059+
instance.levelTwoTrigger.focus();
2060+
fixture.detectChanges();
2061+
tick(500);
2062+
2063+
const levelTwoTrigger = overlay.querySelector('#level-two-trigger')! as HTMLElement;
2064+
2065+
expect(levelTwoTrigger.classList).toContain('cdk-focused');
2066+
expect(levelTwoTrigger.classList).toContain('cdk-mouse-focused');
2067+
}));
2068+
20312069
// TODO(crisbeto): disabled until we've mapped our elevation to MDC's.
20322070
// tslint:disable-next-line:ban
20332071
xit('should not increase the elevation if the user specified a custom one', () => {

src/material/menu/menu.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,9 @@ describe('MatMenu', () => {
627627
const firstMenuItemInstance = firstMenuItemDebugEl.componentInstance as MatMenuItem;
628628
const secondMenuItemInstance = secondMenuItemDebugEl.componentInstance as MatMenuItem;
629629

630+
firstMenuItemDebugEl.nativeElement.blur();
630631
firstMenuItemInstance.focus('mouse');
632+
secondMenuItemDebugEl.nativeElement.blur();
631633
secondMenuItemInstance.focus();
632634

633635
expect(secondMenuItemDebugEl.nativeElement.classList).toContain('cdk-focused');
@@ -2028,8 +2030,7 @@ describe('MatMenu', () => {
20282030
.toContain('mat-elevation-z4', 'Expected menu to have the proper updated elevation.');
20292031
}));
20302032

2031-
it('should not change focus origin if origin not specified for menu trigger',
2032-
fakeAsync(() => {
2033+
it('should not change focus origin if origin not specified for trigger', fakeAsync(() => {
20332034
compileTestComponent();
20342035

20352036
instance.levelOneTrigger.openMenu();

0 commit comments

Comments
 (0)