diff --git a/library/src/test/java/com/telefonica/mistica/compose/list/ListRowItemWithCheckBoxTest.kt b/library/src/test/java/com/telefonica/mistica/compose/list/ListRowItemWithCheckBoxTest.kt new file mode 100644 index 000000000..5f1e24520 --- /dev/null +++ b/library/src/test/java/com/telefonica/mistica/compose/list/ListRowItemWithCheckBoxTest.kt @@ -0,0 +1,92 @@ +package com.telefonica.mistica.compose.list + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.test.assertIsOff +import androidx.compose.ui.test.assertIsOn +import androidx.compose.ui.test.isToggleable +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onRoot +import androidx.compose.ui.test.performClick +import com.telefonica.mistica.compose.tag.Tag +import com.telefonica.mistica.compose.theme.MisticaTheme +import com.telefonica.mistica.compose.theme.brand.MovistarBrand +import com.telefonica.mistica.testutils.ScreenshotsTest +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner + +@RunWith(RobolectricTestRunner::class) +internal class ListRowItemWithCheckBoxTest : ScreenshotsTest() { + + @get:Rule + val composeTestRule = createComposeRule() + + @Test + fun `check ListRowItemWithCheckBox Off`() { + `when ListRowItemWithCheckBox`(checked = false) + + `then is NOT checked`() + `then screenshot is OK`() + } + + @Test + fun `check ListRowItemWithCheckBox On`() { + `when ListRowItemWithCheckBox`(checked = true) + + `then is checked`() + `then screenshot is OK`() + } + + @Test + fun `check ListRowItemWithCheckBox state change`() { + `given ListRowItemWithCheckBox`(checked = false) + `given is NOT checked`() + + `when toggling the state`() + + `then is checked`() + } + + private fun `given ListRowItemWithCheckBox`(checked: Boolean = false) = + `when ListRowItemWithCheckBox`(checked) + + private fun `given is NOT checked`() = + `then is NOT checked`() + + private fun `when ListRowItemWithCheckBox`(checked: Boolean = false) { + composeTestRule.setContent { + var isChecked by remember { mutableStateOf(checked) } + MisticaTheme(brand = MovistarBrand) { + ListRowItemWithCheckBox( + listRowIcon = null, + headline = Tag("Promo"), + title = "title", + subtitle = "Subtitle", + description = "Description", + checked = isChecked, + onCheckedChange = { isChecked = it}, + ) + } + } + } + + private fun `when toggling the state`() { + composeTestRule.onNode(isToggleable()).performClick() + } + + private fun `then screenshot is OK`() { + compareScreenshot(composeTestRule.onRoot()) + } + + private fun `then is NOT checked`() { + composeTestRule.onNode(isToggleable()).assertIsOff() + } + + private fun `then is checked`() { + composeTestRule.onNode(isToggleable()).assertIsOn() + } +} diff --git a/library/src/test/java/com/telefonica/mistica/compose/list/ListRowItemWithSwitchTest.kt b/library/src/test/java/com/telefonica/mistica/compose/list/ListRowItemWithSwitchTest.kt new file mode 100644 index 000000000..3b4d52fed --- /dev/null +++ b/library/src/test/java/com/telefonica/mistica/compose/list/ListRowItemWithSwitchTest.kt @@ -0,0 +1,92 @@ +package com.telefonica.mistica.compose.list + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.test.assertIsOff +import androidx.compose.ui.test.assertIsOn +import androidx.compose.ui.test.isToggleable +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onRoot +import androidx.compose.ui.test.performClick +import com.telefonica.mistica.compose.tag.Tag +import com.telefonica.mistica.compose.theme.MisticaTheme +import com.telefonica.mistica.compose.theme.brand.MovistarBrand +import com.telefonica.mistica.testutils.ScreenshotsTest +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner + +@RunWith(RobolectricTestRunner::class) +internal class ListRowItemWithSwitchTest : ScreenshotsTest() { + + @get:Rule + val composeTestRule = createComposeRule() + + @Test + fun `check ListRowItemWithSwitch Off`() { + `when ListRowItemWithSwitch`(checked = false) + + `then is NOT checked`() + `then screenshot is OK`() + } + + @Test + fun `check ListRowItemWithSwitch On`() { + `when ListRowItemWithSwitch`(checked = true) + + `then is checked`() + `then screenshot is OK`() + } + + @Test + fun `check ListRowItemWithSwitch state change`() { + `given ListRowItemWithSwitch`(checked = false) + `given is NOT checked`() + + `when toggling the state`() + + `then is checked`() + } + + private fun `given ListRowItemWithSwitch`(checked: Boolean = false) = + `when ListRowItemWithSwitch`(checked) + + private fun `given is NOT checked`() = + `then is NOT checked`() + + private fun `when ListRowItemWithSwitch`(checked: Boolean = false) { + composeTestRule.setContent { + var isChecked by remember { mutableStateOf(checked) } + MisticaTheme(brand = MovistarBrand) { + ListRowItemWithSwitch( + listRowIcon = null, + headline = Tag("Promo"), + title = "title", + subtitle = "Subtitle", + description = "Description", + checked = isChecked, + onCheckedChange = { isChecked = it}, + ) + } + } + } + + private fun `when toggling the state`() { + composeTestRule.onNode(isToggleable()).performClick() + } + + private fun `then screenshot is OK`() { + compareScreenshot(composeTestRule.onRoot()) + } + + private fun `then is NOT checked`() { + composeTestRule.onNode(isToggleable()).assertIsOff() + } + + private fun `then is checked`() { + composeTestRule.onNode(isToggleable()).assertIsOn() + } +}