1
1
describe ( 'dropdownToggle' , function ( ) {
2
- var $compile , $rootScope , $document , $location ;
2
+ var $compile , $rootScope , $document , $location , elm , toggleElm , targetElm ;
3
3
4
4
beforeEach ( module ( 'mm.foundation.dropdownToggle' ) ) ;
5
5
@@ -8,6 +8,7 @@ describe('dropdownToggle', function() {
8
8
$rootScope = _$rootScope_ ;
9
9
$document = _$document_ ;
10
10
$location = _$location_ ;
11
+ $scope = $rootScope . $new ( ) ;
11
12
12
13
} ) ) ;
13
14
@@ -19,53 +20,66 @@ describe('dropdownToggle', function() {
19
20
'<div><a dropdown-toggle="#' + id + '">Trigger</a>' +
20
21
'<ul id="' + id + '"><li>Hello</li></ul></div>'
21
22
) . appendTo ( 'body' ) ;
22
- return $compile ( element ) ( $rootScope ) ;
23
+ return $compile ( element ) ( $scope ) ;
23
24
}
24
25
25
- it ( 'should toggle on `a` click' , function ( ) {
26
- var elm = dropdown ( ) ;
27
- expect ( elm . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'none' ) ;
28
- elm . find ( 'a' ) . click ( ) ;
29
- expect ( elm . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'block' ) ;
30
- elm . find ( 'a' ) . click ( ) ;
31
- expect ( elm . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'none' ) ;
32
- elm . remove ( ) ;
26
+ afterEach ( function ( ) {
27
+ if ( elm ) {
28
+ elm . remove ( ) ;
29
+ }
33
30
} ) ;
34
31
35
- it ( 'should close on elm click' , function ( ) {
36
- var elm = dropdown ( ) ;
37
- elm . find ( 'a' ) . click ( ) ;
38
- elm . click ( ) ;
39
- expect ( elm . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'none' ) ;
40
- elm . remove ( ) ;
41
- } ) ;
32
+ describe ( 'with a single dropdown' , function ( ) {
33
+ beforeEach ( function ( ) {
34
+ elm = dropdown ( ) ;
35
+ toggleElm = elm . find ( 'a' ) ;
36
+ targetElm = elm . find ( 'ul' ) ;
37
+ } ) ;
42
38
43
- it ( 'should close on document click' , function ( ) {
44
- var elm = dropdown ( ) ;
45
- elm . find ( 'a' ) . click ( ) ;
46
- $document . click ( ) ;
47
- expect ( elm . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'none' ) ;
48
- elm . remove ( ) ;
49
- } ) ;
39
+ it ( 'should initially hide the target element' , function ( ) {
40
+ expect ( targetElm . css ( 'display' ) ) . toBe ( 'none' ) ;
41
+ } ) ;
42
+
43
+ it ( 'should toggle on `a` click' , function ( ) {
44
+ expect ( targetElm . css ( 'display' ) ) . toBe ( 'none' ) ;
45
+ toggleElm . click ( ) ;
46
+ expect ( targetElm . css ( 'display' ) ) . toBe ( 'block' ) ;
47
+ toggleElm . click ( ) ;
48
+ expect ( targetElm . css ( 'display' ) ) . toBe ( 'none' ) ;
49
+ } ) ;
50
+
51
+ it ( 'should close on elm click' , function ( ) {
52
+ toggleElm . click ( ) ;
53
+ elm . click ( ) ;
54
+ expect ( targetElm . css ( 'display' ) ) . toBe ( 'none' ) ;
55
+ } ) ;
56
+
57
+ it ( 'should close on document click' , function ( ) {
58
+ toggleElm . click ( ) ;
59
+ expect ( targetElm . css ( 'display' ) ) . toBe ( 'block' ) ;
60
+ $document . click ( ) ;
61
+ expect ( targetElm . css ( 'display' ) ) . toBe ( 'none' ) ;
62
+ } ) ;
50
63
51
- it ( 'should close on $location change' , function ( ) {
52
- var elm = dropdown ( ) ;
53
- elm . find ( 'a' ) . click ( ) ;
54
- $location . path ( '/foo' ) ;
55
- $rootScope . $apply ( ) ;
56
- expect ( elm . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'none' ) ;
57
- elm . remove ( ) ;
64
+ it ( 'should close on $location change' , function ( ) {
65
+ toggleElm . click ( ) ;
66
+ $location . path ( '/foo' ) ;
67
+ $rootScope . $apply ( ) ;
68
+ expect ( targetElm . css ( 'display' ) ) . toBe ( 'none' ) ;
69
+ } ) ;
58
70
} ) ;
59
71
60
- it ( 'should only allow one dropdown to be open at once' , function ( ) {
61
- var elm1 = dropdown ( 'target1' ) ;
62
- var elm2 = dropdown ( 'target2' ) ;
63
- elm1 . find ( 'a' ) . click ( ) ;
64
- elm2 . find ( 'a' ) . click ( ) ;
65
- expect ( elm1 . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'none' ) ;
66
- expect ( elm2 . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'block' ) ;
67
- elm1 . remove ( ) ;
68
- elm2 . remove ( ) ;
72
+ describe ( 'with multiple dropdowns' , function ( ) {
73
+ it ( 'should only allow one dropdown to be open at once' , function ( ) {
74
+ var elm1 = dropdown ( 'target1' ) ;
75
+ var elm2 = dropdown ( 'target2' ) ;
76
+ elm1 . find ( 'a' ) . click ( ) ;
77
+ elm2 . find ( 'a' ) . click ( ) ;
78
+ expect ( elm1 . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'none' ) ;
79
+ expect ( elm2 . find ( 'ul' ) . css ( 'display' ) ) . toBe ( 'block' ) ;
80
+ elm1 . remove ( ) ;
81
+ elm2 . remove ( ) ;
82
+ } ) ;
69
83
} ) ;
70
84
} ) ;
71
85
0 commit comments