mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 11:55:38 -04:00
#2119 more history test fixes
This commit is contained in:
parent
eb81565c5a
commit
17a5697988
@ -75,26 +75,11 @@ internal class HistoryViewModelTest {
|
||||
|
||||
@Test
|
||||
internal fun `ExitActionModeMenu deselects history items`() {
|
||||
viewModel.state.postValue(
|
||||
historyState(
|
||||
historyItems = listOf(
|
||||
historyItem(
|
||||
isSelected = true
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
viewModel.state.postValue(historyState(historyItems = listOf(historyItem(isSelected = true))))
|
||||
viewModel.actions.offer(ExitActionModeMenu)
|
||||
viewModel.state.test()
|
||||
.assertValue(
|
||||
historyState(
|
||||
historyItems = listOf(
|
||||
historyItem(
|
||||
isSelected = false
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
viewModel.state.test().assertValue(
|
||||
historyState(historyItems = listOf(historyItem(isSelected = false)))
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -113,8 +98,7 @@ internal class HistoryViewModelTest {
|
||||
|
||||
@Test
|
||||
internal fun `UserClickedDeleteSelectedHistoryItems offers ShowDeleteHistoryDialog`() {
|
||||
viewModel.effects.test()
|
||||
.also { viewModel.actions.offer(UserClickedDeleteSelectedHistoryItems) }
|
||||
viewModel.effects.test().also { viewModel.actions.offer(UserClickedDeleteSelectedHistoryItems) }
|
||||
.assertValue(ShowDeleteHistoryDialog(viewModel.actions))
|
||||
viewModel.state.test().assertValue(historyState())
|
||||
}
|
||||
@ -124,86 +108,43 @@ internal class HistoryViewModelTest {
|
||||
viewModel.effects.test()
|
||||
.also { viewModel.actions.offer(UserClickedShowAllToggle(false)) }
|
||||
.assertValue(UpdateAllHistoryPreference(sharedPreferenceUtil, false))
|
||||
viewModel.state.test().assertValue(
|
||||
historyState(
|
||||
showAll = false
|
||||
)
|
||||
)
|
||||
viewModel.state.test().assertValue(historyState(showAll = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun `OnItemClick selects item if one is selected`() {
|
||||
val historyItem =
|
||||
historyItem(isSelected = true)
|
||||
viewModel.state.postValue(
|
||||
historyState(
|
||||
listOf(historyItem)
|
||||
)
|
||||
)
|
||||
val historyItem = historyItem(isSelected = true)
|
||||
viewModel.state.postValue(historyState(listOf(historyItem)))
|
||||
viewModel.actions.offer(OnItemClick(historyItem))
|
||||
viewModel.state.test().assertValue(
|
||||
historyState(
|
||||
listOf(historyItem())
|
||||
)
|
||||
)
|
||||
viewModel.state.test().assertValue(historyState(listOf(historyItem())))
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun `OnItemClick offers OpenHistoryItem if none is selected`() {
|
||||
viewModel.state.postValue(
|
||||
historyState(
|
||||
listOf(historyItem())
|
||||
)
|
||||
)
|
||||
viewModel.effects.test()
|
||||
.also { viewModel.actions.offer(OnItemClick(historyItem())) }
|
||||
viewModel.state.postValue(historyState(listOf(historyItem())))
|
||||
viewModel.effects.test().also { viewModel.actions.offer(OnItemClick(historyItem())) }
|
||||
.assertValue(OpenHistoryItem(historyItem(), zimReaderContainer))
|
||||
viewModel.state.test().assertValue(
|
||||
historyState(
|
||||
listOf(historyItem())
|
||||
)
|
||||
)
|
||||
viewModel.state.test().assertValue(historyState(listOf(historyItem())))
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun `OnItemLongClick selects item if none is selected`() {
|
||||
val historyItem =
|
||||
historyItem()
|
||||
viewModel.state.postValue(
|
||||
historyState(
|
||||
listOf(historyItem)
|
||||
)
|
||||
)
|
||||
val historyItem = historyItem()
|
||||
viewModel.state.postValue(historyState(listOf(historyItem)))
|
||||
viewModel.actions.offer(OnItemLongClick(historyItem))
|
||||
viewModel.state.test().assertValue(
|
||||
historyState(
|
||||
listOf(
|
||||
historyItem(
|
||||
isSelected = true
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
viewModel.state.test().assertValue(historyState(listOf(historyItem(isSelected = true))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Filter updates search term`() {
|
||||
val searchTerm = "searchTerm"
|
||||
viewModel.actions.offer(Filter(searchTerm))
|
||||
viewModel.state.test().assertValue(
|
||||
historyState(
|
||||
searchTerm = searchTerm
|
||||
)
|
||||
)
|
||||
viewModel.state.test().assertValue(historyState(searchTerm = searchTerm))
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun `UpdateHistory updates history`() {
|
||||
viewModel.actions.offer(UpdateHistory(listOf(historyItem())))
|
||||
viewModel.state.test().assertValue(
|
||||
historyState(
|
||||
listOf(historyItem())
|
||||
)
|
||||
)
|
||||
viewModel.state.test().assertValue(historyState(listOf(historyItem())))
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,12 @@
|
||||
package org.kiwix.kiwixmobile.core.history.viewmodel.effects
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.kiwix.kiwixmobile.core.dao.HistoryDao
|
||||
import org.kiwix.kiwixmobile.core.history.viewmodel.HistoryState
|
||||
|
||||
internal class DeleteHistoryItemsTest {
|
||||
val state: MutableLiveData<HistoryState> = mockk()
|
||||
private val historyDao: HistoryDao = mockk()
|
||||
val activity: AppCompatActivity = mockk()
|
||||
private val item1 = historyItem()
|
||||
@ -19,16 +15,14 @@ internal class DeleteHistoryItemsTest {
|
||||
@Test
|
||||
fun `delete with selected items only deletes the selected items`() {
|
||||
item1.isSelected = true
|
||||
every { state.value } returns historyState(historyItems = listOf(item1, item2))
|
||||
DeleteHistoryItems(state.value!!, historyDao).invokeWith(activity)
|
||||
DeleteHistoryItems(historyState(listOf(item1, item2)), historyDao).invokeWith(activity)
|
||||
verify { historyDao.deleteHistory(listOf(item1)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `delete with no selected items deletes all items`() {
|
||||
item1.isSelected = false
|
||||
every { state.value } returns historyState(historyItems = listOf(item1, item2))
|
||||
DeleteHistoryItems(state.value!!, historyDao).invokeWith(activity)
|
||||
DeleteHistoryItems(historyState(listOf(item1, item2)), historyDao).invokeWith(activity)
|
||||
verify { historyDao.deleteHistory(listOf(item1, item2)) }
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,11 @@ internal class OpenHistoryItemTest {
|
||||
fun `invokeWith returns an Ok Result with historyUrl`() {
|
||||
val item = historyItem()
|
||||
val zimReaderContainer: ZimReaderContainer = mockk()
|
||||
every {
|
||||
zimReaderContainer.zimCanonicalPath
|
||||
} returns "zimFilePath"
|
||||
every { zimReaderContainer.zimCanonicalPath } returns "zimFilePath"
|
||||
val activity: AppCompatActivity = mockk()
|
||||
mockkConstructor(Intent::class)
|
||||
val intent: Intent = mockk()
|
||||
every {
|
||||
anyConstructed<Intent>().putExtra(EXTRA_CHOSE_X_URL, item.historyUrl)
|
||||
} returns intent
|
||||
every { anyConstructed<Intent>().putExtra(EXTRA_CHOSE_X_URL, item.historyUrl) } returns intent
|
||||
OpenHistoryItem(item, zimReaderContainer).invokeWith(activity)
|
||||
verify {
|
||||
activity.setResult(Activity.RESULT_OK, intent)
|
||||
@ -40,18 +36,12 @@ internal class OpenHistoryItemTest {
|
||||
fun `invokeWith returns an Ok Result with historyUrl and zimFilePath`() {
|
||||
val item = historyItem()
|
||||
val zimReaderContainer: ZimReaderContainer = mockk()
|
||||
every {
|
||||
zimReaderContainer.zimCanonicalPath
|
||||
} returns "notZimFilePath"
|
||||
every { zimReaderContainer.zimCanonicalPath } returns "notZimFilePath"
|
||||
val activity: AppCompatActivity = mockk()
|
||||
mockkConstructor(Intent::class)
|
||||
val intent: Intent = mockk()
|
||||
every {
|
||||
anyConstructed<Intent>().putExtra(EXTRA_CHOSE_X_URL, item.historyUrl)
|
||||
} returns intent
|
||||
every {
|
||||
intent.putExtra(EXTRA_CHOSE_X_FILE, item.zimFilePath)
|
||||
} returns intent
|
||||
every { anyConstructed<Intent>().putExtra(EXTRA_CHOSE_X_URL, item.historyUrl) } returns intent
|
||||
every { intent.putExtra(EXTRA_CHOSE_X_FILE, item.zimFilePath) } returns intent
|
||||
OpenHistoryItem(item, zimReaderContainer).invokeWith(activity)
|
||||
verify {
|
||||
intent.putExtra(EXTRA_CHOSE_X_FILE, item.zimFilePath)
|
||||
|
@ -26,9 +26,7 @@ internal class ShowDeleteHistoryDialogTest {
|
||||
}
|
||||
val lambdaSlot = slot<() -> Unit>()
|
||||
showDeleteHistoryDialog.invokeWith(activity)
|
||||
verify {
|
||||
dialogShower.show(DeleteAllHistory, capture(lambdaSlot))
|
||||
}
|
||||
verify { dialogShower.show(DeleteAllHistory, capture(lambdaSlot)) }
|
||||
lambdaSlot.captured.invoke()
|
||||
verify { actions.offer(UserClickedConfirmDelete) }
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ internal class UpdateAllHistoryPreferenceTest {
|
||||
val sharedPreferenceUtil: SharedPreferenceUtil = mockk()
|
||||
val activity: AppCompatActivity = mockk()
|
||||
UpdateAllHistoryPreference(sharedPreferenceUtil, true).invokeWith(activity)
|
||||
verify {
|
||||
sharedPreferenceUtil.showHistoryAllBooks = true
|
||||
}
|
||||
verify { sharedPreferenceUtil.showHistoryAllBooks = true }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user