@@ -10,7 +10,7 @@ describe('When a router enters a branch', function () {
10
10
let
11
11
node ,
12
12
newsLeaveHookSpy , removeNewsLeaveHook , userLeaveHookSpy ,
13
- DashboardRoute , NewsFeedRoute , InboxRoute , RedirectToInboxRoute , MessageRoute , UserRoute ,
13
+ DashboardRoute , NewsFeedRoute , InboxRoute , RedirectToInboxRoute , MessageRoute , UserRoute , AssignmentRoute ,
14
14
routes
15
15
16
16
beforeEach ( function ( ) {
@@ -52,6 +52,12 @@ describe('When a router enters a branch', function () {
52
52
}
53
53
}
54
54
55
+ class UserAssignment extends Component {
56
+ render ( ) {
57
+ return < div > assignment { this . props . params . assignmentId } </ div >
58
+ }
59
+ }
60
+
55
61
class User extends Component {
56
62
componentWillMount ( ) {
57
63
this . context . router . setRouteLeaveHook (
@@ -61,7 +67,7 @@ describe('When a router enters a branch', function () {
61
67
}
62
68
63
69
render ( ) {
64
- return < div > User</ div >
70
+ return < div > User { this . props . params . userId } { this . props . children } </ div >
65
71
}
66
72
}
67
73
@@ -121,9 +127,19 @@ describe('When a router enters a branch', function () {
121
127
}
122
128
}
123
129
130
+ AssignmentRoute = {
131
+ path : 'assignments/:assignmentId' ,
132
+ component : UserAssignment ,
133
+ onEnter ( ) { expect ( this ) . toBe ( AssignmentRoute ) } ,
134
+ onLeave ( ) { expect ( this ) . toBe ( AssignmentRoute ) }
135
+ }
136
+
124
137
UserRoute = {
125
138
path : 'users/:userId' ,
126
- component : User
139
+ component : User ,
140
+ childRoutes : [ AssignmentRoute ] ,
141
+ onEnter ( ) { expect ( this ) . toBe ( UserRoute ) } ,
142
+ onLeave ( ) { expect ( this ) . toBe ( UserRoute ) }
127
143
}
128
144
129
145
DashboardRoute = {
@@ -277,6 +293,38 @@ describe('When a router enters a branch', function () {
277
293
} )
278
294
} )
279
295
296
+ describe ( 'and then navigates to the same branch, but with different parent params' , function ( ) {
297
+ it ( 'calls the onLeave and onEnter hooks of the parent and children' , function ( done ) {
298
+ const parentLeaveSpy = spyOn ( UserRoute , 'onLeave' ) . andCallThrough ( )
299
+ const parentEnterSpy = spyOn ( UserRoute , 'onEnter' ) . andCallThrough ( )
300
+ const childLeaveSpy = spyOn ( AssignmentRoute , 'onLeave' ) . andCallThrough ( )
301
+ const childEnterSpy = spyOn ( AssignmentRoute , 'onEnter' ) . andCallThrough ( )
302
+ const history = createHistory ( '/users/123/assignments/456' )
303
+
304
+ const steps = [
305
+ function ( ) {
306
+ expect ( parentEnterSpy ) . toHaveBeenCalled ( )
307
+ expect ( childEnterSpy ) . toHaveBeenCalled ( )
308
+ history . push ( '/users/789/assignments/456' )
309
+ } ,
310
+ function ( ) {
311
+ expect ( parentLeaveSpy ) . toHaveBeenCalled ( )
312
+ expect ( childLeaveSpy ) . toHaveBeenCalled ( )
313
+ expect ( parentEnterSpy ) . toHaveBeenCalled ( )
314
+ expect ( childEnterSpy ) . toHaveBeenCalled ( )
315
+ }
316
+ ]
317
+
318
+ const execNextStep = execSteps ( steps , done )
319
+
320
+ render (
321
+ < Router history = { history }
322
+ routes = { routes }
323
+ onUpdate = { execNextStep }
324
+ /> , node , execNextStep )
325
+ } )
326
+ } )
327
+
280
328
describe ( 'and then the query changes' , function ( ) {
281
329
it ( 'calls the onEnter hooks of all routes in that branch' , function ( done ) {
282
330
const newsFeedRouteEnterSpy = spyOn ( NewsFeedRoute , 'onEnter' ) . andCallThrough ( )
0 commit comments