Last active
July 27, 2022 06:19
-
-
Save Raiden18/a2ed03a5e06cb31a698f1b677fd508ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Should show search button when internet connection is reappeared`() { | |
val testInternetConnectionEmitter = TestObservableEmitter(true) | |
every { filtersInteractor.getFilters() } returns Single.just(filters) | |
every { priceNotificationsInteractor.getNotificationsFromInMemory() } returns Observable.just(priceNotifications) | |
every { networkConnectionChecker.isInternetAvailable() } returns Observable.create(testInternetConnectionEmitter) | |
val viewModel = createViewModel() | |
testScheduler.triggerActions() | |
clearMocks(screenState) | |
// Internet connections is disappeared | |
testInternetConnectionEmitter.emitter?.onNext(false) // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
// User hides search | |
viewModel.hideSearchAction.accept() // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
// Internet connection appears | |
testInternetConnectionEmitter.emitter?.onNext(true) // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
clearMocks(screenState) | |
// User clicks on retry button | |
viewModel.retryClickedAction.accept() | |
testScheduler.triggerActions() | |
verify(exactly = 1) { screenState.showSearchButton() } | |
} | |
@Test | |
fun `Should search items after reappearing internet connection`() { | |
val testInternetConnectionEmitter = TestObservableEmitter(true) | |
every { filtersInteractor.getFilters() } returns Single.just(filters) | |
every { priceNotificationsInteractor.getNotificationsFromInMemory() } returns Observable.just(priceNotifications) | |
every { networkConnectionChecker.isInternetAvailable() } returns Observable.create(testInternetConnectionEmitter) | |
val viewModel = createViewModel() | |
testScheduler.triggerActions() | |
clearMocks(screenState) | |
// User searches for Apple | |
viewModel.searchInputAction.accept("Apple") // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
// Internet connections is disappeared | |
testInternetConnectionEmitter.emitter?.onNext(false) // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
//User hides Search view | |
viewModel.hideSearchAction.accept() // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
//Internet connection is appeared | |
testInternetConnectionEmitter.emitter?.onNext(true) // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
// User clicks on retry button | |
viewModel.retryClickedAction.accept() // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
// User searches for Apple again | |
viewModel.searchInputAction.accept("Apple") // Code duplication! | |
testScheduler.triggerActions() // Code duplication! | |
clearMocks(screenState) | |
verify(exactly = 1) { | |
screenState.showNotificationsAndFilters(filters, PriceNotificationsFilter.Active, activePriceNotifications) | |
} | |
verify(exactly = 0) { screenState.showUnknownErrorState() } | |
verify(exactly = 0) { screenState.showLoadingState() } | |
verify(exactly = 0) { screenState.showNoNotificationsAtAllState() } | |
verify(exactly = 0) { screenState.showNoInternetConnectionState() } | |
verify(exactly = 0) { screenState.showNoNotificationsForFilterState(any(), any()) } | |
verify(exactly = 0) { screenState.showNoNotificationsForSearch(any(), any()) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment