-
Notifications
You must be signed in to change notification settings - Fork 12
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
1 parent
3b4dff8
commit 4229a99
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
sample-app/src/androidTest/java/com/atiurin/sampleapp/tests/compose/CheckboxTest.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,41 @@ | ||
package com.atiurin.sampleapp.tests.compose | ||
|
||
import androidx.compose.material.TriStateCheckbox | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.semantics.contentDescription | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.state.ToggleableState | ||
import androidx.compose.ui.test.hasContentDescription | ||
import com.atiurin.ultron.core.compose.createDefaultUltronComposeRule | ||
import com.atiurin.ultron.core.compose.nodeinteraction.click | ||
import com.atiurin.ultron.extensions.assertIsIndeterminate | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class CheckboxTest { | ||
@get:Rule | ||
val composeRule = createDefaultUltronComposeRule() | ||
|
||
@Test | ||
fun checkboxStates() { | ||
val testTag = "checkBox" | ||
composeRule.setContent { | ||
val checkedState = remember { mutableStateOf(ToggleableState.Indeterminate) } | ||
TriStateCheckbox( | ||
state = checkedState.value, | ||
onClick = { | ||
if (checkedState.value == ToggleableState.Indeterminate || checkedState.value == ToggleableState.Off) | ||
checkedState.value = ToggleableState.On | ||
else checkedState.value = ToggleableState.Off | ||
}, | ||
modifier = Modifier.semantics { contentDescription = testTag } | ||
) | ||
} | ||
|
||
hasContentDescription(testTag).assertIsIndeterminate() | ||
.click().assertIsOn() | ||
.click().assertIsOff() | ||
} | ||
} |