Skip to content

Commit

Permalink
test: add jetpack screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Divinelink committed Nov 10, 2024
1 parent 1468832 commit cb3c270
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 92 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,11 @@ web/js/*

node_modules
/app/google-services.json.base64

# Compose Destinations Generated Graph
RootNavGraph.html
RootNavGraph.mmd

# Screenshots
*Preview*.png
*Screenshot*.png
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.andreolas.movierama.ExcludeFromKoverReport
import com.andreolas.movierama.R
import com.divinelink.core.commons.ExcludeFromKoverReport
import com.divinelink.core.designsystem.theme.AppTheme
import com.divinelink.core.designsystem.theme.dimensions
import com.divinelink.core.designsystem.theme.textColorDisabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AndroidApplicationComposeConventionPlugin : Plugin<Project> {
apply("com.android.application")
apply("org.jetbrains.kotlinx.kover")
apply("org.jetbrains.kotlin.plugin.compose")
apply("com.android.compose.screenshot")
}

val extension = extensions.getByType<ApplicationExtension>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
apply("com.android.library")
apply("org.jetbrains.kotlinx.kover")
apply("org.jetbrains.kotlin.plugin.compose")
apply("com.android.compose.screenshot")
}

val extension = extensions.getByType<LibraryExtension>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ internal fun Project.configureAndroidCompose(commonExtension: CommonExtension<*,
add("implementation", libs.findLibrary("compose-shimmer").get())
}

testOptions {
unitTests {
// For Robolectric
isIncludeAndroidResources = true
}
}
testOptions.unitTests.isIncludeAndroidResources = true
experimentalProperties["android.experimental.enableScreenshotTest"] = true
}

extensions.configure<ComposeCompilerGradlePluginExtension> {
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ plugins {
alias(libs.plugins.sqldelight) apply false
alias(libs.plugins.gms) apply false
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.screenshot) apply false
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.andreolas.movierama
package com.divinelink.core.commons

/**
* Any time we have a function that we want excluded from our JaCoCo coverage report, we can add this
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
package com.divinelink.feature.credits.provider

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.divinelink.core.commons.ExcludeFromKoverReport
import com.divinelink.core.model.credits.PersonRole
import com.divinelink.core.model.credits.SeriesCrewDepartment
import com.divinelink.core.model.details.Person
import com.divinelink.feature.credits.ui.CreditsTab
import com.divinelink.feature.credits.ui.CreditsUiContent
import com.divinelink.feature.credits.ui.CreditsUiState

class CreditsUiStateParameterProvider : PreviewParameterProvider<CreditsUiState> {
override val values: Sequence<CreditsUiState> = sequenceOf(
CreditsUiState(
selectedTabIndex = 0,
tabs = listOf(
CreditsTab.Cast(2),
CreditsTab.Crew(4),
),
forms = mapOf(
CreditsTab.Cast(2) to CreditsUiContent.Cast(
cast = listOf(
CreditsUiStateParameters.actor1,
CreditsUiStateParameters.actor2,
CreditsUiStateParameters.actor3,
),
),
CreditsTab.Crew(4) to CreditsUiContent.Crew(
crew = listOf(
SeriesCrewDepartment(
department = "Department 1",
crewList = listOf(
CreditsUiStateParameters.crew1,
CreditsUiStateParameters.crew2,
CreditsUiStateParameters.crew3,
),
),
SeriesCrewDepartment(
department = "Department 2",
crewList = listOf(
CreditsUiStateParameters.crew1,
),
),
),
),
),
),
CreditsUiState(
selectedTabIndex = 1,
tabs = listOf(
CreditsTab.Cast(2),
CreditsTab.Crew(4),
),
forms = mapOf(
CreditsTab.Cast(2) to CreditsUiContent.Cast(
cast = listOf(
CreditsUiStateParameters.actor1,
CreditsUiStateParameters.actor2,
CreditsUiStateParameters.actor3,
),
),
CreditsTab.Crew(4) to CreditsUiContent.Crew(
crew = listOf(
SeriesCrewDepartment(
department = "Department 1",
crewList = listOf(
CreditsUiStateParameters.crew1,
CreditsUiStateParameters.crew2,
),
),
SeriesCrewDepartment(
department = "Department 2",
crewList = listOf(
CreditsUiStateParameters.crew3,
CreditsUiStateParameters.crew4,
),
),
),
),
),
),
CreditsUiState(
selectedTabIndex = 0,
tabs = listOf(
CreditsTab.Cast(0),
CreditsTab.Crew(0),
),
forms = mapOf(
CreditsTab.Cast(0) to CreditsUiContent.Cast(
cast = listOf(),
),
CreditsTab.Crew(0) to CreditsUiContent.Crew(
crew = listOf(),
),
),
),
CreditsUiState(
selectedTabIndex = 1,
tabs = listOf(
CreditsTab.Cast(0),
CreditsTab.Crew(0),
),
forms = mapOf(
CreditsTab.Cast(0) to CreditsUiContent.Cast(
cast = listOf(),
),
CreditsTab.Crew(0) to CreditsUiContent.Crew(
crew = listOf(),
),
),
),
)
}

@ExcludeFromKoverReport
private object CreditsUiStateParameters {
val actor1 = Person(
id = 1,
name = "Person 1",
profilePath = "https://image.tmdb.org/t/p/w185/1.jpg",
knownForDepartment = "Acting",
role = listOf(
PersonRole.SeriesActor(
character = "Character 1",
),
PersonRole.SeriesActor(
character = "Character 2",
),
),
)

val actor2 = Person(
id = 2,
name = "Person 2",
profilePath = "https://image.tmdb.org/t/p/w185/2.jpg",
knownForDepartment = "Acting",
role = listOf(
PersonRole.SeriesActor(
character = "",
totalEpisodes = 10,
),
),
)

val actor3 = Person(
id = 3,
name = "Person 3",
profilePath = "https://image.tmdb.org/t/p/w185/1.jpg",
knownForDepartment = "Acting",
role = (1..5).map {
PersonRole.SeriesActor(
character = "Character $it",
totalEpisodes = it,
)
},
)

val crew1 = Person(
id = 1,
name = "Crew 1",
profilePath = "https://image.tmdb.org/t/p/w185/3.jpg",
knownForDepartment = "Directing",
role = listOf(
PersonRole.Crew(
job = "Job 1",
creditId = "Credit 1",
totalEpisodes = 2,
),
),
)

val crew2 = Person(
id = 2,
name = "Crew 2",
profilePath = "https://image.tmdb.org/t/p/w185/4.jpg",
knownForDepartment = "Directing",
role = listOf(
PersonRole.Crew(
job = "Job 2",
creditId = "Credit 2",
),
),
)

val crew3 = Person(
id = 1,
name = "Crew 3",
profilePath = "https://image.tmdb.org/t/p/w185/5.jpg",
knownForDepartment = "Directing",
role = (4..8).map {
PersonRole.Crew(
job = "Job $it",
creditId = "Credit $it",
totalEpisodes = it.toLong(),
)
},
)

val crew4 = Person(
id = 10,
name = "Crew 2",
profilePath = "https://image.tmdb.org/t/p/w185/4.jpg",
knownForDepartment = "Directing",
role = listOf(
PersonRole.Crew(
job = "",
creditId = "Credit 10",
totalEpisodes = 5,
),
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.divinelink.core.designsystem.theme.AppTheme
import com.divinelink.core.designsystem.theme.dimensions
import com.divinelink.core.model.credits.PersonRole
import com.divinelink.core.model.credits.SeriesCrewDepartment
import com.divinelink.core.model.details.Person
import com.divinelink.core.ui.Previews
import com.divinelink.core.ui.TestTags
import com.divinelink.core.ui.blankslate.BlankSlate
import com.divinelink.core.ui.blankslate.BlankSlateState
import com.divinelink.feature.credits.provider.CreditsUiStateParameterProvider
import kotlinx.coroutines.launch

@Composable
Expand All @@ -41,7 +42,7 @@ fun CreditsContent(
onTabSelected: (Int) -> Unit,
onPersonSelected: (Person) -> Unit,
) {
var selectedPage by rememberSaveable { mutableIntStateOf(0) }
var selectedPage by rememberSaveable { mutableIntStateOf(state.selectedTabIndex) }
val scope = rememberCoroutineScope()
val pagerState = rememberPagerState(
initialPage = selectedPage,
Expand Down Expand Up @@ -139,82 +140,13 @@ fun CreditsContent(

@Previews
@Composable
private fun CreditsContentPreview() {
fun CreditsContentPreview(
@PreviewParameter(CreditsUiStateParameterProvider::class) uiState: CreditsUiState,
) {
AppTheme {
Surface {
CreditsContent(
state = CreditsUiState(
selectedTabIndex = 0,
tabs = listOf(
CreditsTab.Cast(2),
CreditsTab.Crew(1),
),
forms = mapOf(
CreditsTab.Cast(2) to CreditsUiContent.Cast(
cast = listOf(
Person(
id = 1,
name = "Person 1",
profilePath = "https://image.tmdb.org/t/p/w185/1.jpg",
knownForDepartment = "Acting",
role = listOf(
PersonRole.SeriesActor(
character = "Character 1",
),
PersonRole.SeriesActor(
character = "Character 2",
),
),
),
Person(
id = 2,
name = "Person 2",
profilePath = "https://image.tmdb.org/t/p/w185/2.jpg",
knownForDepartment = "Acting",
role = listOf(
PersonRole.SeriesActor(
character = "Character 2",
totalEpisodes = 10,
),
),
),
),
),
CreditsTab.Crew(1) to CreditsUiContent.Crew(
crew = listOf(
SeriesCrewDepartment(
department = "Department 1",
crewList = listOf(
Person(
id = 3,
name = "Person 3",
profilePath = "https://image.tmdb.org/t/p/w185/3.jpg",
knownForDepartment = "Directing",
role = listOf(
PersonRole.Crew(
job = "Job 3",
creditId = "Credit 3",
),
),
),
Person(
id = 4,
name = "Person 4",
profilePath = "https://image.tmdb.org/t/p/w185/4.jpg",
knownForDepartment = "Directing",
role = listOf(
PersonRole.Crew(
job = "Job 4",
creditId = "Credit 4",
),
),
),
),
),
),
),
),
),
state = uiState,
onTabSelected = { },
onPersonSelected = { },
)
Expand Down
Loading

0 comments on commit cb3c270

Please sign in to comment.