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