diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/main/home/HomeData.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/main/home/HomeData.kt index 8966f716c4a63d2fd8142e319f03d034822c223a..8f89855cf01a8d2882cbf0a1b6234b876f76625f 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/main/home/HomeData.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/main/home/HomeData.kt @@ -29,6 +29,12 @@ import de.rki.coronawarnapp.tracing.ui.homecards.TracingDisabledCard import de.rki.coronawarnapp.tracing.ui.homecards.TracingFailedCard import de.rki.coronawarnapp.tracing.ui.homecards.TracingProgressCard import de.rki.coronawarnapp.util.TimeAndDateExtensions.toLocalDateUtc +import de.rki.coronawarnapp.vaccination.core.VaccinatedPerson +import de.rki.coronawarnapp.vaccination.ui.homecard.ImmuneVaccinationHomeCard +import de.rki.coronawarnapp.vaccination.ui.homecard.VaccinationHomeCard +import io.mockk.every +import io.mockk.mockk +import org.joda.time.Duration import org.joda.time.Instant object HomeData { @@ -169,4 +175,34 @@ object HomeData { onClickAction = {} ) } + + object Vaccination { + val INCOMPLETE = VaccinationHomeCard.Item( + vaccinatedPerson = mockk<VaccinatedPerson>().apply { + every { fullName } returns "Andrea Schneider" + every { identifier } returns mockk() + every { getVaccinationStatus(any()) } returns VaccinatedPerson.Status.INCOMPLETE + every { getTimeUntilImmunity(any()) } returns Duration.standardDays(14) + }, + onClickAction = {} + ) + val COMPLETE = VaccinationHomeCard.Item( + vaccinatedPerson = mockk<VaccinatedPerson>().apply { + every { fullName } returns "Andrea Schneider" + every { identifier } returns mockk() + every { getVaccinationStatus(any()) } returns VaccinatedPerson.Status.COMPLETE + every { getTimeUntilImmunity(any()) } returns Duration.standardDays(14) + }, + onClickAction = {} + ) + val IMMUNITY = ImmuneVaccinationHomeCard.Item( + vaccinatedPerson = mockk<VaccinatedPerson>().apply { + every { fullName } returns "Andrea Schneider" + every { identifier } returns mockk() + every { getVaccinationStatus(any()) } returns VaccinatedPerson.Status.IMMUNITY + every { getTimeUntilImmunity(any()) } returns Duration.standardDays(14) + }, + onClickAction = {} + ) + } } diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentTest.kt index 3df630d6cb70d01d8af5578bd46ec4f27b85de7d..03430513efd136f91f631d65df8dfbd2df483029 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/main/home/HomeFragmentTest.kt @@ -35,6 +35,7 @@ import de.rki.coronawarnapp.util.ui.SingleLiveEvent import de.rki.coronawarnapp.vaccination.core.VaccinationSettings import de.rki.coronawarnapp.vaccination.core.repository.VaccinationRepository import de.rki.coronawarnapp.vaccination.ui.homecard.CreateVaccinationHomeCard +import de.rki.coronawarnapp.vaccination.ui.homecard.VaccinationStatusItem import io.mockk.MockKAnnotations import io.mockk.Runs import io.mockk.every @@ -90,7 +91,7 @@ class HomeFragmentTest : BaseUITest() { every { refreshRequiredData() } just Runs every { tracingHeaderState } returns MutableLiveData(TracingHeaderState.TracingActive) every { showLoweredRiskLevelDialog } returns MutableLiveData() - every { homeItems } returns MutableLiveData(emptyList()) + every { homeItems } returns homeFragmentItemsLiveData() every { popupEvents } returns SingleLiveEvent() every { showPopUps() } just Runs every { restoreAppShortcuts() } just Runs @@ -273,6 +274,51 @@ class HomeFragmentTest : BaseUITest() { captureHomeFragment("compatibility_ble_scan_not_supported") } + @Screenshot + @Test + fun captureVaccinationNoCertificate() { + launchInMainActivity<HomeFragment>() + onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2, additionalY = 450)) + + takeScreenshot<HomeFragment>("vaccination_none") + } + + @Screenshot + @Test + fun captureVaccinationIncomplete() { + every { homeFragmentViewModel.homeItems } returns homeFragmentItemsLiveData( + vaccinationStatus = HomeData.Vaccination.INCOMPLETE + ) + launchInMainActivity<HomeFragment>() + onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2)) + + takeScreenshot<HomeFragment>("vaccination_incomplete") + } + + @Screenshot + @Test + fun captureVaccinationComplete() { + every { homeFragmentViewModel.homeItems } returns homeFragmentItemsLiveData( + vaccinationStatus = HomeData.Vaccination.COMPLETE + ) + launchInMainActivity<HomeFragment>() + onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2)) + + takeScreenshot<HomeFragment>("vaccination_complete") + } + + @Screenshot + @Test + fun captureVaccinationImmunity() { + every { homeFragmentViewModel.homeItems } returns homeFragmentItemsLiveData( + vaccinationStatus = HomeData.Vaccination.IMMUNITY + ) + launchInMainActivity<HomeFragment>() + onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2)) + + takeScreenshot<HomeFragment>("vaccination_immunity") + } + @After fun teardown() { clearAllViewModels() @@ -314,7 +360,8 @@ class HomeFragmentTest : BaseUITest() { // LiveData item for fragments private fun homeFragmentItemsLiveData( tracingStateItem: TracingStateItem = HomeData.Tracing.LOW_RISK_ITEM_WITH_ENCOUNTERS, - submissionTestResultItem: TestResultItem = HomeData.Submission.TEST_UNREGISTERED_ITEM + submissionTestResultItem: TestResultItem = HomeData.Submission.TEST_UNREGISTERED_ITEM, + vaccinationStatus: VaccinationStatusItem? = null, ): LiveData<List<HomeItem>> = MutableLiveData( mutableListOf<HomeItem>().apply { @@ -325,8 +372,15 @@ class HomeFragmentTest : BaseUITest() { } else -> add(tracingStateItem) } + + vaccinationStatus?.let { + add(it) + } + add(submissionTestResultItem) + add(CreateVaccinationHomeCard.Item {}) + Statistics.statisticsData?.let { add(StatisticsHomeCard.Item(data = it, onHelpAction = { })) } diff --git a/Corona-Warn-App/src/androidTest/java/testhelpers/ViewActions.kt b/Corona-Warn-App/src/androidTest/java/testhelpers/ViewActions.kt index ab0e0e65d36e005edde33439106fcfda24c0fb06..ca567a039bfa44626ec0aa88f9d770f1c183811b 100644 --- a/Corona-Warn-App/src/androidTest/java/testhelpers/ViewActions.kt +++ b/Corona-Warn-App/src/androidTest/java/testhelpers/ViewActions.kt @@ -13,9 +13,21 @@ import com.google.android.material.tabs.TabLayout import org.hamcrest.CoreMatchers.allOf import org.hamcrest.Matcher -fun recyclerScrollTo(position: Int? = null): ViewAction = RecyclerViewScrollAction(position) +fun recyclerScrollTo( + position: Int? = null, + additionalX: Int = 0, + additionalY: Int = 0, +): ViewAction = RecyclerViewScrollAction( + position = position, + additionalX = additionalX, + additionalY = additionalY +) -private class RecyclerViewScrollAction(private val position: Int? = null) : ViewAction { +private class RecyclerViewScrollAction( + private val position: Int? = null, + private val additionalX: Int = 0, + private val additionalY: Int = 0, +) : ViewAction { override fun getDescription(): String { return "scroll RecyclerView to bottom" } @@ -30,6 +42,8 @@ private class RecyclerViewScrollAction(private val position: Int? = null) : View val itemPosition = position ?: itemCount?.minus(1) ?: 0 recyclerView.scrollToPosition(itemPosition) uiController.loopMainThreadUntilIdle() + recyclerView.scrollBy(additionalX, additionalY) + uiController.loopMainThreadUntilIdle() } }