Skip to content

Commit

Permalink
Improve UI code coverage (#52)
Browse files Browse the repository at this point in the history
* exclude stateful composables from coverage

* add append error test scenario
  • Loading branch information
lucasmodesto committed Jun 19, 2024
1 parent 39ce65f commit 4e1dae6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package br.com.cattose.app.core.ui.util

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class ExcludeFromJacocoGeneratedReport
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ import br.com.cattose.app.core.ui.R
import br.com.cattose.app.core.ui.error.TryAgain
import br.com.cattose.app.core.ui.image.DefaultAsyncImage
import br.com.cattose.app.core.ui.tags.TagList
import br.com.cattose.app.core.ui.util.ExcludeFromJacocoGeneratedReport
import br.com.cattose.app.core.ui.util.halfScreenWidthDp
import br.com.cattose.app.data.model.domain.Breed


@ExcludeFromJacocoGeneratedReport
@Composable
fun SharedTransitionScope.DetailScreen(
onBackClick: () -> Unit,
Expand All @@ -80,7 +82,6 @@ fun SharedTransitionScope.DetailScreen(
)
}


@Composable
fun SharedTransitionScope.DetailsScreenContent(
state: DetailState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class ListScreenTest {
fun successState() {
val pagingDataFlow = flowOf(
PagingData.from(
data = cats, sourceLoadStates = LoadStates(
data = cats,
sourceLoadStates = LoadStates(
refresh = LoadState.NotLoading(false),
prepend = LoadState.NotLoading(false),
append = LoadState.NotLoading(false)
Expand Down Expand Up @@ -91,7 +92,8 @@ class ListScreenTest {
fun initialLoading() {
val pagingDataFlow = flowOf(
PagingData.from(
data = listOf<CatImage>(), sourceLoadStates = LoadStates(
data = listOf<CatImage>(),
sourceLoadStates = LoadStates(
refresh = LoadState.Loading,
prepend = LoadState.Loading,
append = LoadState.Loading
Expand All @@ -117,7 +119,8 @@ class ListScreenTest {
fun appendLoading() {
val pagingDataFlow = flowOf(
PagingData.from(
data = cats, sourceLoadStates = LoadStates(
data = cats,
sourceLoadStates = LoadStates(
refresh = LoadState.NotLoading(false),
prepend = LoadState.NotLoading(false),
append = LoadState.Loading
Expand All @@ -144,10 +147,11 @@ class ListScreenTest {
}

@Test
fun errorState() {
fun refreshErrorState() {
val pagingDataFlow = flowOf(
PagingData.from(
data = listOf<CatImage>(), sourceLoadStates = LoadStates(
data = listOf<CatImage>(),
sourceLoadStates = LoadStates(
refresh = LoadState.Error(Exception()),
prepend = LoadState.NotLoading(false),
append = LoadState.NotLoading(false)
Expand All @@ -174,11 +178,44 @@ class ListScreenTest {
}
}

@Test
fun appendErrorState() {
val pagingDataFlow = flowOf(
PagingData.from(
data = cats,
sourceLoadStates = LoadStates(
refresh = LoadState.NotLoading(false),
prepend = LoadState.NotLoading(false),
append = LoadState.Error(Exception())
)
)
)

composeTestRule.setContent {
val lazyPagingItems = pagingDataFlow.collectAsLazyPagingItems()
SharedTransitionPreviewTheme {
ListScreenContent(
lazyPagingItems = lazyPagingItems,
onItemClick = {},
animatedVisibilityScope = it
)
}
}
with(composeTestRule) {
onNodeWithTag(ERROR).assertIsNotDisplayed()
onNodeWithTag(APPEND_LOADING).assertIsNotDisplayed()
onNodeWithTag(INITIAL_LOADING).assertIsNotDisplayed()
onNodeWithTag(EMPTY_LIST).assertIsNotDisplayed()
onNodeWithTag(LAZY_GRID).onChildren().assertCountEquals(3)
}
}

@Test
fun emptyState() {
val pagingDataFlow = flowOf(
PagingData.from(
data = listOf<CatImage>(), sourceLoadStates = LoadStates(
data = listOf<CatImage>(),
sourceLoadStates = LoadStates(
refresh = LoadState.NotLoading(true),
prepend = LoadState.NotLoading(false),
append = LoadState.NotLoading(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import androidx.paging.compose.collectAsLazyPagingItems
import br.com.cattose.app.core.ui.error.TryAgain
import br.com.cattose.app.core.ui.image.DefaultAsyncImage
import br.com.cattose.app.core.ui.image.ImagePlaceholder
import br.com.cattose.app.core.ui.util.ExcludeFromJacocoGeneratedReport
import br.com.cattose.app.data.model.domain.CatImage
import br.com.cattose.app.feature.list.ListTestTags.APPEND_LOADING
import br.com.cattose.app.feature.list.ListTestTags.EMPTY_LIST
Expand All @@ -65,7 +66,7 @@ import br.com.cattose.app.feature.list.ListTestTags.INITIAL_LOADING
import br.com.cattose.app.feature.list.ListTestTags.LAZY_GRID
import coil.transform.RoundedCornersTransformation


@ExcludeFromJacocoGeneratedReport
@Composable
fun SharedTransitionScope.ListScreen(
onItemClick: (CatImage) -> Unit,
Expand All @@ -83,7 +84,6 @@ fun SharedTransitionScope.ListScreen(
)
}


@Composable
fun SharedTransitionScope.ListScreenContent(
lazyPagingItems: LazyPagingItems<CatImage>,
Expand Down

0 comments on commit 4e1dae6

Please sign in to comment.