@@ -13,7 +13,41 @@ describe('uiStateRef', function() {
13
13
} ) ) ;
14
14
15
15
describe ( 'links' , function ( ) {
16
- var el , scope ;
16
+ var el , scope , document ;
17
+
18
+ beforeEach ( inject ( function ( $document ) {
19
+ document = $document [ 0 ] ;
20
+ } ) ) ;
21
+
22
+ function triggerClick ( el , options ) {
23
+ options = angular . extend ( {
24
+ metaKey : false ,
25
+ ctrlKey : false ,
26
+ shiftKey : false ,
27
+ altKey : false ,
28
+ button : 0
29
+ } , options || { } ) ;
30
+
31
+ var e = document . createEvent ( "MouseEvents" ) ;
32
+ e . initMouseEvent (
33
+ "click" , // typeArg of type DOMString, Specifies the event type.
34
+ true , // canBubbleArg of type boolean, Specifies whether or not the event can bubble.
35
+ true , // cancelableArg of type boolean, Specifies whether or not the event's default action can be prevented.
36
+ undefined , // viewArg of type views::AbstractView, Specifies the Event's AbstractView.
37
+ 0 , // detailArg of type long, Specifies the Event's mouse click count.
38
+ 0 , // screenXArg of type long, Specifies the Event's screen x coordinate
39
+ 0 , // screenYArg of type long, Specifies the Event's screen y coordinate
40
+ 0 , // clientXArg of type long, Specifies the Event's client x coordinate
41
+ 0 , // clientYArg of type long, Specifies the Event's client y coordinate
42
+ options . ctrlKey , // ctrlKeyArg of type boolean, Specifies whether or not control key was depressed during the Event.
43
+ options . altKey , // altKeyArg of type boolean, Specifies whether or not alt key was depressed during the Event.
44
+ options . shiftKey , // shiftKeyArg of type boolean, Specifies whether or not shift key was depressed during the Event.
45
+ options . metaKey , // metaKeyArg of type boolean, Specifies whether or not meta key was depressed during the Event.
46
+ options . button , // buttonArg of type unsigned short, Specifies the Event's mouse button.
47
+ null // relatedTargetArg of type EventTarget
48
+ ) ;
49
+ el [ 0 ] . dispatchEvent ( e ) ;
50
+ }
17
51
18
52
beforeEach ( inject ( function ( $rootScope , $compile ) {
19
53
el = angular . element ( '<a ui-sref="contacts.item.detail({ id: contact.id })">Details</a>' ) ;
@@ -27,66 +61,29 @@ describe('uiStateRef', function() {
27
61
28
62
29
63
it ( 'should generate the correct href' , function ( ) {
30
- expect ( el . attr ( 'href' ) ) . toBe ( '/contacts/5' ) ;
64
+ expect ( el . attr ( 'href' ) ) . toBe ( '# /contacts/5' ) ;
31
65
} ) ;
32
66
33
67
it ( 'should update the href when parameters change' , function ( ) {
34
- expect ( el . attr ( 'href' ) ) . toBe ( '/contacts/5' ) ;
68
+ expect ( el . attr ( 'href' ) ) . toBe ( '# /contacts/5' ) ;
35
69
scope . contact . id = 6 ;
36
70
scope . $apply ( ) ;
37
- expect ( el . attr ( 'href' ) ) . toBe ( '/contacts/6' ) ;
71
+ expect ( el . attr ( 'href' ) ) . toBe ( '# /contacts/6' ) ;
38
72
} ) ;
39
73
40
74
it ( 'should transition states when left-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
41
75
expect ( $state . $current . name ) . toEqual ( '' ) ;
42
76
43
- var e = $document [ 0 ] . createEvent ( "MouseEvents" ) ;
44
- e . initMouseEvent (
45
- "click" , // typeArg of type DOMString, Specifies the event type.
46
- true , // canBubbleArg of type boolean, Specifies whether or not the event can bubble.
47
- true , // cancelableArg of type boolean, Specifies whether or not the event's default action can be prevented.
48
- undefined , // viewArg of type views::AbstractView, Specifies the Event's AbstractView.
49
- 0 , // detailArg of type long, Specifies the Event's mouse click count.
50
- 0 , // screenXArg of type long, Specifies the Event's screen x coordinate
51
- 0 , // screenYArg of type long, Specifies the Event's screen y coordinate
52
- 0 , // clientXArg of type long, Specifies the Event's client x coordinate
53
- 0 , // clientYArg of type long, Specifies the Event's client y coordinate
54
- false , // ctrlKeyArg of type boolean, Specifies whether or not control key was depressed during the Event.
55
- false , // altKeyArg of type boolean, Specifies whether or not alt key was depressed during the Event.
56
- false , // shiftKeyArg of type boolean, Specifies whether or not shift key was depressed during the Event.
57
- false , // metaKeyArg of type boolean, Specifies whether or not meta key was depressed during the Event.
58
- 0 , // buttonArg of type unsigned short, Specifies the Event's mouse button.
59
- null // relatedTargetArg of type EventTarget
60
- ) ;
61
- el [ 0 ] . dispatchEvent ( e ) ;
62
-
77
+ triggerClick ( el ) ;
63
78
$q . flush ( ) ;
79
+
64
80
expect ( $state . current . name ) . toEqual ( 'contacts.item.detail' ) ;
65
81
expect ( $stateParams ) . toEqual ( { id : "5" } ) ;
66
82
} ) ) ;
67
83
68
84
it ( 'should not transition states when ctrl-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
69
85
expect ( $state . $current . name ) . toEqual ( '' ) ;
70
-
71
- var e = $document [ 0 ] . createEvent ( "MouseEvents" ) ;
72
- e . initMouseEvent (
73
- "click" , // typeArg of type DOMString, Specifies the event type.
74
- true , // canBubbleArg of type boolean, Specifies whether or not the event can bubble.
75
- true , // cancelableArg of type boolean, Specifies whether or not the event's default action can be prevented.
76
- undefined , // viewArg of type views::AbstractView, Specifies the Event's AbstractView.
77
- 0 , // detailArg of type long, Specifies the Event's mouse click count.
78
- 0 , // screenXArg of type long, Specifies the Event's screen x coordinate
79
- 0 , // screenYArg of type long, Specifies the Event's screen y coordinate
80
- 0 , // clientXArg of type long, Specifies the Event's client x coordinate
81
- 0 , // clientYArg of type long, Specifies the Event's client y coordinate
82
- true , // ctrlKeyArg of type boolean, Specifies whether or not control key was depressed during the Event.
83
- false , // altKeyArg of type boolean, Specifies whether or not alt key was depressed during the Event.
84
- false , // shiftKeyArg of type boolean, Specifies whether or not shift key was depressed during the Event.
85
- false , // metaKeyArg of type boolean, Specifies whether or not meta key was depressed during the Event.
86
- 0 , // buttonArg of type unsigned short, Specifies the Event's mouse button.
87
- null // relatedTargetArg of type EventTarget
88
- ) ;
89
- el [ 0 ] . dispatchEvent ( e ) ;
86
+ triggerClick ( el , { ctrlKey : true } ) ;
90
87
91
88
$q . flush ( ) ;
92
89
expect ( $state . current . name ) . toEqual ( '' ) ;
@@ -96,83 +93,29 @@ describe('uiStateRef', function() {
96
93
it ( 'should not transition states when meta-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
97
94
expect ( $state . $current . name ) . toEqual ( '' ) ;
98
95
99
- var e = $document [ 0 ] . createEvent ( "MouseEvents" ) ;
100
- e . initMouseEvent (
101
- "click" , // typeArg of type DOMString, Specifies the event type.
102
- true , // canBubbleArg of type boolean, Specifies whether or not the event can bubble.
103
- true , // cancelableArg of type boolean, Specifies whether or not the event's default action can be prevented.
104
- undefined , // viewArg of type views::AbstractView, Specifies the Event's AbstractView.
105
- 0 , // detailArg of type long, Specifies the Event's mouse click count.
106
- 0 , // screenXArg of type long, Specifies the Event's screen x coordinate
107
- 0 , // screenYArg of type long, Specifies the Event's screen y coordinate
108
- 0 , // clientXArg of type long, Specifies the Event's client x coordinate
109
- 0 , // clientYArg of type long, Specifies the Event's client y coordinate
110
- false , // ctrlKeyArg of type boolean, Specifies whether or not control key was depressed during the Event.
111
- false , // altKeyArg of type boolean, Specifies whether or not alt key was depressed during the Event.
112
- false , // shiftKeyArg of type boolean, Specifies whether or not shift key was depressed during the Event.
113
- true , // metaKeyArg of type boolean, Specifies whether or not meta key was depressed during the Event.
114
- 0 , // buttonArg of type unsigned short, Specifies the Event's mouse button.
115
- null // relatedTargetArg of type EventTarget
116
- ) ;
117
- el [ 0 ] . dispatchEvent ( e ) ;
118
-
96
+ triggerClick ( el , { metaKey : true } ) ;
119
97
$q . flush ( ) ;
98
+
120
99
expect ( $state . current . name ) . toEqual ( '' ) ;
121
100
expect ( $stateParams ) . toEqual ( { id : "5" } ) ;
122
101
} ) ) ;
123
102
124
103
it ( 'should not transition states when shift-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
125
104
expect ( $state . $current . name ) . toEqual ( '' ) ;
126
105
127
- var e = $document [ 0 ] . createEvent ( "MouseEvents" ) ;
128
- e . initMouseEvent (
129
- "click" , // typeArg of type DOMString, Specifies the event type.
130
- true , // canBubbleArg of type boolean, Specifies whether or not the event can bubble.
131
- true , // cancelableArg of type boolean, Specifies whether or not the event's default action can be prevented.
132
- undefined , // viewArg of type views::AbstractView, Specifies the Event's AbstractView.
133
- 0 , // detailArg of type long, Specifies the Event's mouse click count.
134
- 0 , // screenXArg of type long, Specifies the Event's screen x coordinate
135
- 0 , // screenYArg of type long, Specifies the Event's screen y coordinate
136
- 0 , // clientXArg of type long, Specifies the Event's client x coordinate
137
- 0 , // clientYArg of type long, Specifies the Event's client y coordinate
138
- false , // ctrlKeyArg of type boolean, Specifies whether or not control key was depressed during the Event.
139
- false , // altKeyArg of type boolean, Specifies whether or not alt key was depressed during the Event.
140
- true , // shiftKeyArg of type boolean, Specifies whether or not shift key was depressed during the Event.
141
- false , // metaKeyArg of type boolean, Specifies whether or not meta key was depressed during the Event.
142
- 0 , // buttonArg of type unsigned short, Specifies the Event's mouse button.
143
- null // relatedTargetArg of type EventTarget
144
- ) ;
145
- el [ 0 ] . dispatchEvent ( e ) ;
146
-
106
+ triggerClick ( el , { shiftKey : true } ) ;
147
107
$q . flush ( ) ;
108
+
148
109
expect ( $state . current . name ) . toEqual ( '' ) ;
149
110
expect ( $stateParams ) . toEqual ( { id : "5" } ) ;
150
111
} ) ) ;
151
112
152
113
it ( 'should not transition states when middle-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
153
114
expect ( $state . $current . name ) . toEqual ( '' ) ;
154
115
155
- var e = $document [ 0 ] . createEvent ( "MouseEvents" ) ;
156
- e . initMouseEvent (
157
- "click" , // typeArg of type DOMString, Specifies the event type.
158
- true , // canBubbleArg of type boolean, Specifies whether or not the event can bubble.
159
- true , // cancelableArg of type boolean, Specifies whether or not the event's default action can be prevented.
160
- undefined , // viewArg of type views::AbstractView, Specifies the Event's AbstractView.
161
- 0 , // detailArg of type long, Specifies the Event's mouse click count.
162
- 0 , // screenXArg of type long, Specifies the Event's screen x coordinate
163
- 0 , // screenYArg of type long, Specifies the Event's screen y coordinate
164
- 0 , // clientXArg of type long, Specifies the Event's client x coordinate
165
- 0 , // clientYArg of type long, Specifies the Event's client y coordinate
166
- false , // ctrlKeyArg of type boolean, Specifies whether or not control key was depressed during the Event.
167
- false , // altKeyArg of type boolean, Specifies whether or not alt key was depressed during the Event.
168
- false , // shiftKeyArg of type boolean, Specifies whether or not shift key was depressed during the Event.
169
- false , // metaKeyArg of type boolean, Specifies whether or not meta key was depressed during the Event.
170
- 1 , // buttonArg of type unsigned short, Specifies the Event's mouse button.
171
- null // relatedTargetArg of type EventTarget
172
- ) ;
173
- el [ 0 ] . dispatchEvent ( e ) ;
174
-
116
+ triggerClick ( el , { button : 1 } ) ;
175
117
$q . flush ( ) ;
118
+
176
119
expect ( $state . current . name ) . toEqual ( '' ) ;
177
120
expect ( $stateParams ) . toEqual ( { id : "5" } ) ;
178
121
} ) ) ;
@@ -192,7 +135,7 @@ describe('uiStateRef', function() {
192
135
} ) ) ;
193
136
194
137
it ( 'should generate the correct action' , function ( ) {
195
- expect ( el . attr ( 'action' ) ) . toBe ( '/contacts/5' ) ;
138
+ expect ( el . attr ( 'action' ) ) . toBe ( '# /contacts/5' ) ;
196
139
} ) ;
197
140
} ) ;
198
141
} ) ;
0 commit comments