|
1 | 1 | import {TestBed, async} from '@angular/core/testing';
|
2 |
| -import {Component} from '@angular/core'; |
3 |
| -import {MdMenuModule} from './menu'; |
| 2 | +import {Component, ViewChild} from '@angular/core'; |
| 3 | +import {By} from '@angular/platform-browser'; |
| 4 | +import {MdMenuModule, MdMenuTrigger} from './menu'; |
4 | 5 |
|
5 | 6 |
|
6 | 7 | describe('MdMenu', () => {
|
7 | 8 |
|
8 | 9 | beforeEach(async(() => {
|
9 | 10 | TestBed.configureTestingModule({
|
10 | 11 | imports: [MdMenuModule.forRoot()],
|
11 |
| - declarations: [TestMenu], |
| 12 | + declarations: [SimpleMenu], |
12 | 13 | });
|
13 | 14 |
|
14 | 15 | TestBed.compileComponents();
|
15 | 16 | }));
|
16 | 17 |
|
17 |
| - it('should add and remove focus class on focus/blur', () => { |
18 |
| - let fixture = TestBed.createComponent(TestMenu); |
19 |
| - expect(fixture).toBeTruthy(); |
| 18 | + it('should open the menu as an idempotent operation', () => { |
| 19 | + let fixture = TestBed.createComponent(SimpleMenu); |
| 20 | + fixture.detectChanges(); |
| 21 | + let menu = fixture.debugElement.query(By.css('.md-menu')); |
| 22 | + expect(menu).toBe(null); |
| 23 | + expect(() => { |
| 24 | + fixture.componentInstance.trigger.openMenu(); |
| 25 | + fixture.componentInstance.trigger.openMenu(); |
| 26 | + |
| 27 | + menu = fixture.debugElement.query(By.css('.md-menu')); |
| 28 | + expect(menu.nativeElement.innerHTML.trim()).toEqual('Content'); |
| 29 | + }).not.toThrowError(); |
20 | 30 | });
|
21 | 31 | });
|
22 | 32 |
|
23 |
| -@Component({template: ``}) |
24 |
| -class TestMenu {} |
| 33 | +@Component({ |
| 34 | + template: ` |
| 35 | + <button [md-menu-trigger-for]="menu">Toggle menu</button> |
| 36 | + <md-menu #menu="mdMenu"> |
| 37 | + Content |
| 38 | + </md-menu> |
| 39 | + ` |
| 40 | +}) |
| 41 | +class SimpleMenu { |
| 42 | + @ViewChild(MdMenuTrigger) trigger: MdMenuTrigger; |
| 43 | +} |
0 commit comments