diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentFragmentTest.kt index ff507c78862..3fff7acf694 100644 --- a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentFragmentTest.kt +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentFragmentTest.kt @@ -48,7 +48,7 @@ class DccReissuanceConsentFragmentTest : BaseUITest() { private val state = DccReissuanceConsentViewModel.State( certificateList = mutableListOf( - DccReissuanceConsentCard.Item( + DccReissuanceCertificateCard.Item( mockk { every { nameData } returns mockk { every { fullName } returns "Andrea Schneider" @@ -66,7 +66,7 @@ class DccReissuanceConsentFragmentTest : BaseUITest() { } } ), - DccReissuanceConsentCard.Item( + DccReissuanceCertificateCard.Item( mockk { every { nameData } returns mockk { every { fullName } returns "Andrea Schneider" diff --git a/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccerts/DccReissuanceAccCertsFragmentTest.kt b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccerts/DccReissuanceAccCertsFragmentTest.kt new file mode 100644 index 00000000000..d5ebf84e7b9 --- /dev/null +++ b/Corona-Warn-App/src/androidTest/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccerts/DccReissuanceAccCertsFragmentTest.kt @@ -0,0 +1,125 @@ +package de.rki.coronawarnapp.dccreissuance.ui.consent.acccerts + +import androidx.lifecycle.ViewModelStore +import androidx.lifecycle.liveData +import androidx.navigation.testing.TestNavHostController +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.internal.runner.junit4.statement.UiThreadStatement +import dagger.Module +import dagger.android.ContributesAndroidInjector +import de.rki.coronawarnapp.R +import de.rki.coronawarnapp.covidcertificate.common.certificate.CertificatePersonIdentifier +import de.rki.coronawarnapp.covidcertificate.common.certificate.VaccinationDccV1 +import de.rki.coronawarnapp.dccreissuance.ui.consent.DccReissuanceCertificateCard +import de.rki.coronawarnapp.dccreissuance.ui.consent.DccReissuanceItem +import io.mockk.MockKAnnotations +import io.mockk.every +import io.mockk.impl.annotations.RelaxedMockK +import io.mockk.mockk +import org.joda.time.LocalDate +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.launchFragment2 +import testhelpers.launchFragmentInContainer2 +import testhelpers.takeScreenshot + +@RunWith(AndroidJUnit4::class) +class DccReissuanceAccCertsFragmentTest : BaseUITest() { + + @RelaxedMockK lateinit var viewModel: DccReissuanceAccCertsViewModel + + private val navController = TestNavHostController( + context = ApplicationProvider.getApplicationContext() + ).apply { + UiThreadStatement.runOnUiThread { + setViewModelStore(ViewModelStore()) + setGraph(R.navigation.covid_certificates_graph) + setCurrentDestination(R.id.dccReissuanceAccCertsFragment) + } + } + + private val args = DccReissuanceAccCertsFragmentArgs(personIdentifierCode = "personIdentifierCode").toBundle() + + private val certificateList = mutableListOf( + DccReissuanceCertificateCard.Item( + mockk { + every { nameData } returns mockk { + every { fullName } returns "Andrea Schneider" + } + + every { vaccination } returns mockk { + every { doseNumber } returns 2 + every { totalSeriesOfDoses } returns 2 + every { vaccinatedOn } returns LocalDate.parse("2022-01-15") + every { personIdentifier } returns CertificatePersonIdentifier( + dateOfBirthFormatted = "1980-06-01", + lastNameStandardized = "Schneider", + firstNameStandardized = "Andrea" + ) + } + } + ), + DccReissuanceCertificateCard.Item( + mockk { + every { nameData } returns mockk { + every { fullName } returns "Andrea Schneider" + } + + every { vaccination } returns mockk { + every { doseNumber } returns 1 + every { totalSeriesOfDoses } returns 2 + every { vaccinatedOn } returns LocalDate.parse("2021-10-17") + every { personIdentifier } returns CertificatePersonIdentifier( + dateOfBirthFormatted = "1980-06-01", + lastNameStandardized = "Schneider", + firstNameStandardized = "Andrea" + ) + } + } + ) + ) + + @Before + fun setup() { + MockKAnnotations.init(this) + + every { viewModel.certificatesLiveData } returns liveData { emit(certificateList) } + + setupMockViewModel( + factory = object : DccReissuanceAccCertsViewModel.Factory { + override fun create(personIdentifierCode: String): DccReissuanceAccCertsViewModel = viewModel + } + ) + } + + @After + fun tearDown() { + clearAllViewModels() + } + + @Test + fun launch_fragment() { + launchFragment2(fragmentArgs = args) + } + + @Test + @Screenshot + fun capture_fragment() { + launchFragmentInContainer2( + testNavHostController = navController, + fragmentArgs = args + ) + takeScreenshot("1") + } +} + +@Module +abstract class DccReissuanceAccCertsFragmentTestModule { + @ContributesAndroidInjector + abstract fun dccReissuanceAccCertsFragment(): DccReissuanceAccCertsFragment +} diff --git a/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt b/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt index 9c485cd983a..c0e6c5af10a 100644 --- a/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt +++ b/Corona-Warn-App/src/androidTest/java/testhelpers/FragmentTestModuleRegistrar.kt @@ -12,6 +12,7 @@ import de.rki.coronawarnapp.covidcertificate.recovery.ui.RecoveryCertificateDeta import de.rki.coronawarnapp.covidcertificate.test.ui.CovidCertificateDetailsFragmentTestModule import de.rki.coronawarnapp.covidcertificate.vaccination.ui.details.VaccinationDetailsFragmentTestModule import de.rki.coronawarnapp.dccreissuance.ui.consent.DccReissuanceConsentFragmentTestModule +import de.rki.coronawarnapp.dccreissuance.ui.consent.acccerts.DccReissuanceAccCertsFragmentTestModule import de.rki.coronawarnapp.dccticketing.ui.certificateselection.DccTicketingCertificateSelectionFragmentModule import de.rki.coronawarnapp.dccticketing.ui.consent.one.DccTicketingConsentOneFragmentTestModule import de.rki.coronawarnapp.dccticketing.ui.consent.two.DccTicketingConsentTwoFragmentModule @@ -133,6 +134,7 @@ import kotlinx.coroutines.test.TestScope PersonDetailsFragmentTestModule::class, BoosterInfoDetailsFragmentTestModule::class, DccReissuanceConsentFragmentTestModule::class, + DccReissuanceAccCertsFragmentTestModule::class, // -------- Profile ------------ ProfileCreateFragmentTestModule::class, diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceAdapter.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceAdapter.kt index b8024780f1a..42a04c72f72 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceAdapter.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceAdapter.kt @@ -23,7 +23,9 @@ class DccReissuanceAdapter : listOf( StableIdMod(data), DataBinderMod>(data), - TypedVHCreatorMod({ data[it] is DccReissuanceConsentCard.Item }) { DccReissuanceConsentCard(it) } + TypedVHCreatorMod({ data[it] is DccReissuanceCertificateCard.Item }) { + DccReissuanceCertificateCard(it) + } ) ) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentCard.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceCertificateCard.kt similarity index 96% rename from Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentCard.kt rename to Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceCertificateCard.kt index 75d910563c7..83909080e95 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentCard.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceCertificateCard.kt @@ -12,8 +12,8 @@ import de.rki.coronawarnapp.util.TimeAndDateExtensions.toShortDayFormat import de.rki.coronawarnapp.util.TimeAndDateExtensions.toUserTimeZone import de.rki.coronawarnapp.util.lists.diffutil.HasPayloadDiffer -class DccReissuanceConsentCard(parent: ViewGroup) : - DccReissuanceAdapter.ItemVH( +class DccReissuanceCertificateCard(parent: ViewGroup) : + DccReissuanceAdapter.ItemVH( layoutRes = R.layout.dcc_reissuance_certificate_card, parent = parent ) { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentViewModel.kt index 8ea218d1f5e..438d5f98713 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentViewModel.kt @@ -68,7 +68,7 @@ class DccReissuanceConsentViewModel @AssistedInject constructor( dccCertificate.certificateToReissue.certificateRef.barcodeData, DccV1Parser.Mode.CERT_SINGLE_STRICT ).data.certificate.let { - DccReissuanceConsentCard.Item( + DccReissuanceCertificateCard.Item( it ) } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccerts/DccReissuanceAccCertsViewModel.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccerts/DccReissuanceAccCertsViewModel.kt index 6fcd85c9086..65df824e6a6 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccerts/DccReissuanceAccCertsViewModel.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccerts/DccReissuanceAccCertsViewModel.kt @@ -13,7 +13,7 @@ import de.rki.coronawarnapp.covidcertificate.person.core.PersonCertificatesProvi import de.rki.coronawarnapp.covidcertificate.recovery.core.qrcode.RecoveryCertificateQRCode import de.rki.coronawarnapp.covidcertificate.test.core.qrcode.TestCertificateQRCode import de.rki.coronawarnapp.covidcertificate.vaccination.core.qrcode.VaccinationCertificateQRCode -import de.rki.coronawarnapp.dccreissuance.ui.consent.DccReissuanceConsentCard +import de.rki.coronawarnapp.dccreissuance.ui.consent.DccReissuanceCertificateCard import de.rki.coronawarnapp.dccreissuance.ui.consent.DccReissuanceItem import de.rki.coronawarnapp.util.TimeAndDateExtensions.toLocalDateUserTz import de.rki.coronawarnapp.util.coroutine.DispatcherProvider @@ -47,7 +47,7 @@ class DccReissuanceAccCertsViewModel @AssistedInject constructor( null } }.sort().map { - DccReissuanceConsentCard.Item(it.data.certificate) + DccReissuanceCertificateCard.Item(it.data.certificate) } } diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/dccwalletinfo/model/CertificateReissuanceExtensionTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/dccwalletinfo/model/CertificateReissuanceExtensionTest.kt new file mode 100644 index 00000000000..aac77a5c628 --- /dev/null +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/dccwalletinfo/model/CertificateReissuanceExtensionTest.kt @@ -0,0 +1,161 @@ +package de.rki.coronawarnapp.ccl.dccwalletinfo.model + +import io.kotest.matchers.collections.shouldContainAll +import io.kotest.matchers.shouldBe +import io.mockk.mockk +import org.junit.jupiter.api.Test +import testhelpers.BaseTest + +internal class CertificateReissuanceExtensionTest : BaseTest() { + + val reissuanceDivision: ReissuanceDivision = mockk() + + private val certificateReissuanceLegacy = CertificateReissuance( + reissuanceDivision = reissuanceDivision, + certificateToReissue = Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringVac, + ) + ), + accompanyingCertificates = listOf( + Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringTest + ) + ) + ) + ) + + private val certificateReissuance = CertificateReissuance( + reissuanceDivision = reissuanceDivision, + certificates = listOf( + CertificateReissuanceItem( + certificateToReissue = Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringVac, + ) + ), + accompanyingCertificates = listOf( + Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringTest + ) + ) + ), + action = "renew" + ), + ) + ) + + private val certificateReissuance2 = CertificateReissuance( + reissuanceDivision = mockk(), + certificates = listOf( + CertificateReissuanceItem( + certificateToReissue = Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringVac, + ) + ), + accompanyingCertificates = listOf( + Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringTest + ) + ) + ), + action = "renew" + ), + CertificateReissuanceItem( + certificateToReissue = Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringTest, + ) + ), + accompanyingCertificates = listOf( + Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringVac + ) + ) + ), + action = "extend" + ), + ) + ) + + private val certificateReissuance3 = CertificateReissuance( + reissuanceDivision = mockk(), + certificates = listOf( + CertificateReissuanceItem( + certificateToReissue = Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringVac, + ) + ), + accompanyingCertificates = listOf( + Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringTest + ) + ) + ), + action = "renew" + ), + CertificateReissuanceItem( + certificateToReissue = Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringVac, + ) + ), + accompanyingCertificates = listOf( + Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringTest + ) + ) + ), + action = "extend" + ), + ) + ) + + @Test + fun `compat test`() { + certificateReissuanceLegacy.asCertificateReissuanceCompat() shouldBe + certificateReissuance + } + + @Test + fun `certificate consolidation test`() { + val set = certificateReissuance.consolidateAccompanyingCertificates() + set shouldContainAll + setOf( + Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringTest + ) + ) + ) + set.size shouldBe 1 + } + + @Test + fun `certificate consolidation test with certificates which accompany each other`() { + val set = certificateReissuance2.consolidateAccompanyingCertificates() + set.size shouldBe 0 + } + + @Test + fun `certificate consolidation test with duplicates`() { + val set = certificateReissuance3.consolidateAccompanyingCertificates() + set shouldContainAll + setOf( + Certificate( + certificateRef = CertificateRef( + barcodeData = qrCodeStringTest + ) + ) + ) + set.size shouldBe 1 + } +} diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentViewModelTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentViewModelTest.kt index e5bc75bffff..e99931c6c4e 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentViewModelTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/dccreissuance/ui/consent/DccReissuanceConsentViewModelTest.kt @@ -82,7 +82,7 @@ internal class DccReissuanceConsentViewModelTest : BaseTest() { @Test fun `getState works`() { viewModel().stateLiveData.getOrAwaitValue() shouldBe DccReissuanceConsentViewModel.State( - certificateList = listOf(DccReissuanceConsentCard.Item(metadata)), + certificateList = listOf(DccReissuanceCertificateCard.Item(metadata)), divisionVisible = true, listItemsTitle = "", title = "Zertifikat ersetzen", diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccert/DccReissuanceAccCertsViewModelTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccert/DccReissuanceAccCertsViewModelTest.kt index c6bea16b04e..be2097dd3fa 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccert/DccReissuanceAccCertsViewModelTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/dccreissuance/ui/consent/acccert/DccReissuanceAccCertsViewModelTest.kt @@ -10,7 +10,7 @@ import de.rki.coronawarnapp.covidcertificate.common.qrcode.DccQrCode import de.rki.coronawarnapp.covidcertificate.person.core.PersonCertificates import de.rki.coronawarnapp.covidcertificate.person.core.PersonCertificatesProvider import de.rki.coronawarnapp.covidcertificate.vaccination.core.VaccinationCertificate -import de.rki.coronawarnapp.dccreissuance.ui.consent.DccReissuanceConsentCard +import de.rki.coronawarnapp.dccreissuance.ui.consent.DccReissuanceCertificateCard import de.rki.coronawarnapp.dccreissuance.ui.consent.acccerts.DccReissuanceAccCertsViewModel import io.kotest.matchers.shouldBe import io.mockk.MockKAnnotations @@ -71,7 +71,7 @@ internal class DccReissuanceAccCertsViewModelTest : BaseTest() { @Test fun `getState works`() { viewModel().certificatesLiveData.getOrAwaitValue() shouldBe listOf( - DccReissuanceConsentCard.Item(metadata) + DccReissuanceCertificateCard.Item(metadata) ) }