marshroute

Форк
0
/
AnimatingTransitionsHandlerTransitionAnimationsLauncherTests_BaseRouter.swift 
388 строк · 16.7 Кб
1
import XCTest
2
@testable import Marshroute
3

4
final class AnimatingTransitionsHandlerTransitionAnimationsLauncherTests_BaseRouter: XCTestCase {
5

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

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

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

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

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