@@ -13,7 +13,41 @@ describe('uiStateRef', function() {
1313 } ) ) ;
1414
1515 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+ }
1751
1852 beforeEach ( inject ( function ( $rootScope , $compile ) {
1953 el = angular . element ( '<a ui-sref="contacts.item.detail({ id: contact.id })">Details</a>' ) ;
@@ -27,66 +61,29 @@ describe('uiStateRef', function() {
2761
2862
2963 it ( 'should generate the correct href' , function ( ) {
30- expect ( el . attr ( 'href' ) ) . toBe ( '/contacts/5' ) ;
64+ expect ( el . attr ( 'href' ) ) . toBe ( '# /contacts/5' ) ;
3165 } ) ;
3266
3367 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' ) ;
3569 scope . contact . id = 6 ;
3670 scope . $apply ( ) ;
37- expect ( el . attr ( 'href' ) ) . toBe ( '/contacts/6' ) ;
71+ expect ( el . attr ( 'href' ) ) . toBe ( '# /contacts/6' ) ;
3872 } ) ;
3973
4074 it ( 'should transition states when left-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
4175 expect ( $state . $current . name ) . toEqual ( '' ) ;
4276
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 ) ;
6378 $q . flush ( ) ;
79+
6480 expect ( $state . current . name ) . toEqual ( 'contacts.item.detail' ) ;
6581 expect ( $stateParams ) . toEqual ( { id : "5" } ) ;
6682 } ) ) ;
6783
6884 it ( 'should not transition states when ctrl-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
6985 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 } ) ;
9087
9188 $q . flush ( ) ;
9289 expect ( $state . current . name ) . toEqual ( '' ) ;
@@ -96,83 +93,29 @@ describe('uiStateRef', function() {
9693 it ( 'should not transition states when meta-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
9794 expect ( $state . $current . name ) . toEqual ( '' ) ;
9895
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 } ) ;
11997 $q . flush ( ) ;
98+
12099 expect ( $state . current . name ) . toEqual ( '' ) ;
121100 expect ( $stateParams ) . toEqual ( { id : "5" } ) ;
122101 } ) ) ;
123102
124103 it ( 'should not transition states when shift-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
125104 expect ( $state . $current . name ) . toEqual ( '' ) ;
126105
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 } ) ;
147107 $q . flush ( ) ;
108+
148109 expect ( $state . current . name ) . toEqual ( '' ) ;
149110 expect ( $stateParams ) . toEqual ( { id : "5" } ) ;
150111 } ) ) ;
151112
152113 it ( 'should not transition states when middle-clicked' , inject ( function ( $state , $stateParams , $document , $q ) {
153114 expect ( $state . $current . name ) . toEqual ( '' ) ;
154115
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 } ) ;
175117 $q . flush ( ) ;
118+
176119 expect ( $state . current . name ) . toEqual ( '' ) ;
177120 expect ( $stateParams ) . toEqual ( { id : "5" } ) ;
178121 } ) ) ;
@@ -192,7 +135,7 @@ describe('uiStateRef', function() {
192135 } ) ) ;
193136
194137 it ( 'should generate the correct action' , function ( ) {
195- expect ( el . attr ( 'action' ) ) . toBe ( '/contacts/5' ) ;
138+ expect ( el . attr ( 'action' ) ) . toBe ( '# /contacts/5' ) ;
196139 } ) ;
197140 } ) ;
198141} ) ;
0 commit comments