|
1 | 1 | package com.badoo.ribs.sandbox.rib.switcher
|
2 | 2 |
|
3 |
| -// TODO: Uncomment once Mockito issues with BackStack are fixed. |
4 |
| -// This blocked the update to AGP 8.2.2 |
5 |
| -//@RunWith(RobolectricTestRunner::class) |
6 |
| -//class SwitcherInteractorTest { |
7 |
| -// |
8 |
| -// private val backStack: BackStack<Configuration> = mock() |
9 |
| -// private val dialogToTestOverlay: DialogToTestOverlay = mock() |
10 |
| -// |
11 |
| -// private val viewEventRelay = PublishRelay.create<Event>() |
12 |
| -// private lateinit var interactor: SwitcherInteractor |
13 |
| -// private lateinit var interactorTestHelper: InteractorTestHelper<SwitcherView> |
14 |
| -// |
15 |
| -// @Before |
16 |
| -// fun setup() { |
17 |
| -// interactor = SwitcherInteractor( |
18 |
| -// buildParams = emptyBuildParams(), |
19 |
| -// backStack = backStack, |
20 |
| -// dialogToTestOverlay = dialogToTestOverlay, |
21 |
| -// transitions = Observable.just(SETTLED), |
22 |
| -// transitionSettled = { true } |
23 |
| -// ) |
24 |
| -// |
25 |
| -// interactorTestHelper = createInteractorTestHelper(interactor, viewEventRelay) |
26 |
| -// } |
27 |
| -// |
28 |
| -// @Test |
29 |
| -// fun `router open overlay dialog when show overlay dialog clicked`(){ |
30 |
| -// interactorTestHelper.moveToStateAndCheck(STARTED) { |
31 |
| -// viewEventRelay.accept(Event.ShowOverlayDialogClicked) |
32 |
| -// |
33 |
| -// verify(backStack).pushOverlay(Overlay.Dialog) |
34 |
| -// } |
35 |
| -// } |
36 |
| -// |
37 |
| -// @Test |
38 |
| -// fun `router open blocker when show blocker clicked`(){ |
39 |
| -// interactorTestHelper.moveToStateAndCheck(STARTED) { |
40 |
| -// viewEventRelay.accept(Event.ShowBlockerClicked) |
41 |
| -// |
42 |
| -// verify(backStack).push(Content.Blocker) |
43 |
| -// } |
44 |
| -// } |
45 |
| -// |
46 |
| -// @Test |
47 |
| -// fun `skip view event when view not resumed`(){ |
48 |
| -// interactorTestHelper.moveToStateAndCheck(CREATED) { |
49 |
| -// viewEventRelay.accept(Event.ShowBlockerClicked) |
50 |
| -// |
51 |
| -// verify(backStack, never()).push(Content.Blocker) |
52 |
| -// } |
53 |
| -// } |
54 |
| -//} |
| 3 | +import androidx.lifecycle.Lifecycle.State.CREATED |
| 4 | +import androidx.lifecycle.Lifecycle.State.STARTED |
| 5 | +import com.badoo.common.ribs.rx2.createInteractorTestHelper |
| 6 | +import com.badoo.ribs.routing.router.Router.TransitionState.SETTLED |
| 7 | +import com.badoo.ribs.routing.source.backstack.BackStack |
| 8 | +import com.badoo.ribs.routing.source.backstack.operation.push |
| 9 | +import com.badoo.ribs.routing.source.backstack.operation.pushOverlay |
| 10 | +import com.badoo.ribs.sandbox.rib.switcher.SwitcherView.Event |
| 11 | +import com.badoo.ribs.sandbox.rib.switcher.dialog.DialogToTestOverlay |
| 12 | +import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration |
| 13 | +import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration.Content |
| 14 | +import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration.Overlay |
| 15 | +import com.badoo.ribs.test.InteractorTestHelper |
| 16 | +import com.badoo.ribs.test.emptyBuildParams |
| 17 | +import com.jakewharton.rxrelay2.PublishRelay |
| 18 | +import io.reactivex.Observable |
| 19 | +import org.junit.Before |
| 20 | +import org.junit.Test |
| 21 | +import org.junit.runner.RunWith |
| 22 | +import org.mockito.kotlin.mock |
| 23 | +import org.mockito.kotlin.never |
| 24 | +import org.mockito.kotlin.verify |
| 25 | +import org.robolectric.RobolectricTestRunner |
| 26 | + |
| 27 | +@RunWith(RobolectricTestRunner::class) |
| 28 | +class SwitcherInteractorTest { |
| 29 | + |
| 30 | + private val backStack: BackStack<Configuration> = mock() |
| 31 | + private val dialogToTestOverlay: DialogToTestOverlay = mock() |
| 32 | + |
| 33 | + private val viewEventRelay = PublishRelay.create<Event>() |
| 34 | + private lateinit var interactor: SwitcherInteractor |
| 35 | + private lateinit var interactorTestHelper: InteractorTestHelper<SwitcherView> |
| 36 | + |
| 37 | + @Before |
| 38 | + fun setup() { |
| 39 | + interactor = SwitcherInteractor( |
| 40 | + buildParams = emptyBuildParams(), |
| 41 | + backStack = backStack, |
| 42 | + dialogToTestOverlay = dialogToTestOverlay, |
| 43 | + transitions = Observable.just(SETTLED), |
| 44 | + transitionSettled = { true } |
| 45 | + ) |
| 46 | + |
| 47 | + interactorTestHelper = createInteractorTestHelper(interactor, viewEventRelay) |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + fun `router open overlay dialog when show overlay dialog clicked`() { |
| 52 | + interactorTestHelper.moveToStateAndCheck(STARTED) { |
| 53 | + viewEventRelay.accept(Event.ShowOverlayDialogClicked) |
| 54 | + |
| 55 | + verify(backStack).pushOverlay(Overlay.Dialog) |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + fun `router open blocker when show blocker clicked`() { |
| 61 | + interactorTestHelper.moveToStateAndCheck(STARTED) { |
| 62 | + viewEventRelay.accept(Event.ShowBlockerClicked) |
| 63 | + |
| 64 | + verify(backStack).push(Content.Blocker) |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + fun `skip view event when view not resumed`() { |
| 70 | + interactorTestHelper.moveToStateAndCheck(CREATED) { |
| 71 | + viewEventRelay.accept(Event.ShowBlockerClicked) |
| 72 | + |
| 73 | + verify(backStack, never()).push(Content.Blocker) |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments