-
Notifications
You must be signed in to change notification settings - Fork 22
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
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
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,65 @@ | ||
--- | ||
title: Android | ||
--- | ||
|
||
## Overview | ||
|
||
`Checkbox` component is provided in two flavors, as a simple checkbox and as a row with an additional label and a description: | ||
|
||
- [`Checkbox`](https://kiwicom.github.io/orbit-compose/ui/kiwi.orbit.compose.ui.controls/-checkbox.html) - a simple checkbox | ||
- [`CheckboxField`](https://kiwicom.github.io/orbit-compose/ui/kiwi.orbit.compose.ui.controls/-checkbox-field.html) a checkbox with label and description | ||
|
||
## Usage | ||
|
||
`Checkbox` accepts a boolean state and a callback on its change. | ||
|
||
```kotlin | ||
@Composable | ||
fun Example() { | ||
Checkbox( | ||
checked = false, | ||
onCheckedChange = { /*...*/ }, | ||
) | ||
} | ||
``` | ||
|
||
`CheckboxField` has two additional slots - `description` and `label`. | ||
|
||
```kotlin | ||
@Composable | ||
fun Example() { | ||
CheckboxField( | ||
checked = false, | ||
onCheckedChange = {}, | ||
description = { Text("If selected, you will get the latest updates.") } | ||
) { | ||
Text("Autoupdate") | ||
} | ||
} | ||
``` | ||
|
||
## UI testing | ||
|
||
Slotting API allows you to add testTag to particular component parts. Utilize `assertIsOn` and `assertIsOff` to check the state. | ||
|
||
```kotlin | ||
composeTestRule.setContent { | ||
var checked by remember { mutableStateOf(false) } | ||
CheckboxField( | ||
modifier = Modifier.testTag("checkbox"), | ||
checked = checked, | ||
onCheckedChange = { checked = !checked }, | ||
) { | ||
Text("Label") | ||
} | ||
} | ||
|
||
val checkbox = composeTestRule.onNodeWithTag("checkbox") | ||
checkbox.assertIsOff() | ||
checkbox.performClick() | ||
checkbox.assertIsOn() | ||
``` | ||
|
||
## Customization | ||
|
||
`Checkbox` and `CheckboxField` appearance is not customizable. |
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
42 changes: 42 additions & 0 deletions
42
ui/src/test/kotlin/kiwi/orbit/compose/ui/controls/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,42 @@ | ||
package kiwi.orbit.compose.ui.controls | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.test.assertIsOff | ||
import androidx.compose.ui.test.assertIsOn | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.performClick | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
internal class CheckboxTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testBasics() { | ||
composeTestRule.setContent { | ||
var checked by remember { mutableStateOf(false) } | ||
CheckboxField( | ||
modifier = Modifier.testTag("checkbox"), | ||
checked = checked, | ||
onCheckedChange = { checked = !checked }, | ||
description = { Text("Description") }, | ||
) { | ||
Text("Label") | ||
} | ||
} | ||
val checkbox = composeTestRule.onNodeWithTag("checkbox") | ||
checkbox.assertIsOff() | ||
checkbox.performClick() | ||
checkbox.assertIsOn() | ||
} | ||
} |