compose test updates

This commit is contained in:
John O'Reilly 2021-07-10 21:51:44 +01:00
parent 93a7e73ea8
commit f37b9a783d
3 changed files with 36 additions and 10 deletions

View file

@ -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<List<Assignment>> {
return flowOf(peopleList)
}
override fun pollISSPosition(): Flow<IssPosition> {
return emptyFlow()
return flowOf(issPosition)
}
}

View file

@ -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()
}
}

View file

@ -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>("IssPosition")
var SemanticsPropertyReceiver.observedIssPosition by IssPositionKey
@Composable
fun ISSPositionScreen() {
val peopleInSpaceViewModel = getViewModel<PeopleInSpaceViewModel>()
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)