@@ -5,8 +5,8 @@ describe('uiStateRef', function() {
5
5
beforeEach ( module ( 'ui.router' ) ) ;
6
6
7
7
beforeEach ( module ( function ( $stateProvider ) {
8
- $stateProvider . state ( 'index ' , {
9
- url : '/ '
8
+ $stateProvider . state ( 'top ' , {
9
+ url : ''
10
10
} ) . state ( 'contacts' , {
11
11
url : '/contacts' ,
12
12
template : '<a ui-sref=".item({ id: 5 })" class="item">Person</a> <ui-view></ui-view>'
@@ -75,15 +75,17 @@ describe('uiStateRef', function() {
75
75
} ) ;
76
76
77
77
describe ( 'links' , function ( ) {
78
- var timeoutFlush ;
78
+ var timeoutFlush , el2 ;
79
79
80
80
beforeEach ( inject ( function ( $rootScope , $compile , $timeout ) {
81
81
el = angular . element ( '<a ui-sref="contacts.item.detail({ id: contact.id })">Details</a>' ) ;
82
+ el2 = angular . element ( '<a ui-sref="top">Top</a>' ) ;
82
83
scope = $rootScope ;
83
84
scope . contact = { id : 5 } ;
84
85
scope . $apply ( ) ;
85
86
86
87
$compile ( el ) ( scope ) ;
88
+ $compile ( el2 ) ( scope ) ;
87
89
scope . $digest ( ) ;
88
90
89
91
timeoutFlush = function ( ) {
@@ -98,6 +100,7 @@ describe('uiStateRef', function() {
98
100
99
101
it ( 'should generate the correct href' , function ( ) {
100
102
expect ( el . attr ( 'href' ) ) . toBe ( '#/contacts/5' ) ;
103
+ expect ( el2 . attr ( 'href' ) ) . toBe ( '#' ) ;
101
104
} ) ;
102
105
103
106
it ( 'should update the href when parameters change' , function ( ) {
@@ -118,7 +121,7 @@ describe('uiStateRef', function() {
118
121
} ) ) ;
119
122
120
123
it ( 'should transition states when left-clicked' , inject ( function ( $state , $stateParams , $q ) {
121
- expect ( $state . $current . name ) . toEqual ( '' ) ;
124
+ expect ( $state . $current . name ) . toEqual ( 'top ' ) ;
122
125
123
126
triggerClick ( el ) ;
124
127
timeoutFlush ( ) ;
@@ -129,7 +132,7 @@ describe('uiStateRef', function() {
129
132
} ) ) ;
130
133
131
134
it ( 'should transition when given a click that contains no data (fake-click)' , inject ( function ( $state , $stateParams , $q ) {
132
- expect ( $state . current . name ) . toEqual ( '' ) ;
135
+ expect ( $state . current . name ) . toEqual ( 'top ' ) ;
133
136
134
137
triggerClick ( el , {
135
138
metaKey : undefined ,
@@ -146,63 +149,63 @@ describe('uiStateRef', function() {
146
149
} ) ) ;
147
150
148
151
it ( 'should not transition states when ctrl-clicked' , inject ( function ( $state , $stateParams , $q ) {
149
- expect ( $state . $current . name ) . toEqual ( '' ) ;
152
+ expect ( $state . $current . name ) . toEqual ( 'top ' ) ;
150
153
triggerClick ( el , { ctrlKey : true } ) ;
151
154
152
155
timeoutFlush ( ) ;
153
156
$q . flush ( ) ;
154
157
155
- expect ( $state . current . name ) . toEqual ( '' ) ;
156
- expect ( $stateParams ) . toEqual ( { id : 5 } ) ;
158
+ expect ( $state . current . name ) . toEqual ( 'top ' ) ;
159
+ expect ( $stateParams ) . toEqualData ( { } ) ;
157
160
} ) ) ;
158
161
159
162
it ( 'should not transition states when meta-clicked' , inject ( function ( $state , $stateParams , $q ) {
160
- expect ( $state . $current . name ) . toEqual ( '' ) ;
163
+ expect ( $state . $current . name ) . toEqual ( 'top ' ) ;
161
164
162
165
triggerClick ( el , { metaKey : true } ) ;
163
166
timeoutFlush ( ) ;
164
167
$q . flush ( ) ;
165
168
166
- expect ( $state . current . name ) . toEqual ( '' ) ;
167
- expect ( $stateParams ) . toEqual ( { id : 5 } ) ;
169
+ expect ( $state . current . name ) . toEqual ( 'top ' ) ;
170
+ expect ( $stateParams ) . toEqualData ( { } ) ;
168
171
} ) ) ;
169
172
170
173
it ( 'should not transition states when shift-clicked' , inject ( function ( $state , $stateParams , $q ) {
171
- expect ( $state . $current . name ) . toEqual ( '' ) ;
174
+ expect ( $state . $current . name ) . toEqual ( 'top ' ) ;
172
175
173
176
triggerClick ( el , { shiftKey : true } ) ;
174
177
timeoutFlush ( ) ;
175
178
$q . flush ( ) ;
176
179
177
- expect ( $state . current . name ) . toEqual ( '' ) ;
178
- expect ( $stateParams ) . toEqual ( { id : 5 } ) ;
180
+ expect ( $state . current . name ) . toEqual ( 'top ' ) ;
181
+ expect ( $stateParams ) . toEqualData ( { } ) ;
179
182
} ) ) ;
180
183
181
184
it ( 'should not transition states when middle-clicked' , inject ( function ( $state , $stateParams , $q ) {
182
- expect ( $state . $current . name ) . toEqual ( '' ) ;
185
+ expect ( $state . $current . name ) . toEqual ( 'top ' ) ;
183
186
184
187
triggerClick ( el , { button : 1 } ) ;
185
188
timeoutFlush ( ) ;
186
189
$q . flush ( ) ;
187
190
188
- expect ( $state . current . name ) . toEqual ( '' ) ;
189
- expect ( $stateParams ) . toEqual ( { id : 5 } ) ;
191
+ expect ( $state . current . name ) . toEqual ( 'top ' ) ;
192
+ expect ( $stateParams ) . toEqualData ( { } ) ;
190
193
} ) ) ;
191
194
192
195
it ( 'should not transition states when element has target specified' , inject ( function ( $state , $stateParams , $q ) {
193
196
el . attr ( 'target' , '_blank' ) ;
194
- expect ( $state . $current . name ) . toEqual ( '' ) ;
197
+ expect ( $state . $current . name ) . toEqual ( 'top ' ) ;
195
198
196
199
triggerClick ( el ) ;
197
200
timeoutFlush ( ) ;
198
201
$q . flush ( ) ;
199
202
200
- expect ( $state . current . name ) . toEqual ( '' ) ;
201
- expect ( $stateParams ) . toEqual ( { id : 5 } ) ;
203
+ expect ( $state . current . name ) . toEqual ( 'top ' ) ;
204
+ expect ( $stateParams ) . toEqualData ( { } ) ;
202
205
} ) ) ;
203
206
204
207
it ( 'should not transition states if preventDefault() is called in click handler' , inject ( function ( $state , $stateParams , $q ) {
205
- expect ( $state . $current . name ) . toEqual ( '' ) ;
208
+ expect ( $state . $current . name ) . toEqual ( 'top ' ) ;
206
209
el . bind ( 'click' , function ( e ) {
207
210
e . preventDefault ( ) ;
208
211
} ) ;
@@ -211,8 +214,8 @@ describe('uiStateRef', function() {
211
214
timeoutFlush ( ) ;
212
215
$q . flush ( ) ;
213
216
214
- expect ( $state . current . name ) . toEqual ( '' ) ;
215
- expect ( $stateParams ) . toEqual ( { id : 5 } ) ;
217
+ expect ( $state . current . name ) . toEqual ( 'top ' ) ;
218
+ expect ( $stateParams ) . toEqualData ( { } ) ;
216
219
} ) ) ;
217
220
218
221
it ( 'should allow passing params to current state' , inject ( function ( $compile , $rootScope , $state ) {
@@ -345,8 +348,8 @@ describe('uiSrefActive', function() {
345
348
beforeEach ( module ( 'ui.router' ) ) ;
346
349
347
350
beforeEach ( module ( function ( $stateProvider ) {
348
- $stateProvider . state ( 'index ' , {
349
- url : '' ,
351
+ $stateProvider . state ( 'top ' , {
352
+ url : ''
350
353
} ) . state ( 'contacts' , {
351
354
url : '/contacts' ,
352
355
views : {
0 commit comments