This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
493 changed files
with
17,765 additions
and
18,941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,6 @@ android { | |
} | ||
|
||
buildFeatures { | ||
dataBinding true | ||
viewBinding true | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
...dTest/java/de/rki/coronawarnapp/presencetracing/attendee/checkins/CheckInsFragmentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package de.rki.coronawarnapp.presencetracing.attendee.checkins | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModelStore | ||
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.presencetracing.checkins.CheckIn | ||
import de.rki.coronawarnapp.ui.presencetracing.attendee.checkins.CheckInsFragment | ||
import de.rki.coronawarnapp.ui.presencetracing.attendee.checkins.CheckInsFragmentArgs | ||
import de.rki.coronawarnapp.ui.presencetracing.attendee.checkins.CheckInsViewModel | ||
import de.rki.coronawarnapp.ui.presencetracing.attendee.checkins.items.ActiveCheckInVH | ||
import de.rki.coronawarnapp.ui.presencetracing.attendee.checkins.items.PastCheckInVH | ||
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 CheckInsFragmentTest : BaseUITest() { | ||
|
||
@MockK private lateinit var viewModel: CheckInsViewModel | ||
private val fragmentArgs = CheckInsFragmentArgs().toBundle() | ||
|
||
private val navController = TestNavHostController( | ||
ApplicationProvider.getApplicationContext() | ||
).apply { | ||
UiThreadStatement.runOnUiThread { | ||
setViewModelStore(ViewModelStore()) | ||
setGraph(R.navigation.nav_graph) | ||
setCurrentDestination(R.id.checkInsFragment) | ||
} | ||
} | ||
|
||
@Before | ||
fun setup() { | ||
MockKAnnotations.init(this, relaxed = true) | ||
|
||
setupMockViewModel( | ||
object : CheckInsViewModel.Factory { | ||
override fun create( | ||
savedState: SavedStateHandle, | ||
deepLink: String?, | ||
cleanHistory: Boolean | ||
): CheckInsViewModel = viewModel | ||
} | ||
) | ||
} | ||
|
||
@After | ||
fun teardown() { | ||
clearAllViewModels() | ||
} | ||
|
||
@Test | ||
@Screenshot | ||
fun capture_active_checkins() { | ||
|
||
val checkIns = listOf( | ||
activeCheckInItem( | ||
checkInId = 1, | ||
checkInDescription = "Rock Konzert", | ||
checkInAddress = "Sponholzstraße 15, 12159 Berlin" | ||
), | ||
activeCheckInItem( | ||
checkInId = 2, | ||
checkInDescription = "Kunstausstellung", | ||
checkInAddress = "Albersweilerweg 18, 12349 Berlin" | ||
) | ||
) | ||
|
||
every { viewModel.checkins } returns MutableLiveData(checkIns) | ||
|
||
launchFragmentInContainer2<CheckInsFragment>( | ||
fragmentArgs = fragmentArgs, | ||
testNavHostController = navController | ||
) | ||
takeScreenshot<CheckInsFragment>("active") | ||
} | ||
|
||
@Test | ||
@Screenshot | ||
fun capture_past_checkins() { | ||
|
||
val checkIns = listOf( | ||
pastCheckInItem( | ||
checkInId = 1, | ||
checkInDescription = "Rock Konzert", | ||
checkInAddress = "Sponholzstraße 15, 12159 Berlin" | ||
), | ||
pastCheckInItem( | ||
checkInId = 2, | ||
checkInDescription = "Kunstausstellung", | ||
checkInAddress = "Albersweilerweg 18, 12349 Berlin" | ||
) | ||
) | ||
|
||
every { viewModel.checkins } returns MutableLiveData(checkIns) | ||
|
||
launchFragmentInContainer2<CheckInsFragment>( | ||
fragmentArgs = fragmentArgs, | ||
testNavHostController = navController | ||
) | ||
takeScreenshot<CheckInsFragment>("past") | ||
} | ||
|
||
@Test | ||
@Screenshot | ||
fun capture_empty_fragment() { | ||
|
||
every { viewModel.checkins } returns MutableLiveData(listOf()) | ||
|
||
launchFragmentInContainer2<CheckInsFragment>( | ||
fragmentArgs = fragmentArgs, | ||
testNavHostController = navController | ||
) | ||
takeScreenshot<CheckInsFragment>("empty") | ||
} | ||
|
||
private fun mockCheckIn( | ||
checkInId: Long, | ||
checkInDescription: String, | ||
checkInAddress: String | ||
) = mockk<CheckIn>().apply { | ||
every { id } returns checkInId | ||
every { description } returns checkInDescription | ||
every { address } returns checkInAddress | ||
every { checkInStart } returns Instant.parse("2021-01-01T12:30:00.000Z") | ||
every { checkInEnd } returns Instant.parse("2021-01-01T14:00:00.000Z") | ||
} | ||
|
||
private fun activeCheckInItem( | ||
checkInId: Long, | ||
checkInDescription: String, | ||
checkInAddress: String | ||
) = ActiveCheckInVH.Item( | ||
checkin = mockCheckIn( | ||
checkInId = checkInId, | ||
checkInDescription = checkInDescription, | ||
checkInAddress = checkInAddress | ||
), | ||
onCardClicked = { _, _ -> }, | ||
onRemoveItem = {}, | ||
onCheckout = {}, | ||
onSwipeItem = { _, _ -> }, | ||
) | ||
|
||
private fun pastCheckInItem( | ||
checkInId: Long, | ||
checkInDescription: String, | ||
checkInAddress: String | ||
) = PastCheckInVH.Item( | ||
checkin = mockCheckIn( | ||
checkInId = checkInId, | ||
checkInDescription = checkInDescription, | ||
checkInAddress = checkInAddress | ||
), | ||
onCardClicked = { _, _ -> }, | ||
onRemoveItem = {}, | ||
onSwipeItem = { _, _ -> }, | ||
) | ||
} | ||
|
||
@Module | ||
abstract class CheckInsFragmentTestModule { | ||
@ContributesAndroidInjector | ||
abstract fun checkInsFragmentTest(): CheckInsFragment | ||
} |
112 changes: 112 additions & 0 deletions
112
.../java/de/rki/coronawarnapp/presencetracing/attendee/confirm/ConfirmCheckInFragmentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package de.rki.coronawarnapp.presencetracing.attendee.confirm | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModelStore | ||
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.presencetracing.checkins.qrcode.TraceLocation | ||
import de.rki.coronawarnapp.qrcode.ui.QrcodeSharedViewModel | ||
import de.rki.coronawarnapp.server.protocols.internal.pt.TraceLocationOuterClass | ||
import de.rki.coronawarnapp.ui.presencetracing.attendee.confirm.ConfirmCheckInFragment | ||
import de.rki.coronawarnapp.ui.presencetracing.attendee.confirm.ConfirmCheckInFragmentArgs | ||
import de.rki.coronawarnapp.ui.presencetracing.attendee.confirm.ConfirmCheckInViewModel | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import okio.ByteString.Companion.decodeBase64 | ||
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.Duration | ||
import java.time.Instant | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ConfirmCheckInFragmentTest : BaseUITest() { | ||
|
||
@MockK private lateinit var viewModel: ConfirmCheckInViewModel | ||
|
||
private val locationId = "2c69dbc182f836431f010020414be8460ce5ba890d63c770c81ca8a63fa0a462" | ||
private val traceLocation = TraceLocation( | ||
id = 1, | ||
type = TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_TEMPORARY_OTHER, | ||
description = "My Birthday Party", | ||
address = "at my place", | ||
startDate = Instant.ofEpochSecond(2687955L), | ||
endDate = Instant.ofEpochSecond(2687991L), | ||
defaultCheckInLengthInMinutes = null, | ||
cryptographicSeed = "CRYPTOGRAPHIC_SEED".decodeBase64()!!, | ||
cnPublicKey = "PUB_KEY", | ||
version = TraceLocation.VERSION | ||
) | ||
|
||
private val fragmentArgs = ConfirmCheckInFragmentArgs( | ||
locationId = locationId | ||
).toBundle() | ||
|
||
private val navController = TestNavHostController( | ||
ApplicationProvider.getApplicationContext() | ||
).apply { | ||
UiThreadStatement.runOnUiThread { | ||
setViewModelStore(ViewModelStore()) | ||
setGraph(R.navigation.nav_graph) | ||
setCurrentDestination(R.id.confirmCheckInFragment) | ||
} | ||
} | ||
|
||
@Before | ||
fun setup() { | ||
MockKAnnotations.init(this, relaxed = true) | ||
|
||
every { viewModel.uiState } returns MutableLiveData( | ||
ConfirmCheckInViewModel.UiState( | ||
traceLocation = traceLocation, | ||
checkInEndOffset = Duration.ofDays(2L), | ||
createJournalEntry = false, | ||
eventInPastVisible = true, | ||
eventInFutureVisible = true, | ||
confirmButtonEnabled = true | ||
) | ||
) | ||
|
||
setupMockViewModel( | ||
object : ConfirmCheckInViewModel.Factory { | ||
override fun create( | ||
verifiedTraceLocationId: String, | ||
qrcodeSharedViewModel: QrcodeSharedViewModel | ||
): ConfirmCheckInViewModel = viewModel | ||
} | ||
) | ||
} | ||
|
||
@After | ||
fun teardown() { | ||
clearAllViewModels() | ||
} | ||
|
||
@Test | ||
@Screenshot | ||
fun capture_fragment() { | ||
|
||
launchFragmentInContainer2<ConfirmCheckInFragment>( | ||
fragmentArgs = fragmentArgs, | ||
testNavHostController = navController | ||
) | ||
takeScreenshot<ConfirmCheckInFragment>() | ||
} | ||
} | ||
|
||
@Module | ||
abstract class ConfirmCheckInFragmentModule { | ||
@ContributesAndroidInjector | ||
abstract fun confirmCheckInFragmentTest(): ConfirmCheckInFragment | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.