marshroute
/
AnimatingTransitionsHandlerTransitionAnimationsLauncherTests_BaseRouter.swift
388 строк · 16.7 Кб
1import XCTest
2@testable import Marshroute
3
4final class AnimatingTransitionsHandlerTransitionAnimationsLauncherTests_BaseRouter: XCTestCase {
5
6var sourceViewController: UIViewController!
7var targetViewController: UIViewController!
8
9var router: BaseRouter!
10
11override func setUp() {
12super.setUp()
13
14sourceViewController = UIViewController()
15targetViewController = UIViewController()
16
17let transitionIdGenerator = TransitionIdGeneratorImpl()
18
19let stackClientProvider = TransitionContextsStackClientProviderImpl()
20
21let peekAndPopTransitionsCoordinator = PeekAndPopUtilityImpl()
22
23let transitionsCoordinator = TransitionsCoordinatorImpl(
24stackClientProvider: stackClientProvider,
25peekAndPopTransitionsCoordinator: peekAndPopTransitionsCoordinator
26)
27
28let animatingTransitionsHandler = BaseAnimatingTransitionsHandler(
29transitionsCoordinator: transitionsCoordinator
30)
31
32let setRootViewControllerContext = ResettingTransitionContext(
33registeringViewController: sourceViewController,
34animatingTransitionsHandler: animatingTransitionsHandler,
35transitionId: transitionIdGenerator.generateNewTransitionId()
36)
37
38// set root view controller for a transitions handler
39animatingTransitionsHandler.resetWithTransition(context: setRootViewControllerContext)
40
41router = BaseRouter(
42routerSeed: RouterSeed(
43transitionsHandlerBox: .init(
44animatingTransitionsHandler: animatingTransitionsHandler
45),
46transitionId: transitionIdGenerator.generateNewTransitionId(),
47presentingTransitionsHandler: nil,
48transitionsHandlersProvider: transitionsCoordinator,
49transitionIdGenerator: transitionIdGenerator,
50controllersProvider: RouterControllersProviderImpl(),
51routerTransitionDelegate: nil
52)
53)
54}
55
56// MARK: - TransitionAnimationsLauncher
57
58// MARK: DetailRouter
59func testThatAnimatorIsNotCalledOn_SetViewControllerDerivedFrom() {
60// Given
61let resetNavigationTransitionsAnimatorSpy = ResetNavigationTransitionsAnimatorSpy()
62
63// When
64router.setViewControllerDerivedFrom( { (_) -> UIViewController in
65return targetViewController
66}, animator: resetNavigationTransitionsAnimatorSpy
67)
68
69// Then
70XCTAssertNil(resetNavigationTransitionsAnimatorSpy.animateResetting)
71}
72
73func testThatAnimatorIsNotCalledOn_PushViewControllerDerivedFrom() {
74// Given
75let navigationTransitionsAnimator = NavigationTransitionsAnimatorSpy()
76
77// When
78router.pushViewControllerDerivedFrom( { (_) -> UIViewController in
79return targetViewController
80}, animator: navigationTransitionsAnimator
81)
82
83// Then
84XCTAssertNil(navigationTransitionsAnimator.animatePerforming)
85}
86
87// MARK: EndpointRouter
88
89func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentModalEndpointNavigationController() {
90// Given
91let targetNavigationController = UINavigationController()
92let modalEndpointNavigationTransitionsAnimator = ModalEndpointNavigationTransitionsAnimatorSpy()
93
94// When
95router.presentModalEndpointNavigationController(
96targetNavigationController,
97animator: modalEndpointNavigationTransitionsAnimator
98) { _ in }
99
100// Then
101if case .called(let animationContext) = modalEndpointNavigationTransitionsAnimator.animatePerforming! {
102XCTAssert(animationContext.sourceViewController === sourceViewController)
103XCTAssert(animationContext.targetNavigationController === targetNavigationController)
104} else { XCTFail() }
105}
106
107// MARK: ModalPresentationRouter
108
109func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentModalViewControllerDerivedFrom() {
110// Given
111let modalTransitionsAnimator = ModalTransitionsAnimatorSpy()
112
113// When
114router.presentModalViewControllerDerivedFrom( { (_) -> UIViewController in
115return targetViewController
116}, animator: modalTransitionsAnimator
117)
118
119// Then
120if case .called(let animationContext) = modalTransitionsAnimator.animatePerforming! {
121XCTAssert(animationContext.sourceViewController === sourceViewController)
122XCTAssert(animationContext.targetViewController === targetViewController)
123} else { XCTFail() }
124}
125
126func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentModalMasterDetailViewControllerDerivedFrom() {
127// Given
128let modalMasterDetailTransitionsAnimator = ModalMasterDetailTransitionsAnimatorSpy()
129
130// When
131router.presentModalMasterDetailViewControllerDerivedFrom(
132deriveMasterViewController: { (_) -> UIViewController in
133return UIViewController()
134},
135deriveDetailViewController: { (_) -> UIViewController in
136return UIViewController()
137},
138animator: modalMasterDetailTransitionsAnimator
139)
140
141// Then
142if case .called(let animationContext) = modalMasterDetailTransitionsAnimator.animatePerforming! {
143XCTAssert(animationContext.sourceViewController === sourceViewController)
144} else { XCTFail() }
145}
146
147func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentModalMasterDetailViewControllerDerivedFrom_IfCustomCustomMasterNavigationController_CustomDetailNavigationController_CustomSplitViewController() {
148// Given
149let modalMasterDetailTransitionsAnimator = ModalMasterDetailTransitionsAnimatorSpy()
150let splitViewController = UISplitViewController()
151
152// When
153router.presentModalMasterDetailViewControllerDerivedFrom(
154deriveMasterViewController: { (_) -> UIViewController in
155return UIViewController()
156},
157deriveDetailViewController: { (_) -> UIViewController in
158return UIViewController()
159},
160animator: modalMasterDetailTransitionsAnimator,
161masterNavigationController: UINavigationController(),
162detailNavigationController: UINavigationController(),
163splitViewController: splitViewController
164)
165
166// Then
167if case .called(let animationContext) = modalMasterDetailTransitionsAnimator.animatePerforming! {
168XCTAssert(animationContext.sourceViewController === sourceViewController)
169XCTAssert(animationContext.targetViewController === splitViewController)
170} else { XCTFail() }
171}
172
173func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentModalNavigationControllerWithRootViewControllerDerivedFrom() {
174// Given
175let modalNavigationTransitionsAnimator = ModalNavigationTransitionsAnimatorSpy()
176
177// When
178router.presentModalNavigationControllerWithRootViewControllerDerivedFrom( { (_) -> UIViewController in
179return targetViewController
180}, animator: modalNavigationTransitionsAnimator
181)
182
183// Then
184if case .called(let animationContext) = modalNavigationTransitionsAnimator.animatePerforming! {
185XCTAssert(animationContext.sourceViewController === sourceViewController)
186XCTAssert(animationContext.targetViewController === targetViewController)
187} else { XCTFail() }
188}
189
190func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentModalNavigationControllerWithRootViewControllerDerivedFrom_IfCustomNavigationController() {
191// Given
192let navigationController = UINavigationController()
193let modalNavigationTransitionsAnimator = ModalNavigationTransitionsAnimatorSpy()
194
195// When
196router.presentModalNavigationControllerWithRootViewControllerDerivedFrom( { (_) -> UIViewController in
197return targetViewController
198}, animator: modalNavigationTransitionsAnimator,
199navigationController: navigationController
200)
201
202// Then
203if case .called(let animationContext) = modalNavigationTransitionsAnimator.animatePerforming! {
204XCTAssert(animationContext.sourceViewController === sourceViewController)
205XCTAssert(animationContext.targetViewController === targetViewController)
206XCTAssert(animationContext.targetNavigationController === navigationController)
207} else { XCTFail() }
208}
209
210// MARK: PopoverPresentationRouter
211
212func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentPopoverFromRect() {
213guard UIDevice.current.userInterfaceIdiom == .pad
214else { return }
215
216// Given
217let rect = CGRect(x: 0, y: 1, width: 2, height: 3)
218let view = UIView()
219let popoverTransitionsAnimator = PopoverTransitionsAnimatorSpy()
220
221// When
222router.presentPopoverFromRect(
223rect,
224inView: view,
225withViewControllerDerivedFrom: { (_) -> UIViewController in
226return targetViewController
227},
228animator: popoverTransitionsAnimator
229)
230
231// Then
232if case .called(let animationContext) = popoverTransitionsAnimator.animatePerforming! {
233XCTAssert(animationContext.sourceViewController === sourceViewController)
234XCTAssert(animationContext.targetViewController === targetViewController)
235if case .popoverFromView(let sourceView, let sourceRect) = animationContext.transitionStyle {
236XCTAssertEqual(sourceRect, rect)
237XCTAssertEqual(sourceView, view)
238} else { XCTFail() }
239} else { XCTFail() }
240}
241
242func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentPopoverFromBarButtonItem() {
243guard UIDevice.current.userInterfaceIdiom == .pad
244else { return }
245
246// Given
247let barButtonItem = UIBarButtonItem()
248let popoverTransitionsAnimator = PopoverTransitionsAnimatorSpy()
249
250// When
251router.presentPopoverFromBarButtonItem(
252barButtonItem,
253withViewControllerDerivedFrom: { (_) -> UIViewController in
254return targetViewController
255},
256animator: popoverTransitionsAnimator
257)
258
259// Then
260if case .called(let animationContext) = popoverTransitionsAnimator.animatePerforming! {
261XCTAssert(animationContext.sourceViewController === sourceViewController)
262XCTAssert(animationContext.targetViewController === targetViewController)
263if case .popoverFromBarButtonItem(let buttonItem) = animationContext.transitionStyle {
264XCTAssert(buttonItem === barButtonItem)
265} else { XCTFail() }
266} else { XCTFail() }
267}
268
269func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentPopoverWithNavigationControllerFromRect() {
270guard UIDevice.current.userInterfaceIdiom == .pad
271else { return }
272
273// Given
274let rect = CGRect(x: 0, y: 1, width: 2, height: 3)
275let view = UIView()
276let popoverNavigationTransitionsAnimator = PopoverNavigationTransitionsAnimatorSpy()
277
278// When
279router.presentPopoverWithNavigationControllerFromRect(
280rect,
281inView: view,
282withViewControllerDerivedFrom: { (_) -> UIViewController in
283return targetViewController
284},
285animator: popoverNavigationTransitionsAnimator
286)
287
288// Then
289if case .called(let animationContext) = popoverNavigationTransitionsAnimator.animatePerforming! {
290XCTAssert(animationContext.sourceViewController === sourceViewController)
291XCTAssert(animationContext.targetViewController === targetViewController)
292if case .popoverFromView(let sourceView, let sourceRect) = animationContext.transitionStyle {
293XCTAssertEqual(sourceRect, rect)
294XCTAssertEqual(sourceView, view)
295} else { XCTFail() }
296} else { XCTFail() }
297}
298
299func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentPopoverWithNavigationControllerFromRect_IfCustomNavigationController() {
300guard UIDevice.current.userInterfaceIdiom == .pad
301else { return }
302
303// Given
304let rect = CGRect(x: 0, y: 1, width: 2, height: 3)
305let view = UIView()
306let navigationController = UINavigationController()
307let popoverNavigationTransitionsAnimator = PopoverNavigationTransitionsAnimatorSpy()
308
309// When
310router.presentPopoverWithNavigationControllerFromRect(
311rect,
312inView: view,
313withViewControllerDerivedFrom: { (_) -> UIViewController in
314return targetViewController
315},
316animator: popoverNavigationTransitionsAnimator,
317navigationController: navigationController
318)
319
320// Then
321if case .called(let animationContext) = popoverNavigationTransitionsAnimator.animatePerforming! {
322XCTAssert(animationContext.sourceViewController === sourceViewController)
323XCTAssert(animationContext.targetViewController === targetViewController)
324XCTAssert(animationContext.targetNavigationController === navigationController)
325if case .popoverFromView(let sourceView, let sourceRect) = animationContext.transitionStyle {
326XCTAssertEqual(sourceRect, rect)
327XCTAssertEqual(sourceView, view)
328} else { XCTFail() }
329} else { XCTFail() }
330}
331
332func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentPopoverWithNavigationControllerFromBarButtonItem() {
333guard UIDevice.current.userInterfaceIdiom == .pad
334else { return }
335
336// Given
337let barButtonItem = UIBarButtonItem()
338let popoverNavigationTransitionsAnimator = PopoverNavigationTransitionsAnimatorSpy()
339
340// When
341router.presentPopoverWithNavigationControllerFromBarButtonItem(
342barButtonItem,
343withViewControllerDerivedFrom: { (_) -> UIViewController in
344return targetViewController
345},
346animator: popoverNavigationTransitionsAnimator
347)
348
349// Then
350if case .called(let animationContext) = popoverNavigationTransitionsAnimator.animatePerforming! {
351XCTAssert(animationContext.sourceViewController === sourceViewController)
352XCTAssert(animationContext.targetViewController === targetViewController)
353if case .popoverFromBarButtonItem(let buttonItem) = animationContext.transitionStyle {
354XCTAssert(buttonItem === barButtonItem)
355} else { XCTFail() }
356} else { XCTFail() }
357}
358
359func testThatAnimatorIsCalledWithCorectPresentationAnimationContextOn_PresentPopoverWithNavigationControllerFromBarButtonItem_IfCustomnavigationController() {
360guard UIDevice.current.userInterfaceIdiom == .pad
361else { return }
362
363// Given
364let barButtonItem = UIBarButtonItem()
365let navigationController = UINavigationController()
366let popoverNavigationTransitionsAnimator = PopoverNavigationTransitionsAnimatorSpy()
367
368// When
369router.presentPopoverWithNavigationControllerFromBarButtonItem(
370barButtonItem,
371withViewControllerDerivedFrom: { (_) -> UIViewController in
372return targetViewController
373},
374animator: popoverNavigationTransitionsAnimator,
375navigationController: navigationController
376)
377
378// Then
379if case .called(let animationContext) = popoverNavigationTransitionsAnimator.animatePerforming! {
380XCTAssert(animationContext.sourceViewController === sourceViewController)
381XCTAssert(animationContext.targetViewController === targetViewController)
382XCTAssert(animationContext.targetNavigationController === navigationController)
383if case .popoverFromBarButtonItem(let buttonItem) = animationContext.transitionStyle {
384XCTAssert(buttonItem === barButtonItem)
385} else { XCTFail() }
386} else { XCTFail() }
387}
388}
389