-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(menu): make menu open idempotent (#1478)
- Loading branch information
Showing
2 changed files
with
32 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,43 @@ | ||
import {TestBed, async} from '@angular/core/testing'; | ||
import {Component} from '@angular/core'; | ||
import {MdMenuModule} from './menu'; | ||
import {Component, ViewChild} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import {MdMenuModule, MdMenuTrigger} from './menu'; | ||
|
||
|
||
describe('MdMenu', () => { | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdMenuModule.forRoot()], | ||
declarations: [TestMenu], | ||
declarations: [SimpleMenu], | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
it('should add and remove focus class on focus/blur', () => { | ||
let fixture = TestBed.createComponent(TestMenu); | ||
expect(fixture).toBeTruthy(); | ||
it('should open the menu as an idempotent operation', () => { | ||
let fixture = TestBed.createComponent(SimpleMenu); | ||
fixture.detectChanges(); | ||
let menu = fixture.debugElement.query(By.css('.md-menu')); | ||
expect(menu).toBe(null); | ||
expect(() => { | ||
fixture.componentInstance.trigger.openMenu(); | ||
fixture.componentInstance.trigger.openMenu(); | ||
|
||
menu = fixture.debugElement.query(By.css('.md-menu')); | ||
expect(menu.nativeElement.innerHTML.trim()).toEqual('Content'); | ||
}).not.toThrowError(); | ||
}); | ||
}); | ||
|
||
@Component({template: ``}) | ||
class TestMenu {} | ||
@Component({ | ||
template: ` | ||
<button [md-menu-trigger-for]="menu">Toggle menu</button> | ||
<md-menu #menu="mdMenu"> | ||
Content | ||
</md-menu> | ||
` | ||
}) | ||
class SimpleMenu { | ||
@ViewChild(MdMenuTrigger) trigger: MdMenuTrigger; | ||
} |