@@ -11,25 +11,47 @@ import Nimble
11
11
import ReSwift
12
12
@testable import ReSwiftRouter
13
13
14
- class FakeRoutable : Routable {
14
+ class MockRoutable : Routable {
15
15
16
+ var callsToPushRouteSegment : [ ( routeElement: RouteElementIdentifier , animated: Bool ) ] = [ ]
17
+ var callsToPopRouteSegment : [ ( routeElement: RouteElementIdentifier , animated: Bool ) ] = [ ]
18
+ var callsToChangeRouteSegment : [ (
19
+ from: RouteElementIdentifier ,
20
+ to: RouteElementIdentifier ,
21
+ animated: Bool
22
+ ) ] = [ ]
16
23
17
- func pushRouteSegment( routeSegment: RouteElementIdentifier ,
24
+ func pushRouteSegment(
25
+ routeElementIdentifier: RouteElementIdentifier ,
26
+ animated: Bool ,
18
27
completionHandler: RoutingCompletionHandler ) -> Routable {
28
+ callsToPushRouteSegment. append (
29
+ ( routeElement: routeElementIdentifier, animated: animated)
30
+ )
19
31
completionHandler ( )
20
- return FakeRoutable ( )
32
+ return MockRoutable ( )
21
33
}
22
34
23
- func popRouteSegment( routeSegment: RouteElementIdentifier ,
35
+ func popRouteSegment(
36
+ routeElementIdentifier: RouteElementIdentifier ,
37
+ animated: Bool ,
24
38
completionHandler: RoutingCompletionHandler ) {
39
+ callsToPopRouteSegment. append (
40
+ ( routeElement: routeElementIdentifier, animated: animated)
41
+ )
25
42
completionHandler ( )
26
43
}
27
44
28
- func changeRouteSegment( from: RouteElementIdentifier ,
45
+ func changeRouteSegment(
46
+ from: RouteElementIdentifier ,
29
47
to: RouteElementIdentifier ,
48
+ animated: Bool ,
30
49
completionHandler: RoutingCompletionHandler ) -> Routable {
31
50
completionHandler ( )
32
- return FakeRoutable ( )
51
+
52
+ callsToChangeRouteSegment. append ( ( from: from, to: to, animated: animated) )
53
+
54
+ return MockRoutable ( )
33
55
}
34
56
35
57
}
@@ -74,7 +96,7 @@ class SwiftFlowRouterIntegrationTests: QuickSpec {
74
96
func pushRouteSegment( routeElementIdentifier: RouteElementIdentifier ,
75
97
completionHandler: RoutingCompletionHandler ) -> Routable {
76
98
called = true
77
- return FakeRoutable ( )
99
+ return MockRoutable ( )
78
100
}
79
101
}
80
102
@@ -100,12 +122,14 @@ class SwiftFlowRouterIntegrationTests: QuickSpec {
100
122
self . calledWithIdentifier = calledWithIdentifier
101
123
}
102
124
103
- func pushRouteSegment( routeSegment: RouteElementIdentifier ,
125
+ func pushRouteSegment(
126
+ routeSegment: RouteElementIdentifier ,
127
+ animated: Bool ,
104
128
completionHandler: RoutingCompletionHandler ) -> Routable {
105
129
calledWithIdentifier ( routeSegment)
106
130
107
131
completionHandler ( )
108
- return FakeRoutable ( )
132
+ return MockRoutable ( )
109
133
}
110
134
111
135
}
@@ -137,12 +161,14 @@ class SwiftFlowRouterIntegrationTests: QuickSpec {
137
161
self . calledWithIdentifier = calledWithIdentifier
138
162
}
139
163
140
- func pushRouteSegment( routeSegment: RouteElementIdentifier ,
164
+ func pushRouteSegment(
165
+ routeSegment: RouteElementIdentifier ,
166
+ animated: Bool ,
141
167
completionHandler: RoutingCompletionHandler ) -> Routable {
142
168
calledWithIdentifier ( routeSegment)
143
169
144
170
completionHandler ( )
145
- return FakeRoutable ( )
171
+ return MockRoutable ( )
146
172
}
147
173
}
148
174
@@ -160,7 +186,9 @@ class SwiftFlowRouterIntegrationTests: QuickSpec {
160
186
self . injectedRoutable = injectedRoutable
161
187
}
162
188
163
- func pushRouteSegment( routeElementIdentifier: RouteElementIdentifier ,
189
+ func pushRouteSegment(
190
+ routeElementIdentifier: RouteElementIdentifier ,
191
+ animated: Bool ,
164
192
completionHandler: RoutingCompletionHandler ) -> Routable {
165
193
completionHandler ( )
166
194
return injectedRoutable
@@ -205,6 +233,54 @@ class SwiftFlowRouterIntegrationTests: QuickSpec {
205
233
206
234
}
207
235
236
+ describe ( " configuring animated/unanimated navigation " ) {
237
+
238
+ var store : Store < FakeAppState > !
239
+ var mockRoutable : MockRoutable !
240
+ var router : Router < FakeAppState > !
241
+
242
+ beforeEach {
243
+ store = Store ( reducer: AppReducer ( ) , state: nil )
244
+ mockRoutable = MockRoutable ( )
245
+ router = Router ( store: store, rootRoutable: mockRoutable) { state in
246
+ state. navigationState
247
+ }
248
+
249
+ // silence router not read warning, need to keep router alive via reference
250
+ _ = router
251
+ }
252
+
253
+ context ( " when dispatching an animated route change " ) {
254
+ beforeEach {
255
+ store. dispatch ( SetRouteAction ( [ " someRoute " ] , animated: true ) )
256
+ }
257
+
258
+ it ( " calls routables asking for an animated presentation " ) {
259
+ expect ( mockRoutable. callsToPushRouteSegment. last? . animated) . toEventually ( beTrue ( ) )
260
+ }
261
+ }
262
+
263
+ context ( " when dispatching an unanimated route change " ) {
264
+ beforeEach {
265
+ store. dispatch ( SetRouteAction ( [ " someRoute " ] , animated: false ) )
266
+ }
267
+
268
+ it ( " calls routables asking for an animated presentation " ) {
269
+ expect ( mockRoutable. callsToPushRouteSegment. last? . animated) . toEventually ( beFalse ( ) )
270
+ }
271
+ }
272
+
273
+ context ( " when dispatching a default route change " ) {
274
+ beforeEach {
275
+ store. dispatch ( SetRouteAction ( [ " someRoute " ] ) )
276
+ }
277
+
278
+ it ( " calls routables asking for an animated presentation " ) {
279
+ expect ( mockRoutable. callsToPushRouteSegment. last? . animated) . toEventually ( beTrue ( ) )
280
+ }
281
+ }
282
+ }
283
+
208
284
209
285
}
210
286
0 commit comments