Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/2.5.x' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rken committed Jul 15, 2021
2 parents c87daaa + 2943eff commit 63df24b
Show file tree
Hide file tree
Showing 484 changed files with 17,126 additions and 11,707 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ jobs:
curl --location --request POST $tsystems_upload_url \
--header "Authorization: Bearer $tsystems_upload_bearer" \
--form "file=@${fileName}" \
--form "camera=true"
instrumentation_tests_device:
resource_class: xlarge
Expand Down
12 changes: 10 additions & 2 deletions Corona-Warn-App/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ android {
exclude 'CODE_OF_CONDUCT.md'
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'
// https://github.com/Kotlin/kotlinx.coroutines/issues/2274
exclude 'DebugProbesKt.bin'
}

sourceSets {
Expand Down Expand Up @@ -322,6 +324,11 @@ dependencies {
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.work:work-runtime-ktx:2.5.0'

def activity_version = "1.2.3"
implementation "androidx.activity:activity-ktx:$activity_version"
def fragment_version = "1.3.5"
implementation "androidx.fragment:fragment-ktx:$fragment_version"

implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
Expand Down Expand Up @@ -362,7 +369,8 @@ dependencies {
testImplementation 'org.hamcrest:hamcrest-library:2.2'

// Testing - jUnit4
testImplementation 'junit:junit:4.13.1'
def junit_version = "4.13.1"
testImplementation "junit:junit:$junit_version"
testImplementation "org.junit.vintage:junit-vintage-engine:5.7.0"
testImplementation "androidx.test:core-ktx:1.3.0"

Expand All @@ -383,7 +391,7 @@ dependencies {
testImplementation "io.github.classgraph:classgraph:4.8.90"

// Testing - Instrumentation
androidTestImplementation 'junit:junit:4.13.1'
androidTestImplementation "junit:junit:$junit_version"
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
package de.rki.coronawarnapp.covidcertificate.person.ui.details

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
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.covidcertificate.common.certificate.CertificatePersonIdentifier
import de.rki.coronawarnapp.covidcertificate.common.certificate.DccV1
import de.rki.coronawarnapp.covidcertificate.common.certificate.TestDccV1
import de.rki.coronawarnapp.covidcertificate.common.certificate.VaccinationDccV1
import de.rki.coronawarnapp.covidcertificate.common.repository.CertificateContainerId
import de.rki.coronawarnapp.covidcertificate.common.repository.RecoveryCertificateContainerId
import de.rki.coronawarnapp.covidcertificate.common.repository.TestCertificateContainerId
import de.rki.coronawarnapp.covidcertificate.common.repository.VaccinationCertificateContainerId
import de.rki.coronawarnapp.covidcertificate.person.core.PersonCertificates
import de.rki.coronawarnapp.covidcertificate.person.ui.details.items.CertificateItem
import de.rki.coronawarnapp.covidcertificate.person.ui.details.items.CwaUserCard
import de.rki.coronawarnapp.covidcertificate.person.ui.details.items.PersonDetailsQrCard
import de.rki.coronawarnapp.covidcertificate.person.ui.details.items.RecoveryCertificateCard
import de.rki.coronawarnapp.covidcertificate.person.ui.details.items.TestCertificateCard
import de.rki.coronawarnapp.covidcertificate.person.ui.details.items.VaccinationCertificateCard
import de.rki.coronawarnapp.covidcertificate.person.ui.overview.PersonColorShade
import de.rki.coronawarnapp.covidcertificate.recovery.core.RecoveryCertificate
import de.rki.coronawarnapp.covidcertificate.test.core.TestCertificate
import de.rki.coronawarnapp.covidcertificate.vaccination.core.VaccinatedPerson
import de.rki.coronawarnapp.covidcertificate.vaccination.core.VaccinationCertificate
import de.rki.coronawarnapp.util.TimeAndDateExtensions.toLocalDateUserTz
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.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.launchFragment2
import testhelpers.launchFragmentInContainer2
import testhelpers.takeScreenshot

@RunWith(AndroidJUnit4::class)
class PersonDetailsFragmentTest : BaseUITest() {
@MockK lateinit var viewModel: PersonDetailsViewModel
private lateinit var bitmap: Bitmap
private val args = PersonDetailsFragmentArgs("code").toBundle()
private val vcContainerId = VaccinationCertificateContainerId("1")
private val tcsContainerId = TestCertificateContainerId("2")
private val rcContainerId = RecoveryCertificateContainerId("3")

@Before
fun setUp() {
MockKAnnotations.init(this, relaxed = true)
viewModel.apply {
every { events } returns SingleLiveEvent()
every { uiState } returns MutableLiveData()
}

bitmap = BitmapFactory.decodeResource(
ApplicationProvider.getApplicationContext<Context>().resources,
R.drawable.test_qr_code
)
setupMockViewModel(
object : PersonDetailsViewModel.Factory {
override fun create(
personIdentifierCode: String,
colorShade: PersonColorShade,
containerId: CertificateContainerId?,
savedInstance: SavedStateHandle
): PersonDetailsViewModel = viewModel
}
)
}

@Test
fun launch_fragment() {
launchFragment2<PersonDetailsFragment>(fragmentArgs = args)
}

@Test
@Screenshot
fun capture_fragment_cwa_user() {
every { viewModel.uiState } returns certificateData(true)

launchFragmentInContainer2<PersonDetailsFragment>(fragmentArgs = args)
takeScreenshot<PersonDetailsFragment>("cwa")

onView(withId(R.id.coordinator_layout)).perform(swipeUp())
takeScreenshot<PersonDetailsFragment>("cwa_2")
}

@Test
@Screenshot
fun capture_fragment_not_cwa_user() {
every { viewModel.uiState } returns certificateData()
launchFragmentInContainer2<PersonDetailsFragment>(fragmentArgs = args)
takeScreenshot<PersonDetailsFragment>("not_cwa")
}

private fun certificateData(isCwa: Boolean = false): LiveData<List<CertificateItem>> = MutableLiveData(
mutableListOf<CertificateItem>().apply {
val testCertificate = mockTestCertificate()
val vaccinationCertificate1 = mockVaccinationCertificate(number = 1, final = false)
val vaccinationCertificate2 = mockVaccinationCertificate(number = 2, final = true)
val recoveryCertificate = mockRecoveryCertificate()
val personCertificates = PersonCertificates(
listOf(testCertificate, vaccinationCertificate1, vaccinationCertificate2), isCwaUser = isCwa
)

add(PersonDetailsQrCard.Item(testCertificate, bitmap))
add(CwaUserCard.Item(personCertificates) {})
add(
VaccinationCertificateCard.Item(
vaccinationCertificate1,
isCurrentCertificate = false,
VaccinatedPerson.Status.COMPLETE,
PersonColorShade.COLOR_1
) {}
)
add(
VaccinationCertificateCard.Item(
vaccinationCertificate2,
isCurrentCertificate = false,
VaccinatedPerson.Status.COMPLETE,
PersonColorShade.COLOR_1
) {}
)
add(TestCertificateCard.Item(testCertificate, isCurrentCertificate = true, PersonColorShade.COLOR_1) {})
add(
RecoveryCertificateCard.Item(
recoveryCertificate,
isCurrentCertificate = false,
PersonColorShade.COLOR_1
) {}
)
}
)

private fun mockTestCertificate(): TestCertificate = mockk<TestCertificate>().apply {
every { certificateId } returns "testCertificateId"
every { fullName } returns "Andrea Schneider"
every { rawCertificate } returns mockk<TestDccV1>().apply {
every { test } returns mockk<DccV1.TestCertificateData>().apply {
every { testType } returns "LP6464-4"
every { sampleCollectedAt } returns Instant.parse("2021-05-31T11:35:00.000Z")
}
}
every { containerId } returns tcsContainerId
every { testType } returns "PCR-Test"
every { dateOfBirthFormatted } returns "1943-04-18"
every { sampleCollectedAt } returns Instant.parse("2021-05-31T11:35:00.000Z")
every { registeredAt } returns Instant.parse("2021-05-21T11:35:00.000Z")
every { personIdentifier } returns certificatePersonIdentifier
every { qrCode } returns "qrCode"
every { personIdentifier } returns CertificatePersonIdentifier(
firstNameStandardized = "firstNameStandardized",
lastNameStandardized = "lastNameStandardized",
dateOfBirthFormatted = "1943-04-18"
)
}

private fun mockVaccinationCertificate(number: Int = 1, final: Boolean = false): VaccinationCertificate =
mockk<VaccinationCertificate>().apply {
val localDate = Instant.parse("2021-06-01T11:35:00.000Z").toLocalDateUserTz()
every { fullName } returns "Andrea Schneider"
every { certificateId } returns "vaccinationCertificateId$number"
every { rawCertificate } returns mockk<VaccinationDccV1>().apply {
every { vaccination } returns mockk<DccV1.VaccinationData>().apply {
every { doseNumber } returns number
every { totalSeriesOfDoses } returns 2
every { vaccinatedOn } returns localDate
}
}
every { containerId } returns vcContainerId
every { vaccinatedOn } returns localDate
every { personIdentifier } returns certificatePersonIdentifier
every { vaccinatedOn } returns Instant.parse("2021-06-01T11:35:00.000Z").toLocalDateUserTz()
every { personIdentifier } returns CertificatePersonIdentifier(
firstNameStandardized = "firstNameStandardized",
lastNameStandardized = "lastNameStandardized",
dateOfBirthFormatted = "1943-04-18"
)
every { doseNumber } returns number
every { totalSeriesOfDoses } returns 2
every { dateOfBirthFormatted } returns "1981-03-20"
every { isFinalShot } returns final
every { qrCode } returns "qrCode"
}

private fun mockRecoveryCertificate(): RecoveryCertificate =
mockk<RecoveryCertificate>().apply {
every { fullName } returns "Andrea Schneider"
every { certificateId } returns "recoveryCertificateId"
every { dateOfBirthFormatted } returns "1981-03-20"
every { validUntil } returns Instant.parse("2021-05-31T11:35:00.000Z").toLocalDateUserTz()
every { personIdentifier } returns certificatePersonIdentifier
every { qrCode } returns "qrCode"
every { containerId } returns rcContainerId
}

private val certificatePersonIdentifier = CertificatePersonIdentifier(
dateOfBirthFormatted = "1981-03-20",
firstNameStandardized = "firstNameStandardized",
lastNameStandardized = "lastNameStandardized",
)

@After
fun tearDown() {
clearAllViewModels()
}
}

@Module
abstract class PersonDetailsFragmentTestModule {
@ContributesAndroidInjector
abstract fun personDetailsFragment(): PersonDetailsFragment
}
Loading

0 comments on commit 63df24b

Please sign in to comment.