marshroute

Форк
0
/
NavigationTransitionsHandlerImpl_TransitionAnimationsLauncherTests_BaseRouter.swift 
399 строк · 17.4 Кб
1
import XCTest
2
@testable import Marshroute
3

4
final class NavigationTransitionsHandlerImpl_TransitionAnimationsLauncherTests_BaseRouter: XCTestCase {
5

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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.