Skip to content

Commit

Permalink
test: add tests for acceptAlert() and unacceptAlert()
Browse files Browse the repository at this point in the history
  • Loading branch information
agonzalez-r committed Dec 19, 2024
1 parent 1eef5e4 commit 15a0697
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,41 @@ class AlertViewModelTest {
assertEquals(alert, viewModel.selectedAlert.value)
}

@Test
fun acceptAlertSuccess() = runBlocking {
doAnswer { it.getArgument<(List<Alert>) -> Unit>(0)(alerts) }
.`when`(alertModelSupabase)
.getAllAlerts(any<(List<Alert>) -> Unit>(), any<(Exception) -> Unit>())
val n = Random.nextInt(EXAMPLES)
val alert = alerts[n]

viewModel.fetchAlerts()
assert(viewModel.palAlerts.value.contains(alert))
assert(viewModel.acceptedAlerts.value.isEmpty())
viewModel.acceptAlert(alert)
assertEquals(listOf(alert), viewModel.acceptedAlerts.value)
assert(!viewModel.palAlerts.value.contains(alert))
}

@Test
fun unAcceptAlertSuccess() = runBlocking {
doAnswer { it.getArgument<(List<Alert>) -> Unit>(0)(alerts) }
.`when`(alertModelSupabase)
.getAllAlerts(any<(List<Alert>) -> Unit>(), any<(Exception) -> Unit>())
val n = Random.nextInt(EXAMPLES)
val alert = alerts[n]

viewModel.fetchAlerts()
assert(viewModel.acceptedAlerts.value.isEmpty())
viewModel.acceptAlert(alert)
assertEquals(listOf(alert), viewModel.acceptedAlerts.value)
assert(!viewModel.palAlerts.value.contains(alert))

viewModel.unAcceptAlert(alert)
assert(viewModel.acceptedAlerts.value.isEmpty())
assert(viewModel.palAlerts.value.contains(alert))
}

@Test
fun formStateContainsCorrectFields() {
val formState = viewModel.formState
Expand Down

0 comments on commit 15a0697

Please sign in to comment.