From fb1689210b1cc3bc23fcc539cb18f0ea15ceed84 Mon Sep 17 00:00:00 2001 From: Nikolaus Schauersberger Date: Fri, 13 Jan 2023 15:29:48 +0100 Subject: [PATCH 1/6] add screenshot tests --- .../ui/checkins/SrsCheckinsFragmentTest.kt | 101 ++++++++++++++++++ .../SrsSubmissionConsentFragmentTest.kt | 10 +- .../ui/done/SrsSubmissionDoneFragmentTest.kt | 35 ++++++ .../SrsTypeSelectionFragmentTest.kt | 2 +- .../ui/main/home/HomeFragmentTest.kt | 10 ++ .../SubmissionDispatcherFragmentTest.kt | 6 +- .../FragmentTestModuleRegistrar.kt | 4 + 7 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/checkins/SrsCheckinsFragmentTest.kt create mode 100644 Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/done/SrsSubmissionDoneFragmentTest.kt diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/checkins/SrsCheckinsFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/checkins/SrsCheckinsFragmentTest.kt new file mode 100644 index 00000000000..c05bf22b75b --- /dev/null +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/checkins/SrsCheckinsFragmentTest.kt @@ -0,0 +1,101 @@ +package de.rki.coronawarnapp.srs.ui.checkins + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.SavedStateHandle +import androidx.test.ext.junit.runners.AndroidJUnit4 +import dagger.Module +import dagger.android.ContributesAndroidInjector +import de.rki.coronawarnapp.presencetracing.checkins.CheckIn +import de.rki.coronawarnapp.srs.core.model.SrsSubmissionType +import de.rki.coronawarnapp.ui.presencetracing.attendee.checkins.consent.SelectableCheckInVH.Item +import de.rki.coronawarnapp.util.ui.SingleLiveEvent +import io.mockk.MockKAnnotations +import io.mockk.every +import io.mockk.impl.annotations.MockK +import io.mockk.mockk +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import testhelpers.BaseUITest +import testhelpers.Screenshot +import testhelpers.launchFragmentInContainer2 +import testhelpers.takeScreenshot +import java.time.Instant + +@RunWith(AndroidJUnit4::class) +class SrsCheckinsFragmentTest : BaseUITest() { + + @MockK lateinit var viewModel: SrsCheckinsFragmentViewModel + + private val fragmentArgs = SrsCheckinsFragmentArgs(submissionType = SrsSubmissionType.SRS_OTHER).toBundle() + + @Before + fun setup() { + MockKAnnotations.init(this, relaxed = true) + + viewModel.apply { + every { events } returns SingleLiveEvent() + every { checkIns } returns MutableLiveData( + listOf( + Item( + mockCheckIn( + checkInId = 1, + checkInDescription = "Frisör", + checkInAddress = "Berlin" + ) + ) {}, + Item( + mockCheckIn( + checkInId = 2, + checkInDescription = "Restaurant", + checkInAddress = "Berlin" + ) + ) {} + ) + ) + } + + setupMockViewModel( + object : SrsCheckinsFragmentViewModel.Factory { + override fun create( + savedState: SavedStateHandle, + submissionType: SrsSubmissionType + ): SrsCheckinsFragmentViewModel = viewModel + } + ) + } + + @After + fun teardown() { + clearAllViewModels() + } + + @Test + @Screenshot + fun capture_fragment() { + launchFragmentInContainer2( + fragmentArgs = fragmentArgs + ) + takeScreenshot() + } + + private fun mockCheckIn( + checkInId: Long, + checkInDescription: String, + checkInAddress: String + ) = mockk().apply { + every { id } returns checkInId + every { description } returns checkInDescription + every { address } returns checkInAddress + every { hasSubmissionConsent } returns true + every { checkInStart } returns Instant.ofEpochSecond(1624291200L) + every { checkInEnd } returns Instant.ofEpochSecond(1624302000L) + } +} + +@Module +abstract class SrsCheckinsFragmentTestModule { + @ContributesAndroidInjector + abstract fun srsCheckinsScreen(): SrsCheckinsFragment +} diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/consent/SrsSubmissionConsentFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/consent/SrsSubmissionConsentFragmentTest.kt index 9d3d0266008..286f40801c6 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/consent/SrsSubmissionConsentFragmentTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/consent/SrsSubmissionConsentFragmentTest.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.ViewModelStore import androidx.navigation.testing.TestNavHostController import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.swipeUp +import androidx.test.espresso.action.ViewActions.scrollTo import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.internal.runner.junit4.statement.UiThreadStatement @@ -77,8 +77,14 @@ class SrsSubmissionConsentFragmentTest : BaseUITest() { ) takeScreenshot("1") - onView(withId(R.id.content_scrollcontainer)).perform(swipeUp()) + onView(withId(R.id.first_bulletpoint)).perform(scrollTo()) takeScreenshot("2") + + onView(withId(R.id.third_bulletpoint)).perform(scrollTo()) + takeScreenshot("3") + + onView(withId(R.id.srs_submission_consent_more_info)).perform(scrollTo()) + takeScreenshot("4") } } diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/done/SrsSubmissionDoneFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/done/SrsSubmissionDoneFragmentTest.kt new file mode 100644 index 00000000000..fb935a90664 --- /dev/null +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/done/SrsSubmissionDoneFragmentTest.kt @@ -0,0 +1,35 @@ +package de.rki.coronawarnapp.srs.ui.done + +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.runners.AndroidJUnit4 +import dagger.Module +import dagger.android.ContributesAndroidInjector +import de.rki.coronawarnapp.R +import org.junit.Test +import org.junit.runner.RunWith +import testhelpers.BaseUITest +import testhelpers.Screenshot +import testhelpers.launchFragmentInContainer2 +import testhelpers.takeScreenshot + +@RunWith(AndroidJUnit4::class) +class SrsSubmissionDoneFragmentTest : BaseUITest() { + + @Test + @Screenshot + fun capture_fragment() { + launchFragmentInContainer2() + takeScreenshot() + + onView(withId(R.id.further_info_text)).perform(ViewActions.scrollTo()) + takeScreenshot("1") + } +} + +@Module +abstract class SrsSubmissionDoneFragmentTestModule { + @ContributesAndroidInjector + abstract fun srsSubmissionDoneScreen(): SrsSubmissionDoneFragment +} diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/typeselection/SrsTypeSelectionFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/typeselection/SrsTypeSelectionFragmentTest.kt index aeb2cac42ca..fbab961458f 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/typeselection/SrsTypeSelectionFragmentTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/typeselection/SrsTypeSelectionFragmentTest.kt @@ -30,7 +30,7 @@ class SrsTypeSelectionFragmentTest : BaseUITest() { viewModel.apply { every { navigation } returns SingleLiveEvent() every { types } returns MutableLiveData( - SrsSubmissionType.values().toList().map { + SrsSubmissionType.values().filterNot { it == SrsSubmissionType.SRS_SELF_TEST }.toList().map { SrsTypeSelectionItem(submissionType = it) } ) 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 4e13b3c2e0a..4c80d429dd2 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 @@ -302,6 +302,16 @@ class HomeFragmentTest : BaseUITest() { takeScreenshot("vaccination_none") } + @Screenshot + @Test + fun captureSubmissionTestCard() { + launchInMainActivity( + testNavHostController = navController + ) + onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2, additionalY = -300)) + takeScreenshot("submission_test_card") + } + @After fun teardown() { clearAllViewModels() diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/submission/SubmissionDispatcherFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/submission/SubmissionDispatcherFragmentTest.kt index 04643d7f0e8..691e7b6ed30 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/submission/SubmissionDispatcherFragmentTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/submission/SubmissionDispatcherFragmentTest.kt @@ -120,8 +120,10 @@ class SubmissionDispatcherFragmentTest : BaseUITest() { launchFragmentInContainer2() takeScreenshot() - onView(withId(R.id.profile_card)) - .perform(scrollTo()) + onView(withId(R.id.submission_dispatcher_qr)).perform(scrollTo()) + takeScreenshot("1") + + onView(withId(R.id.profile_card)).perform(scrollTo()) takeScreenshot("2") } } diff --git a/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt b/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt index f366e4629ea..da6574bab7c 100644 --- a/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt +++ b/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt @@ -25,7 +25,9 @@ import de.rki.coronawarnapp.profile.ui.list.ProfileListFragmentTestModule import de.rki.coronawarnapp.profile.ui.onboarding.ProfileOnboardingFragmentTestModule import de.rki.coronawarnapp.qrcode.ui.QrCodeScannerFragmentTestModule import de.rki.coronawarnapp.reyclebin.ui.RecyclerBinOverviewFragmentTestModule +import de.rki.coronawarnapp.srs.ui.checkins.SrsCheckinsFragmentTestModule import de.rki.coronawarnapp.srs.ui.consent.SrsSubmissionConsentFragmentTestModule +import de.rki.coronawarnapp.srs.ui.done.SrsSubmissionDoneFragmentTestModule import de.rki.coronawarnapp.srs.ui.typeselection.SrsTypeSelectionFragmentTestModule import de.rki.coronawarnapp.ui.contactdiary.ContactDiaryDayFragmentTestModule import de.rki.coronawarnapp.ui.contactdiary.ContactDiaryEditLocationsFragmentTestModule @@ -102,6 +104,8 @@ import kotlinx.coroutines.test.TestScope SrsSubmissionConsentFragmentTestModule::class, SrsTypeSelectionFragmentTestModule::class, SubmissionDoneFragmentTestModule::class, + SrsCheckinsFragmentTestModule::class, + SrsSubmissionDoneFragmentTestModule::class, // -------- Tracing -------- TracingDetailsFragmentTestTestModule::class, From 9670d0c6cf902dac0506eea4fcbcd724c551a365 Mon Sep 17 00:00:00 2001 From: Nikolaus Schauersberger Date: Fri, 13 Jan 2023 15:35:52 +0100 Subject: [PATCH 2/6] run on push --- .github/workflows/screenshots.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/screenshots.yml b/.github/workflows/screenshots.yml index 2d8cf82bac9..250f87f6717 100644 --- a/.github/workflows/screenshots.yml +++ b/.github/workflows/screenshots.yml @@ -2,8 +2,8 @@ name: Create Screenshots on: push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+*' + #tags: + #- 'v[0-9]+.[0-9]+.[0-9]+*' env: JVM_OPTS: -Xmx4096m From 125a5c6faca9c4014c371da16e09d2279fdacb8b Mon Sep 17 00:00:00 2001 From: Nikolaus Schauersberger Date: Fri, 13 Jan 2023 16:50:06 +0100 Subject: [PATCH 3/6] change view id reference --- .../srs/ui/done/SrsSubmissionDoneFragmentTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/done/SrsSubmissionDoneFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/done/SrsSubmissionDoneFragmentTest.kt index fb935a90664..e343d1d5e72 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/done/SrsSubmissionDoneFragmentTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/srs/ui/done/SrsSubmissionDoneFragmentTest.kt @@ -1,7 +1,7 @@ package de.rki.coronawarnapp.srs.ui.done import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.action.ViewActions.scrollTo import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.ext.junit.runners.AndroidJUnit4 import dagger.Module @@ -23,7 +23,7 @@ class SrsSubmissionDoneFragmentTest : BaseUITest() { launchFragmentInContainer2() takeScreenshot() - onView(withId(R.id.further_info_text)).perform(ViewActions.scrollTo()) + onView(withId(R.id.further_info_title)).perform(scrollTo()) takeScreenshot("1") } } From 8e47699311027d25e3108995361b8aa29d9aeb70 Mon Sep 17 00:00:00 2001 From: Nikolaus Schauersberger Date: Mon, 16 Jan 2023 08:58:49 +0100 Subject: [PATCH 4/6] change scroll position --- .../java/de/rki/coronawarnapp/ui/main/home/HomeFragmentTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4c80d429dd2..09b262255a5 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 @@ -308,7 +308,7 @@ class HomeFragmentTest : BaseUITest() { launchInMainActivity( testNavHostController = navController ) - onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2, additionalY = -300)) + onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2, additionalY = -700)) takeScreenshot("submission_test_card") } From 32ef4b94978a53d5b994214831be484c2abbba56 Mon Sep 17 00:00:00 2001 From: Nikolaus Schauersberger Date: Mon, 16 Jan 2023 15:14:52 +0100 Subject: [PATCH 5/6] change scrollposition --- .../java/de/rki/coronawarnapp/ui/main/home/HomeFragmentTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 09b262255a5..f47cad11415 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 @@ -308,7 +308,7 @@ class HomeFragmentTest : BaseUITest() { launchInMainActivity( testNavHostController = navController ) - onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2, additionalY = -700)) + onView(withId(R.id.recycler_view)).perform(recyclerScrollTo(2, additionalY = -900)) takeScreenshot("submission_test_card") } From 0910811671a6643c847d50f7d46b3bbe78d1621d Mon Sep 17 00:00:00 2001 From: Nikolaus Schauersberger Date: Mon, 16 Jan 2023 16:37:26 +0100 Subject: [PATCH 6/6] remove screenshots on push --- .github/workflows/screenshots.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/screenshots.yml b/.github/workflows/screenshots.yml index 250f87f6717..2d8cf82bac9 100644 --- a/.github/workflows/screenshots.yml +++ b/.github/workflows/screenshots.yml @@ -2,8 +2,8 @@ name: Create Screenshots on: push: - #tags: - #- 'v[0-9]+.[0-9]+.[0-9]+*' + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' env: JVM_OPTS: -Xmx4096m