compose test updates
This commit is contained in:
parent
9e5069e85c
commit
89bbba0ed2
3 changed files with 20 additions and 8 deletions
|
@ -8,8 +8,10 @@ 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"))
|
||||
|
||||
override fun fetchPeopleAsFlow(): Flow<List<Assignment>> {
|
||||
val peopleList = listOf(Assignment("ISS", "Megan McArthur"))
|
||||
return flowOf(peopleList)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.surrus.peopleinspace
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.*
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import com.surrus.peopleinspace.ui.PeopleInSpaceViewModel
|
||||
import com.surrus.peopleinspace.ui.PersonListScreen
|
||||
import com.surrus.peopleinspace.ui.PersonListTag
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
|
@ -26,9 +26,16 @@ class PeopleInSpaceTest {
|
|||
peopleInSpaceViewModel = peopleInSpaceViewModel
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Megan McArthur")
|
||||
.assertIsDisplayed()
|
||||
|
||||
val peopleList = peopleInSpaceRepository.peopleList
|
||||
|
||||
composeTestRule.onNodeWithTag(PersonListTag).assertIsDisplayed()
|
||||
composeTestRule.onNodeWithTag(PersonListTag).onChildren().assertCountEquals(peopleList.size)
|
||||
|
||||
peopleList.forEach { person ->
|
||||
composeTestRule
|
||||
.onNodeWithText(person.name)
|
||||
.assertExists()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.compose.runtime.collectAsState
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
@ -20,6 +21,8 @@ import com.google.accompanist.coil.rememberCoilPainter
|
|||
import com.surrus.common.remote.Assignment
|
||||
import org.koin.androidx.compose.getViewModel
|
||||
|
||||
const val PersonListTag = "PersonList"
|
||||
|
||||
@Composable
|
||||
fun PersonListScreen(paddingValues: PaddingValues,
|
||||
personSelected: (person: Assignment) -> Unit,
|
||||
|
@ -32,7 +35,7 @@ fun PersonListScreen(paddingValues: PaddingValues,
|
|||
TopAppBar(title = { Text("People In Space") })
|
||||
}
|
||||
) {
|
||||
LazyColumn(contentPadding = paddingValues) {
|
||||
LazyColumn(contentPadding = paddingValues, modifier = Modifier.testTag(PersonListTag)) {
|
||||
items(peopleState.value) { person ->
|
||||
PersonView(person, personSelected)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue