@@ -58,7 +58,8 @@ class ReSwiftRouterUnitTests: QuickSpec {
5858 expect ( action2Correct) . to ( beTrue ( ) )
5959 }
6060
61- it ( " generates a Change action on the last common subroute " ) {
61+ it ( " generates a Change on the last common subroute for routes of same length " ) {
62+
6263 let oldRoute = [ tabBarViewControllerIdentifier, counterViewControllerIdentifier]
6364 let newRoute = [ tabBarViewControllerIdentifier, statsViewControllerIdentifier]
6465
@@ -83,7 +84,7 @@ class ReSwiftRouterUnitTests: QuickSpec {
8384 expect ( new) . to ( equal ( statsViewControllerIdentifier) )
8485 }
8586
86- it ( " generates a Change action on the last common subroute, also for routes of different length " ) {
87+ it ( " generates a Change on the last common subroute when new route is longer than the old route " ) {
8788 let oldRoute = [ tabBarViewControllerIdentifier, counterViewControllerIdentifier]
8889 let newRoute = [ tabBarViewControllerIdentifier, statsViewControllerIdentifier,
8990 infoViewControllerIdentifier]
@@ -119,6 +120,42 @@ class ReSwiftRouterUnitTests: QuickSpec {
119120 expect ( action1Correct) . to ( beTrue ( ) )
120121 expect ( action2Correct) . to ( beTrue ( ) )
121122 }
123+
124+ it ( " generates a Change on the last common subroute when the new route is shorter than the old route " ) {
125+ let oldRoute = [ tabBarViewControllerIdentifier, counterViewControllerIdentifier, infoViewControllerIdentifier]
126+ let newRoute = [ tabBarViewControllerIdentifier, statsViewControllerIdentifier]
127+
128+ let routingActions = Router< AppState> . routingActionsForTransition( from: oldRoute,
129+ to: newRoute)
130+
131+ var action1Correct : Bool ?
132+ var action2Correct : Bool ?
133+
134+ if case let RoutingActions . pop( responsibleRoutableIndex, segmentToBePopped)
135+ = routingActions [ 0 ] {
136+
137+ if responsibleRoutableIndex == 2
138+ && segmentToBePopped == infoViewControllerIdentifier {
139+
140+ action1Correct = true
141+ }
142+ }
143+
144+ if case let RoutingActions . change( responsibleRoutableIndex, segmentToBeReplaced,
145+ newSegment)
146+ = routingActions [ 1 ] {
147+
148+ if responsibleRoutableIndex == 1
149+ && segmentToBeReplaced == counterViewControllerIdentifier
150+ && newSegment == statsViewControllerIdentifier{
151+ action2Correct = true
152+ }
153+ }
154+
155+ expect ( routingActions) . to ( haveCount ( 2 ) )
156+ expect ( action1Correct) . to ( beTrue ( ) )
157+ expect ( action2Correct) . to ( beTrue ( ) )
158+ }
122159
123160 it ( " generates a Change action on root when root element changes " ) {
124161 let oldRoute = [ tabBarViewControllerIdentifier]
0 commit comments