From ff3f543eae3d84bb1b71e4b1d5eb57117fce6983 Mon Sep 17 00:00:00 2001
From: Mohamed Metwalli <mohamed.metwalli@sap.com>
Date: Thu, 3 Jun 2021 17:40:58 +0200
Subject: [PATCH] Screenshots Request DCC (EXPOSUREAPP-7434) (#3352)

* Rename package

* Create test

Co-authored-by: Alex Paulescu <alex.paulescu@gmail.com>
---
 .../RequestCovidCertificateFragmentTest.kt    | 116 ++++++++++++++++++
 .../FragmentTestModuleRegistrar.kt            |   4 +-
 .../RequestCovidCertificateFragment.kt        |   2 +-
 .../RequestCovidCertificateFragmentModule.kt  |   2 +-
 .../RequestCovidCertificateViewModel.kt       |   2 +-
 .../RequestDccNavEvent.kt                     |   2 +-
 .../viewmodel/SubmissionFragmentModule.kt     |   8 +-
 .../fragment_request_covid_certificate.xml    |   2 +-
 .../src/main/res/navigation/nav_graph.xml     |   2 +-
 .../RequestCovidCertificateViewModelTest.kt   |   2 +-
 10 files changed, 130 insertions(+), 12 deletions(-)
 create mode 100644 Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragmentTest.kt
 rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/{greencertificate => covidcertificate}/RequestCovidCertificateFragment.kt (99%)
 rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/{greencertificate => covidcertificate}/RequestCovidCertificateFragmentModule.kt (90%)
 rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/{greencertificate => covidcertificate}/RequestCovidCertificateViewModel.kt (98%)
 rename Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/{greencertificate => covidcertificate}/RequestDccNavEvent.kt (72%)
 rename Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/{greencertificate => covidcertificate}/RequestCovidCertificateViewModelTest.kt (99%)

diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragmentTest.kt
new file mode 100644
index 000000000..68b8a1b80
--- /dev/null
+++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragmentTest.kt
@@ -0,0 +1,116 @@
+package de.rki.coronawarnapp.ui.submission.covidcertificate
+
+import androidx.lifecycle.MutableLiveData
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.action.ViewActions.click
+import androidx.test.espresso.action.ViewActions.swipeUp
+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 de.rki.coronawarnapp.coronatest.qrcode.CoronaTestQRCode
+import de.rki.coronawarnapp.ui.submission.ApiRequestState
+import de.rki.coronawarnapp.ui.submission.qrcode.QrCodeRegistrationStateProcessor
+import io.mockk.MockKAnnotations
+import io.mockk.every
+import io.mockk.impl.annotations.MockK
+import org.joda.time.Instant
+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
+
+@RunWith(AndroidJUnit4::class)
+class RequestCovidCertificateFragmentTest : BaseUITest() {
+
+    @MockK lateinit var viewModel: RequestCovidCertificateViewModel
+
+    @Before
+    fun setup() {
+        MockKAnnotations.init(this, relaxed = true)
+
+        every { viewModel.birthDate } returns MutableLiveData(null)
+        every { viewModel.registrationState } returns MutableLiveData(
+            QrCodeRegistrationStateProcessor.RegistrationState(ApiRequestState.IDLE)
+        )
+
+        setupMockViewModel(
+            object : RequestCovidCertificateViewModel.Factory {
+                override fun create(
+                    coronaTestQrCode: CoronaTestQRCode,
+                    coronaTestConsent: Boolean,
+                    deleteOldTest: Boolean
+                ): RequestCovidCertificateViewModel = viewModel
+            }
+        )
+    }
+
+    @Test
+    fun launch_fragment_pcr() {
+        val args = RequestCovidCertificateFragmentArgs(
+            CoronaTestQRCode.PCR(qrCodeGUID = "GUID")
+        ).toBundle()
+        launchFragmentInContainer2<RequestCovidCertificateFragment>(fragmentArgs = args)
+    }
+
+    @Test
+    fun launch_fragment_rat() {
+        val args = RequestCovidCertificateFragmentArgs(
+            CoronaTestQRCode.RapidAntigen(hash = "hash", createdAt = Instant.EPOCH)
+        ).toBundle()
+        launchFragmentInContainer2<RequestCovidCertificateFragment>(fragmentArgs = args)
+    }
+
+    @Test
+    @Screenshot
+    fun capture_fragment_pcr() {
+        val args = RequestCovidCertificateFragmentArgs(
+            CoronaTestQRCode.PCR(qrCodeGUID = "GUID")
+        ).toBundle()
+        launchFragmentInContainer2<RequestCovidCertificateFragment>(fragmentArgs = args)
+        takeScreenshot<RequestCovidCertificateFragment>("pcr")
+
+        onView(withId(R.id.scrollview)).perform(swipeUp())
+        takeScreenshot<RequestCovidCertificateFragment>("pcr_2")
+    }
+
+    @Test
+    @Screenshot
+    fun capture_fragment_pcr_birthdate_dialog() {
+        val args = RequestCovidCertificateFragmentArgs(
+            CoronaTestQRCode.PCR(qrCodeGUID = "GUID")
+        ).toBundle()
+        launchFragmentInContainer2<RequestCovidCertificateFragment>(fragmentArgs = args)
+        onView(withId(R.id.date_input_edit)).perform(click())
+        takeScreenshot<RequestCovidCertificateFragment>("date_picker")
+    }
+
+    @Test
+    @Screenshot
+    fun capture_fragment_rat() {
+        val args = RequestCovidCertificateFragmentArgs(
+            CoronaTestQRCode.RapidAntigen(hash = "hash", createdAt = Instant.EPOCH)
+        ).toBundle()
+        launchFragmentInContainer2<RequestCovidCertificateFragment>(fragmentArgs = args)
+        takeScreenshot<RequestCovidCertificateFragment>("rat")
+
+        onView(withId(R.id.scrollview)).perform(swipeUp())
+        takeScreenshot<RequestCovidCertificateFragment>("rat_2")
+    }
+
+    @After
+    fun teardown() {
+        clearAllViewModels()
+    }
+}
+
+@Module
+abstract class RequestCovidCertificateFragmentTestModule {
+    @ContributesAndroidInjector
+    abstract fun requestCovidCertificateFragment(): RequestCovidCertificateFragment
+}
diff --git a/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt b/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt
index 937486ea3..c2cd3038e 100644
--- a/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt
+++ b/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt
@@ -35,6 +35,7 @@ import de.rki.coronawarnapp.ui.submission.SubmissionTestResultTestAvailableModul
 import de.rki.coronawarnapp.ui.submission.SubmissionTestResultTestModule
 import de.rki.coronawarnapp.ui.submission.SubmissionTestResultTestNegativeModule
 import de.rki.coronawarnapp.ui.submission.SubmissionYourConsentFragmentTestModule
+import de.rki.coronawarnapp.ui.submission.covidcertificate.RequestCovidCertificateFragmentTestModule
 import de.rki.coronawarnapp.ui.tracing.TracingDetailsFragmentTestTestModule
 import de.rki.coronawarnapp.ui.vaccination.VaccinationConsentFragmentTestModule
 import de.rki.coronawarnapp.vaccination.ui.details.VaccinationDetailsFragmentTestModule
@@ -88,7 +89,8 @@ import de.rki.coronawarnapp.vaccination.ui.list.VaccinationListFragmentTestModul
         // Vaccination
         VaccinationDetailsFragmentTestModule::class,
         VaccinationConsentFragmentTestModule::class,
-        VaccinationListFragmentTestModule::class
+        VaccinationListFragmentTestModule::class,
+        RequestCovidCertificateFragmentTestModule::class,
     ]
 )
 class FragmentTestModuleRegistrar
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragment.kt
similarity index 99%
rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateFragment.kt
rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragment.kt
index 6ada9a974..2635a01a5 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateFragment.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragment.kt
@@ -1,4 +1,4 @@
-package de.rki.coronawarnapp.ui.submission.greencertificate
+package de.rki.coronawarnapp.ui.submission.covidcertificate
 
 import android.os.Bundle
 import androidx.fragment.app.Fragment
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateFragmentModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragmentModule.kt
similarity index 90%
rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateFragmentModule.kt
rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragmentModule.kt
index 74c2e8f20..6bc12c024 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateFragmentModule.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateFragmentModule.kt
@@ -1,4 +1,4 @@
-package de.rki.coronawarnapp.ui.submission.greencertificate
+package de.rki.coronawarnapp.ui.submission.covidcertificate
 
 import dagger.Binds
 import dagger.Module
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateViewModel.kt
similarity index 98%
rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateViewModel.kt
rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateViewModel.kt
index e6603079d..ff0e272e7 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateViewModel.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateViewModel.kt
@@ -1,4 +1,4 @@
-package de.rki.coronawarnapp.ui.submission.greencertificate
+package de.rki.coronawarnapp.ui.submission.covidcertificate
 
 import androidx.lifecycle.LiveData
 import androidx.lifecycle.MutableLiveData
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestDccNavEvent.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestDccNavEvent.kt
similarity index 72%
rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestDccNavEvent.kt
rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestDccNavEvent.kt
index 1bb251b76..d1b3d8c60 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestDccNavEvent.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestDccNavEvent.kt
@@ -1,4 +1,4 @@
-package de.rki.coronawarnapp.ui.submission.greencertificate
+package de.rki.coronawarnapp.ui.submission.covidcertificate
 
 sealed class RequestDccNavEvent
 object ToDispatcherScreen : RequestDccNavEvent()
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/viewmodel/SubmissionFragmentModule.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/viewmodel/SubmissionFragmentModule.kt
index 2f0c1d509..fe135a5d3 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/viewmodel/SubmissionFragmentModule.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/viewmodel/SubmissionFragmentModule.kt
@@ -8,8 +8,8 @@ import de.rki.coronawarnapp.ui.submission.fragment.SubmissionContactFragment
 import de.rki.coronawarnapp.ui.submission.fragment.SubmissionDispatcherFragment
 import de.rki.coronawarnapp.ui.submission.deletionwarning.SubmissionDeletionWarningFragment
 import de.rki.coronawarnapp.ui.submission.deletionwarning.SubmissionDeletionWarningModule
