From 0fa9457e955b8a233090eced4b03ead56d67b2ae Mon Sep 17 00:00:00 2001 From: Kolya Opahle <k.opahle@sap.com> Date: Fri, 11 Sep 2020 15:51:31 +0200 Subject: [PATCH] Implementation of tests for the interoperability countries selection screen (EXPOSUREAPP-2439) (#1140) * Added initial set of viewModel tests Signed-off-by: Kolya Opahle <k.opahle@sap.com> * Fail tests on unexpected null. Co-authored-by: Matthias Urhahn <matthias.urhahn@sap.com> --- .../SubmissionCountrySelectViewModelTest.kt | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/viewmodel/SubmissionCountrySelectViewModelTest.kt diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/viewmodel/SubmissionCountrySelectViewModelTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/viewmodel/SubmissionCountrySelectViewModelTest.kt new file mode 100644 index 000000000..6fc0545ed --- /dev/null +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/viewmodel/SubmissionCountrySelectViewModelTest.kt @@ -0,0 +1,59 @@ +package de.rki.coronawarnapp.ui.submission.viewmodel + +import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import de.rki.coronawarnapp.ui.submission.SubmissionCountry +import io.kotest.inspectors.forAll +import io.kotest.inspectors.forAtLeastOne +import io.kotest.inspectors.forAtMostOne +import io.kotest.matchers.collections.shouldHaveSize +import io.kotest.matchers.shouldBe +import org.junit.Rule +import org.junit.Test + +class SubmissionCountrySelectViewModelTest { + @get:Rule + val instantTaskExecRule = InstantTaskExecutorRule() + + @Test + fun testFetchCountries() { + val viewModel = SubmissionCountrySelectViewModel() + + viewModel.fetchCountries() + // TODO: implement proper test one backend is merged + viewModel.countries.value!!.shouldHaveSize(2) + } + + @Test + fun testUpdateCountryCheckedState() { + val viewModel = SubmissionCountrySelectViewModel() + + viewModel.fetchCountries() + + viewModel.updateCountryCheckedState(SubmissionCountry("IT", true)) + viewModel.countries.value!!.forAtMostOne { + it.countryCode shouldBe "IT" + it.selected shouldBe true + } + + viewModel.updateCountryCheckedState(SubmissionCountry("IT", false)) + viewModel.countries.value!!.forAtLeastOne { + it.countryCode shouldBe "IT" + it.selected shouldBe false + } + } + + @Test + fun testNoInfoClickRemovesSelections() { + val viewModel = SubmissionCountrySelectViewModel() + + viewModel.fetchCountries() + + viewModel.updateCountryCheckedState(SubmissionCountry("IT", true)) + viewModel.updateCountryCheckedState(SubmissionCountry("ES", true)) + viewModel.countries.value!!.forAll { it.selected shouldBe true } + + viewModel.noInfoClick() + + viewModel.countries.value!!.forAll { it.selected shouldBe false } + } +} -- GitLab