1
- describe ( 'material.components.menu' , function ( ) {
1
+ ddescribe ( 'material.components.menu' , function ( ) {
2
2
var attachedElements = [ ] ;
3
3
var $mdMenu , $timeout , menuActionPerformed , $mdUtil ;
4
4
@@ -7,7 +7,7 @@ describe('material.components.menu', function() {
7
7
$mdUtil = _$mdUtil_ ;
8
8
$mdMenu = _$mdMenu_ ;
9
9
$timeout = _$timeout_ ;
10
- var abandonedMenus = $document [ 0 ] . querySelectorAll ( '.md-menu-container' ) ;
10
+ var abandonedMenus = $document [ 0 ] . querySelectorAll ( '.md-open- menu-container' ) ;
11
11
angular . element ( abandonedMenus ) . remove ( ) ;
12
12
} ) ) ;
13
13
afterEach ( function ( ) {
@@ -41,6 +41,23 @@ describe('material.components.menu', function() {
41
41
expect ( getOpenMenuContainer ( menu ) . length ) . toBe ( 0 ) ;
42
42
} ) ;
43
43
44
+ it ( 'cleans up an open menu when the element leaves the DOM' , function ( ) {
45
+ var menu = setup ( ) ;
46
+ openMenu ( menu ) ;
47
+ menu . remove ( ) ;
48
+ expect ( getOpenMenuContainer ( menu ) . length ) . toBe ( 0 ) ;
49
+ } ) ;
50
+
51
+ it ( 'sets up proper aria-owns and aria-haspopup relations between the button and the container' , function ( ) {
52
+ var menu = setup ( ) ;
53
+ var button = menu [ 0 ] . querySelector ( 'button' ) ;
54
+ expect ( button . hasAttribute ( 'aria-haspopup' ) ) . toBe ( true ) ;
55
+ expect ( button . hasAttribute ( 'aria-owns' ) ) . toBe ( true ) ;
56
+ var ownsId = button . getAttribute ( 'aria-owns' ) ;
57
+ openMenu ( menu ) ;
58
+ expect ( getOpenMenuContainer ( menu ) . attr ( 'id' ) ) . toBe ( ownsId ) ;
59
+ } ) ;
60
+
44
61
it ( 'opens on click without $event' , function ( ) {
45
62
var noEvent = true ;
46
63
var menu = setup ( 'ng-click' , noEvent ) ;
@@ -98,7 +115,7 @@ describe('material.components.menu', function() {
98
115
openMenu ( menu ) ;
99
116
expect ( getOpenMenuContainer ( menu ) . length ) . toBe ( 1 ) ;
100
117
101
- var openMenuEl = menu [ 0 ] . querySelector ( 'md-menu-content' ) ;
118
+ var openMenuEl = $document [ 0 ] . querySelector ( 'md-menu-content' ) ;
102
119
103
120
pressKey ( openMenuEl , $mdConstant . KEY_CODE . ESCAPE ) ;
104
121
waitForMenuClose ( ) ;
@@ -197,21 +214,22 @@ describe('material.components.menu', function() {
197
214
// ********************************************
198
215
199
216
function getOpenMenuContainer ( el ) {
217
+ var res ;
200
218
el = ( el instanceof angular . element ) ? el [ 0 ] : el ;
201
- var container = el . querySelector ( '.md-open-menu-container' ) ;
202
- if ( container . style . display == 'none' ) {
203
- return angular . element ( [ ] ) ;
204
- } else {
205
- return angular . element ( container ) ;
206
- }
219
+ inject ( function ( $document ) {
220
+ var container = $document [ 0 ] . querySelector ( '.md-open-menu-container' ) ;
221
+ if ( container && container . style . display == 'none' ) {
222
+ res = [ ] ;
223
+ } else {
224
+ res = angular . element ( container ) ;
225
+ }
226
+ } ) ;
227
+ return res ;
207
228
}
208
229
209
230
function openMenu ( el , triggerType ) {
210
- inject ( function ( $document ) {
211
- el . children ( ) . eq ( 0 ) . triggerHandler ( triggerType || 'click' ) ;
212
- $document [ 0 ] . body . appendChild ( el [ 0 ] ) ;
213
- waitForMenuOpen ( ) ;
214
- } ) ;
231
+ el . children ( ) . eq ( 0 ) . triggerHandler ( triggerType || 'click' ) ;
232
+ waitForMenuOpen ( ) ;
215
233
}
216
234
217
235
function closeMenu ( ) {
0 commit comments