mirror of
https://github.com/afollestad/nock-nock.git
synced 2025-04-20 03:25:14 +00:00
Update MainViewModelTest
This commit is contained in:
parent
38c8c92c1c
commit
b369f9dfd3
2 changed files with 47 additions and 25 deletions
|
@ -89,20 +89,24 @@ fun fakeHeaders(siteId: Long): List<Header> {
|
|||
)
|
||||
}
|
||||
|
||||
fun fakeModel(id: Long) = Site(
|
||||
fun fakeModel(
|
||||
id: Long,
|
||||
tags: String = ""
|
||||
) = Site(
|
||||
id = id,
|
||||
name = "Test",
|
||||
url = "https://test.com",
|
||||
tags = "",
|
||||
tags = tags,
|
||||
settings = fakeSettingsModel(id),
|
||||
lastResult = fakeResultModel(id),
|
||||
retryPolicy = fakeRetryPolicy(id),
|
||||
headers = fakeHeaders(id)
|
||||
)
|
||||
|
||||
val MOCK_MODEL_1 = fakeModel(1)
|
||||
val MOCK_MODEL_2 = fakeModel(2)
|
||||
val MOCK_MODEL_3 = fakeModel(3)
|
||||
val MOCK_MODEL_1 = fakeModel(1, tags = "one,two")
|
||||
val MOCK_MODEL_2 = fakeModel(2, tags = "three,four")
|
||||
val MOCK_MODEL_3 = fakeModel(3, tags = "five,six")
|
||||
|
||||
val ALL_MOCK_MODELS = listOf(MOCK_MODEL_1, MOCK_MODEL_2, MOCK_MODEL_3)
|
||||
|
||||
fun mockDatabase(): AppDatabase {
|
||||
|
@ -168,13 +172,13 @@ fun mockDatabase(): AppDatabase {
|
|||
on { delete(isA()) } doReturn 1
|
||||
}
|
||||
val headerDao = mock<HeaderDao> {
|
||||
on { all() } doReturn com.afollestad.nocknock.engine.MOCK_MODEL_1.headers + com.afollestad.nocknock.engine.MOCK_MODEL_2.headers + com.afollestad.nocknock.engine.MOCK_MODEL_3.headers
|
||||
on { all() } doReturn MOCK_MODEL_1.headers + MOCK_MODEL_2.headers + MOCK_MODEL_3.headers
|
||||
on { forSite(isA()) } doAnswer { inv ->
|
||||
val id = inv.getArgument<Long>(0)
|
||||
return@doAnswer when (id) {
|
||||
1L -> com.afollestad.nocknock.engine.MOCK_MODEL_1.headers
|
||||
2L -> com.afollestad.nocknock.engine.MOCK_MODEL_2.headers
|
||||
3L -> com.afollestad.nocknock.engine.MOCK_MODEL_3.headers
|
||||
1L -> MOCK_MODEL_1.headers
|
||||
2L -> MOCK_MODEL_2.headers
|
||||
3L -> MOCK_MODEL_3.headers
|
||||
else -> listOf()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,18 +60,45 @@ class MainViewModelTest {
|
|||
.test()
|
||||
val sites = viewModel.onSites()
|
||||
.test()
|
||||
val tags = viewModel.onTags()
|
||||
.test()
|
||||
val tagsVisibility = viewModel.onTagsListVisibility()
|
||||
.test()
|
||||
|
||||
viewModel.onResume()
|
||||
|
||||
verify(notificationManager).cancelStatusNotifications()
|
||||
verify(validationManager).ensureScheduledValidations()
|
||||
|
||||
sites.assertValues(
|
||||
listOf(),
|
||||
ALL_MOCK_MODELS
|
||||
)
|
||||
sites.assertValues(ALL_MOCK_MODELS)
|
||||
isLoading.assertValues(true, false)
|
||||
emptyTextVisibility.assertValues(false, false)
|
||||
tags.assertValues(listOf("one", "two", "three", "four", "five", "six").sorted())
|
||||
tagsVisibility.assertValues(true)
|
||||
}
|
||||
|
||||
@Test fun onTagSelection() = runBlocking {
|
||||
val isLoading = viewModel.onIsLoading()
|
||||
.test()
|
||||
val emptyTextVisibility = viewModel.onEmptyTextVisibility()
|
||||
.test()
|
||||
val sites = viewModel.onSites()
|
||||
.test()
|
||||
val tags = viewModel.onTags()
|
||||
.test()
|
||||
val tagsVisibility = viewModel.onTagsListVisibility()
|
||||
.test()
|
||||
|
||||
viewModel.onTagSelection(listOf("four", "six"))
|
||||
|
||||
verify(notificationManager).cancelStatusNotifications()
|
||||
verify(validationManager).ensureScheduledValidations()
|
||||
|
||||
sites.assertValues(listOf(MOCK_MODEL_2, MOCK_MODEL_3))
|
||||
isLoading.assertValues(true, false)
|
||||
emptyTextVisibility.assertValues(false, false)
|
||||
tags.assertValues(listOf("one", "two", "three", "four", "five", "six").sorted())
|
||||
tagsVisibility.assertValues(true)
|
||||
}
|
||||
|
||||
@Test fun postSiteUpdate_notFound() {
|
||||
|
@ -86,10 +113,7 @@ class MainViewModelTest {
|
|||
.test()
|
||||
|
||||
viewModel.onResume()
|
||||
sites.assertValues(
|
||||
listOf(),
|
||||
ALL_MOCK_MODELS
|
||||
)
|
||||
sites.assertValues(ALL_MOCK_MODELS)
|
||||
|
||||
val updatedModel2 = MOCK_MODEL_2.copy(
|
||||
name = "Wakanda Forever!!!"
|
||||
|
@ -120,10 +144,7 @@ class MainViewModelTest {
|
|||
.test()
|
||||
|
||||
viewModel.onResume()
|
||||
sites.assertValues(
|
||||
listOf(),
|
||||
ALL_MOCK_MODELS
|
||||
)
|
||||
sites.assertValues(ALL_MOCK_MODELS)
|
||||
isLoading.assertValues(true, false)
|
||||
|
||||
val modifiedModel = MOCK_MODEL_1.copy(id = 11111)
|
||||
|
@ -147,10 +168,7 @@ class MainViewModelTest {
|
|||
.test()
|
||||
|
||||
viewModel.onResume()
|
||||
sites.assertValues(
|
||||
listOf(),
|
||||
ALL_MOCK_MODELS
|
||||
)
|
||||
sites.assertValues(ALL_MOCK_MODELS)
|
||||
isLoading.assertValues(true, false)
|
||||
|
||||
val modelsWithout1 = ALL_MOCK_MODELS.toMutableList()
|
||||
|
|
Loading…
Add table
Reference in a new issue