Update the disposabe and improve test methods

This commit is contained in:
Yash Khare 2020-04-17 20:08:10 +05:30
parent 9401b688bc
commit f837a45d21
3 changed files with 5 additions and 5 deletions

View File

@ -110,7 +110,7 @@ class ZimManageViewModel @Inject constructor(
val requestFiltering = BehaviorProcessor.createDefault<String>("")
val currentPage = PublishProcessor.create<Int>()
val libraryTabIsVisible = currentPage.filter { it == 1 }
val libraryTabIsVisible = currentPage.map { it == 1 }.filter { it }
private val compositeDisposable = CompositeDisposable()

View File

@ -115,7 +115,7 @@ class ZimFileSelectFragment : BaseFragment() {
disposable.add(zimManageViewModel.libraryTabIsVisible.subscribe { finishActionMode() })
}
fun finishActionMode() {
private fun finishActionMode() {
actionMode?.finish()
}

View File

@ -519,14 +519,14 @@ class ZimManageViewModelTest {
}
@Test
fun `finish actionMode on tab change to online section`() {
fun `libraryTabIsVisible emits when currentPage is 1`() {
viewModel.libraryTabIsVisible.test()
.also { viewModel.currentPage.offer(1) }
.assertValue(1)
.assertValue(true)
}
@Test
fun `no change in actionMode`() {
fun `libraryTabIsVisible does not emit when currentPage is 0`() {
viewModel.libraryTabIsVisible.test()
.also { viewModel.currentPage.offer(0) }
.assertEmpty()