diff --git a/app/src/main/java/com/kickstarter/ui/fragments/projectpage/ui/RisksScreen.kt b/app/src/main/java/com/kickstarter/ui/fragments/projectpage/ui/RisksScreen.kt index 8daf72d089..69246df66d 100644 --- a/app/src/main/java/com/kickstarter/ui/fragments/projectpage/ui/RisksScreen.kt +++ b/app/src/main/java/com/kickstarter/ui/fragments/projectpage/ui/RisksScreen.kt @@ -19,6 +19,7 @@ import androidx.compose.runtime.State import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString @@ -65,6 +66,7 @@ fun RisksScreen( bottom = dimensionResource(id = R.dimen.grid_4) ) .padding(horizontal = dimensionResource(id = R.dimen.grid_3)) + .testTag(RisksScreenTestTag.PAGE_TITLE.name) ) Text( text = riskDescState.value, @@ -75,6 +77,7 @@ fun RisksScreen( top = dimensionResource(id = R.dimen.grid_3) ) .padding(horizontal = dimensionResource(id = R.dimen.grid_3)) + .testTag(RisksScreenTestTag.RISK_DESCRIPTION.name) ) Spacer( modifier = Modifier @@ -105,10 +108,17 @@ fun RisksScreen( bottom = dimensionResource(id = R.dimen.grid_5) ) .padding(horizontal = dimensionResource(id = R.dimen.grid_3)) + .testTag(RisksScreenTestTag.CLICKABLE_TEXT.name) ) } } +enum class RisksScreenTestTag { + PAGE_TITLE, + RISK_DESCRIPTION, + CLICKABLE_TEXT +} + @Composable @Preview(showBackground = true, backgroundColor = 0xFFF0EAE2, name = "Light", uiMode = Configuration.UI_MODE_NIGHT_NO) @Preview(showBackground = true, backgroundColor = 0X00000000, name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES) diff --git a/app/src/test/java/com/kickstarter/ui/activities/compose/RisksScreenTest.kt b/app/src/test/java/com/kickstarter/ui/activities/compose/RisksScreenTest.kt new file mode 100644 index 0000000000..a43e3544e1 --- /dev/null +++ b/app/src/test/java/com/kickstarter/ui/activities/compose/RisksScreenTest.kt @@ -0,0 +1,70 @@ +package com.kickstarter.ui.activities.compose + +import androidx.compose.runtime.mutableStateOf +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsEnabled +import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performClick +import androidx.test.platform.app.InstrumentationRegistry +import com.kickstarter.KSRobolectricTestCase +import com.kickstarter.R +import com.kickstarter.ui.compose.designsystem.KSTheme +import com.kickstarter.ui.fragments.projectpage.ui.RisksScreen +import com.kickstarter.ui.fragments.projectpage.ui.RisksScreenTestTag +import org.junit.Test + +class RisksScreenTest : KSRobolectricTestCase() { + + val context = InstrumentationRegistry.getInstrumentation().targetContext + + private val pageTitle = composeTestRule.onNodeWithTag(RisksScreenTestTag.PAGE_TITLE.name) + private val riskDescriptionTextView = composeTestRule.onNodeWithTag(RisksScreenTestTag.RISK_DESCRIPTION.name) + private val clickableTextView = composeTestRule.onNodeWithTag(RisksScreenTestTag.CLICKABLE_TEXT.name) + + @Test + fun `test screen init`() { + val pageTitleText = context.getString(R.string.Risks_and_challenges) + val riskDescriptionText = context.getString(R.string.risk_description) + val clickableText = context.getString(R.string.Learn_about_accountability_on_Kickstarter) + val riskDescription = mutableStateOf(riskDescriptionText) + + composeTestRule.setContent { + KSTheme { + RisksScreen( + riskDescState = riskDescription, + callback = { } + ) + } + } + + pageTitle.assertIsDisplayed() + pageTitle.assertTextEquals(pageTitleText) + riskDescriptionTextView.assertIsDisplayed() + riskDescriptionTextView.assertTextEquals(riskDescriptionText) + clickableTextView.assertIsDisplayed() + clickableTextView.assertIsEnabled() + clickableTextView.assertTextEquals(clickableText) + } + + @Test + fun `test clickable text action`() { + var clickableTextClicks = 0 + val riskDescriptionText = context.getString(R.string.risk_description) + val riskDescription = mutableStateOf(riskDescriptionText) + + composeTestRule.setContent { + KSTheme { + RisksScreen( + riskDescState = riskDescription, + callback = { clickableTextClicks++ } + ) + } + } + + clickableTextView.assertIsDisplayed() + clickableTextView.assertIsEnabled() + clickableTextView.performClick() + assertEquals(1, clickableTextClicks) + } +}