From f37b9a783df4a7c6aa54e35859d830d9cef93f05 Mon Sep 17 00:00:00 2001 From: John O'Reilly Date: Sat, 10 Jul 2021 21:51:44 +0100 Subject: [PATCH] compose test updates --- .../PeopleInSpaceRepositoryFake.kt | 5 ++-- .../surrus/peopleinspace/PeopleInSpaceTest.kt | 23 +++++++++++++++---- .../peopleinspace/ui/ISSPositionScreen.kt | 18 ++++++++++++--- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/src/androidTest/java/com/surrus/peopleinspace/PeopleInSpaceRepositoryFake.kt b/app/src/androidTest/java/com/surrus/peopleinspace/PeopleInSpaceRepositoryFake.kt index 045a523..5097af8 100644 --- a/app/src/androidTest/java/com/surrus/peopleinspace/PeopleInSpaceRepositoryFake.kt +++ b/app/src/androidTest/java/com/surrus/peopleinspace/PeopleInSpaceRepositoryFake.kt @@ -4,18 +4,19 @@ import com.surrus.common.remote.Assignment import com.surrus.common.remote.IssPosition import com.surrus.common.repository.PeopleInSpaceRepositoryInterface import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.flowOf class PeopleInSpaceRepositoryFake: PeopleInSpaceRepositoryInterface { val peopleList = listOf(Assignment("Apollo 11", "Neil Armstrong"), Assignment("Apollo 11", "Buzz Aldrin")) + val issPosition = IssPosition(53.2743394, -9.0514163) + override fun fetchPeopleAsFlow(): Flow> { return flowOf(peopleList) } override fun pollISSPosition(): Flow { - return emptyFlow() + return flowOf(issPosition) } } diff --git a/app/src/androidTest/java/com/surrus/peopleinspace/PeopleInSpaceTest.kt b/app/src/androidTest/java/com/surrus/peopleinspace/PeopleInSpaceTest.kt index 4e6bb6e..e504c50 100644 --- a/app/src/androidTest/java/com/surrus/peopleinspace/PeopleInSpaceTest.kt +++ b/app/src/androidTest/java/com/surrus/peopleinspace/PeopleInSpaceTest.kt @@ -1,11 +1,9 @@ package com.surrus.peopleinspace -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.ui.test.* import androidx.compose.ui.test.junit4.createComposeRule -import com.surrus.peopleinspace.ui.PeopleInSpaceViewModel -import com.surrus.peopleinspace.ui.PersonListScreen -import com.surrus.peopleinspace.ui.PersonListTag +import com.surrus.common.remote.IssPosition +import com.surrus.peopleinspace.ui.* import org.junit.Rule import org.junit.Test @@ -17,7 +15,7 @@ class PeopleInSpaceTest { private val peopleInSpaceViewModel = PeopleInSpaceViewModel(peopleInSpaceRepository) @Test - fun testGetPeople() { + fun testPeopleListScreen() { composeTestRule.setContent { PersonListScreen(personSelected = {}, peopleInSpaceViewModel = peopleInSpaceViewModel @@ -35,4 +33,19 @@ class PeopleInSpaceTest { rowNode.assertTextContains(person.craft) } } + + @Test + fun testISSPositionScreen() { + composeTestRule.setContent { + ISSPositionScreen(peopleInSpaceViewModel = peopleInSpaceViewModel) + } + + composeTestRule.onNodeWithTag(ISSPositionMapTag).assertIsDisplayed() + + val expectedIssPosition = peopleInSpaceRepository.issPosition + composeTestRule + .onNode(SemanticsMatcher.expectValue(IssPositionKey, expectedIssPosition)) + .assertExists() + } + } diff --git a/app/src/main/java/com/surrus/peopleinspace/ui/ISSPositionScreen.kt b/app/src/main/java/com/surrus/peopleinspace/ui/ISSPositionScreen.kt index cccdd06..4410dda 100644 --- a/app/src/main/java/com/surrus/peopleinspace/ui/ISSPositionScreen.kt +++ b/app/src/main/java/com/surrus/peopleinspace/ui/ISSPositionScreen.kt @@ -12,6 +12,10 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.semantics.SemanticsPropertyKey +import androidx.compose.ui.semantics.SemanticsPropertyReceiver +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.viewinterop.AndroidView import com.surrus.common.remote.IssPosition import com.surrus.peopleinspace.util.collectAsStateWithLifecycle @@ -21,9 +25,14 @@ import org.osmdroid.views.CustomZoomButtonsController import org.osmdroid.views.MapView import org.osmdroid.views.overlay.Marker + +const val ISSPositionMapTag = "ISSPositionMap" + +val IssPositionKey = SemanticsPropertyKey("IssPosition") +var SemanticsPropertyReceiver.observedIssPosition by IssPositionKey + @Composable -fun ISSPositionScreen() { - val peopleInSpaceViewModel = getViewModel() +fun ISSPositionScreen(peopleInSpaceViewModel: PeopleInSpaceViewModel = getViewModel()) { val lifecycleOwner = LocalLifecycleOwner.current @@ -41,7 +50,10 @@ fun ISSPositionScreen() { Column { Box { - AndroidView({ map }, modifier = Modifier.fillMaxHeight()) { map -> + AndroidView({ map }, modifier = Modifier + .fillMaxHeight().testTag(ISSPositionMapTag) + .semantics { observedIssPosition = issPosition } + ){ map -> map.zoomController.setVisibility(CustomZoomButtonsController.Visibility.SHOW_AND_FADEOUT) map.setMultiTouchControls(true)