Skip to content

Commit

Permalink
Test: add CheckboxTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Darocs authored and alex-tiurin committed Jul 24, 2024
1 parent 3b4dff8 commit 4229a99
Showing 1 changed file with 41 additions and 0 deletions.
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()
}
}

0 comments on commit 4229a99

Please sign in to comment.