1
1
describe ( 'uiStateRef' , function ( ) {
2
2
3
- var el , scope , document ;
3
+ var el , template , scope , document ;
4
4
5
5
beforeEach ( module ( 'ui.router' ) ) ;
6
6
7
7
beforeEach ( module ( function ( $stateProvider ) {
8
8
$stateProvider . state ( 'index' , {
9
9
url : '/'
10
10
} ) . state ( 'contacts' , {
11
- url : '/contacts'
11
+ url : '/contacts' ,
12
+ template : '<a ui-sref=".item({ id: 5 })" class="item">Person</a> <ui-view></ui-view>'
12
13
} ) . state ( 'contacts.item' , {
13
- url : '/:id'
14
- } ) . state ( 'contacts.item.detail' , { } ) ;
14
+ url : '/:id' ,
15
+ template : '<a ui-sref=".detail" class="item-detail">Detail</a> | <a ui-sref="^" class="item-parent">Parent</a> | <ui-view></ui-view>'
16
+ } ) . state ( 'contacts.item.detail' , {
17
+ template : '<div class="title">Detail</div> | <a ui-sref="^" class="item-parent2">Item</a>'
18
+ } ) ;
15
19
} ) ) ;
16
20
17
21
beforeEach ( inject ( function ( $document ) {
@@ -148,6 +152,7 @@ describe('uiStateRef', function() {
148
152
scope . $apply ( ) ;
149
153
150
154
$compile ( el ) ( scope ) ;
155
+ template = $compile ( angular . element ( '<ui-view></ui-view>' ) ) ( scope ) ;
151
156
scope . $digest ( ) ;
152
157
} ) ) ;
153
158
@@ -158,5 +163,32 @@ describe('uiStateRef', function() {
158
163
expect ( $state . $current . name ) . toBe ( "contacts.item.detail" ) ;
159
164
expect ( $state . params ) . toEqual ( { id : '5' } ) ;
160
165
} ) ) ;
166
+
167
+ it ( 'should resolve states from parent uiView' , inject ( function ( $state , $stateParams , $q ) {
168
+ $state . transitionTo ( 'contacts' ) ;
169
+ $q . flush ( ) ;
170
+
171
+ var parentToChild = angular . element ( template [ 0 ] . querySelector ( 'a.item' ) ) ;
172
+ triggerClick ( parentToChild ) ;
173
+ $q . flush ( ) ;
174
+
175
+ var childToGrandchild = angular . element ( template [ 0 ] . querySelector ( 'a.item-detail' ) ) ;
176
+ var childToParent = angular . element ( template [ 0 ] . querySelector ( 'a.item-parent' ) ) ;
177
+
178
+ triggerClick ( childToGrandchild ) ;
179
+ $q . flush ( ) ;
180
+
181
+ var grandchildToParent = angular . element ( template [ 0 ] . querySelector ( 'a.item-parent2' ) ) ;
182
+ expect ( $state . $current . name ) . toBe ( "contacts.item.detail" )
183
+
184
+ triggerClick ( grandchildToParent ) ;
185
+ $q . flush ( ) ;
186
+ expect ( $state . $current . name ) . toBe ( "contacts.item" ) ;
187
+
188
+ $state . transitionTo ( "contacts.item.detail" , { id : 3 } ) ;
189
+ triggerClick ( childToParent ) ;
190
+ $q . flush ( ) ;
191
+ expect ( $state . $current . name ) . toBe ( "contacts" ) ;
192
+ } ) ) ;
161
193
} ) ;
162
194
} ) ;
0 commit comments