-import de.rki.coronawarnapp.ui.submission.greencertificate.RequestCovidCertificateFragment
-import de.rki.coronawarnapp.ui.submission.greencertificate.RequestCovidCertificateFragmentModule
+import de.rki.coronawarnapp.ui.submission.covidcertificate.RequestCovidCertificateFragment
+import de.rki.coronawarnapp.ui.submission.covidcertificate.RequestCovidCertificateFragmentModule
 import de.rki.coronawarnapp.ui.submission.qrcode.consent.SubmissionConsentFragment
 import de.rki.coronawarnapp.ui.submission.qrcode.consent.SubmissionConsentModule
 import de.rki.coronawarnapp.ui.submission.qrcode.scan.SubmissionQRCodeScanFragment
@@ -102,7 +102,7 @@ internal abstract class SubmissionFragmentModule {
     abstract fun submissionTestResultNoConsentScreen(): SubmissionTestResultNoConsentFragment
 
     @ContributesAndroidInjector(modules = [SubmissionResultPositiveOtherWarningNoConsentModule::class])
-    abstract fun SubmissionResultPositiveOtherWarningNoConsentScreen(): SubmissionResultPositiveOtherWarningNoConsentFragment
+    abstract fun submissionResultPositiveOtherWarningNoConsentScreen(): SubmissionResultPositiveOtherWarningNoConsentFragment
 
     @ContributesAndroidInjector(modules = [SubmissionDeletionWarningModule::class])
     abstract fun submissionDeletionWarningScreen(): SubmissionDeletionWarningFragment
@@ -114,5 +114,5 @@ internal abstract class SubmissionFragmentModule {
     abstract fun submissionTestResultKeysSharedScreen(): SubmissionTestResultKeysSharedFragment
 
     @ContributesAndroidInjector(modules = [RequestCovidCertificateFragmentModule::class])
-    abstract fun requestGreenCertificateFragment(): RequestCovidCertificateFragment
+    abstract fun requestCovidCertificateFragment(): RequestCovidCertificateFragment
 }
diff --git a/Corona-Warn-App/src/main/res/layout/fragment_request_covid_certificate.xml b/Corona-Warn-App/src/main/res/layout/fragment_request_covid_certificate.xml
index 7129eb51e..31c266359 100644
--- a/Corona-Warn-App/src/main/res/layout/fragment_request_covid_certificate.xml
+++ b/Corona-Warn-App/src/main/res/layout/fragment_request_covid_certificate.xml
@@ -5,7 +5,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@color/colorBackground"
-    tools:context="ui.submission.greencertificate.RequestCovidCertificateFragment">
+    tools:context="ui.submission.covidcertificate.RequestCovidCertificateFragment">
 
     <com.google.android.material.appbar.MaterialToolbar
         android:id="@+id/toolbar"
diff --git a/Corona-Warn-App/src/main/res/navigation/nav_graph.xml b/Corona-Warn-App/src/main/res/navigation/nav_graph.xml
index 919fadb96..8d879a4bb 100644
--- a/Corona-Warn-App/src/main/res/navigation/nav_graph.xml
+++ b/Corona-Warn-App/src/main/res/navigation/nav_graph.xml
@@ -830,7 +830,7 @@
         app:destination="@id/qrCodeFullScreenFragment" />
     <fragment
         android:id="@+id/requestCovidCertificateFragment"
-        android:name="de.rki.coronawarnapp.ui.submission.greencertificate.RequestCovidCertificateFragment"
+        android:name="de.rki.coronawarnapp.ui.submission.covidcertificate.RequestCovidCertificateFragment"
         android:label="fragment_request_covid_certificate"
         tools:layout="@layout/fragment_request_covid_certificate">
         <argument
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateViewModelTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateViewModelTest.kt
similarity index 99%
rename from Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateViewModelTest.kt
rename to Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateViewModelTest.kt
index bd9be00a5..0dd5558e9 100644
--- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/greencertificate/RequestCovidCertificateViewModelTest.kt
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ui/submission/covidcertificate/RequestCovidCertificateViewModelTest.kt
@@ -1,4 +1,4 @@
-package de.rki.coronawarnapp.ui.submission.greencertificate
+package de.rki.coronawarnapp.ui.submission.covidcertificate
 
 import androidx.lifecycle.MutableLiveData
 import de.rki.coronawarnapp.coronatest.CoronaTestRepository
-- 
GitLab