@@ -58,7 +58,8 @@ class ReSwiftRouterUnitTests: QuickSpec {
58
58
expect ( action2Correct) . to ( beTrue ( ) )
59
59
}
60
60
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
+
62
63
let oldRoute = [ tabBarViewControllerIdentifier, counterViewControllerIdentifier]
63
64
let newRoute = [ tabBarViewControllerIdentifier, statsViewControllerIdentifier]
64
65
@@ -83,7 +84,7 @@ class ReSwiftRouterUnitTests: QuickSpec {
83
84
expect ( new) . to ( equal ( statsViewControllerIdentifier) )
84
85
}
85
86
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 " ) {
87
88
let oldRoute = [ tabBarViewControllerIdentifier, counterViewControllerIdentifier]
88
89
let newRoute = [ tabBarViewControllerIdentifier, statsViewControllerIdentifier,
89
90
infoViewControllerIdentifier]
@@ -119,6 +120,42 @@ class ReSwiftRouterUnitTests: QuickSpec {
119
120
expect ( action1Correct) . to ( beTrue ( ) )
120
121
expect ( action2Correct) . to ( beTrue ( ) )
121
122
}
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
+ }
122
159
123
160
it ( " generates a Change action on root when root element changes " ) {
124
161
let oldRoute = [ tabBarViewControllerIdentifier]
0 commit comments