-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
library/src/test/java/com/telefonica/mistica/compose/list/ListRowItemWithCheckBoxTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
library/src/test/java/com/telefonica/mistica/compose/list/ListRowItemWithSwitchTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |