Skip to content

test(material/menu): resolve test failures #20988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/material-experimental/mdc-menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,27 @@ describe('MDC-based MatMenu', () => {
expect(items.every(item => item.getAttribute('role') === 'menuitemcheckbox')).toBe(true);
});

it('should not change focus origin if origin not specified for menu items', () => {
const fixture = createComponent(MenuWithCheckboxItems);
fixture.detectChanges();
fixture.componentInstance.trigger.openMenu();
fixture.detectChanges();

let [firstMenuItemDebugEl, secondMenuItemDebugEl] =
fixture.debugElement.queryAll(By.css('.mat-mdc-menu-item'))!;

const firstMenuItemInstance = firstMenuItemDebugEl.componentInstance as MatMenuItem;
const secondMenuItemInstance = secondMenuItemDebugEl.componentInstance as MatMenuItem;

firstMenuItemDebugEl.nativeElement.blur();
firstMenuItemInstance.focus('mouse');
secondMenuItemDebugEl.nativeElement.blur();
secondMenuItemInstance.focus();

expect(secondMenuItemDebugEl.nativeElement.classList).toContain('cdk-focused');
expect(secondMenuItemDebugEl.nativeElement.classList).toContain('cdk-mouse-focused');
});

it('should not throw an error on destroy', () => {
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
expect(fixture.destroy.bind(fixture)).not.toThrow();
Expand Down Expand Up @@ -2028,6 +2049,23 @@ describe('MDC-based MatMenu', () => {
.toContain('mat-elevation-z4', 'Expected menu to have the proper updated elevation.');
}));

it('should not change focus origin if origin not specified for trigger', fakeAsync(() => {
compileTestComponent();

instance.levelOneTrigger.openMenu();
instance.levelOneTrigger.focus('mouse');
fixture.detectChanges();

instance.levelTwoTrigger.focus();
fixture.detectChanges();
tick(500);

const levelTwoTrigger = overlay.querySelector('#level-two-trigger')! as HTMLElement;

expect(levelTwoTrigger.classList).toContain('cdk-focused');
expect(levelTwoTrigger.classList).toContain('cdk-mouse-focused');
}));

// TODO(crisbeto): disabled until we've mapped our elevation to MDC's.
// tslint:disable-next-line:ban
xit('should not increase the elevation if the user specified a custom one', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/material/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,9 @@ describe('MatMenu', () => {
const firstMenuItemInstance = firstMenuItemDebugEl.componentInstance as MatMenuItem;
const secondMenuItemInstance = secondMenuItemDebugEl.componentInstance as MatMenuItem;

firstMenuItemDebugEl.nativeElement.blur();
firstMenuItemInstance.focus('mouse');
secondMenuItemDebugEl.nativeElement.blur();
secondMenuItemInstance.focus();

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

it('should not change focus origin if origin not specified for menu trigger',
fakeAsync(() => {
it('should not change focus origin if origin not specified for trigger', fakeAsync(() => {
compileTestComponent();

instance.levelOneTrigger.openMenu();
Expand Down