-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement top-node semantics for Stepper
closes #349
- Loading branch information
Showing
5 changed files
with
149 additions
and
3 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,68 @@ | ||
--- | ||
title: Android | ||
--- | ||
|
||
## Overview | ||
|
||
`Stepper` component is provided as a single value component in two variants: | ||
|
||
- [`Stepper` with min & max values](https://kiwicom.github.io/orbit-compose/ui/kiwi.orbit.compose.ui.controls/-stepper.html) | ||
- [`Stepper` with a custom validator](https://kiwicom.github.io/orbit-compose/ui/kiwi.orbit.compose.ui.controls/-stepper.html) | ||
|
||
## Usage | ||
|
||
Use the `Stepper` composable and define its value and value change callback. Optionally, set up the value boundaries using `minValue` and `maxValue`. The overloaded implementation allows you to set up a custom validator and also set custom `contentDescription` labels for the increase and decrease actions. | ||
|
||
The whole component can be info-color highlighted by setting it as `active`. | ||
|
||
```kotlin | ||
@Composable | ||
fun Example() { | ||
var value by remember { mutableIntStateOf(0) } | ||
Stepper( | ||
modifier = Modifier.testTag("stepper"), | ||
value = value, | ||
onValueChange = { value = it }, | ||
active = value > 0, | ||
minValue = 0, | ||
maxValue = 10, | ||
) | ||
} | ||
``` | ||
|
||
## UI Testing | ||
|
||
Use semantic properties and custom actions to read the value and increase/decrease it. | ||
|
||
If the button is not active, the particular semantic action is not added, use `fetchSemanticsNode()` to check its presence. | ||
|
||
```kotlin | ||
composeTestRule.setContent { | ||
var value by remember { mutableIntStateOf(0) } | ||
Stepper( | ||
modifier = Modifier.testTag("stepper"), | ||
value = value, | ||
onValueChange = { value = it }, | ||
) | ||
} | ||
val stepper = composeTestRule.onNodeWithTag("stepper") | ||
|
||
assertFalse(stepper.fetchSemanticsNode().config.contains(StepperSemanticsActions.DecreaseValue)) | ||
assertTrue(stepper.fetchSemanticsNode().config.contains(StepperSemanticsActions.IncreaseValue)) | ||
|
||
stepper | ||
.assertTextEquals("0") | ||
.performSemanticsAction(StepperSemanticsActions.IncreaseValue) | ||
.assertTextEquals("1") | ||
.performSemanticsAction(StepperSemanticsActions.IncreaseValue) | ||
.assertTextEquals("2") | ||
.performSemanticsAction(StepperSemanticsActions.DecreaseValue) | ||
.assertTextEquals("1") | ||
|
||
assertTrue(stepper.fetchSemanticsNode().config.contains(StepperSemanticsActions.DecreaseValue)) | ||
assertTrue(stepper.fetchSemanticsNode().config.contains(StepperSemanticsActions.IncreaseValue)) | ||
``` | ||
|
||
## Customization | ||
|
||
`Stepper` 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
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
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
52 changes: 52 additions & 0 deletions
52
ui/src/test/kotlin/kiwi/orbit/compose/ui/controls/StepperTest.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,52 @@ | ||
package kiwi.orbit.compose.ui.controls | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableIntStateOf | ||
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.assertTextEquals | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.performSemanticsAction | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
internal class StepperTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testBasics() { | ||
composeTestRule.setContent { | ||
var value by remember { mutableIntStateOf(0) } | ||
Stepper( | ||
modifier = Modifier.testTag("stepper"), | ||
value = value, | ||
onValueChange = { value = it }, | ||
) | ||
} | ||
val stepper = composeTestRule.onNodeWithTag("stepper") | ||
|
||
assertFalse(stepper.fetchSemanticsNode().config.contains(StepperSemanticsActions.DecreaseValue)) | ||
assertTrue(stepper.fetchSemanticsNode().config.contains(StepperSemanticsActions.IncreaseValue)) | ||
|
||
stepper | ||
.assertTextEquals("0") | ||
.performSemanticsAction(StepperSemanticsActions.IncreaseValue) | ||
.assertTextEquals("1") | ||
.performSemanticsAction(StepperSemanticsActions.IncreaseValue) | ||
.assertTextEquals("2") | ||
.performSemanticsAction(StepperSemanticsActions.DecreaseValue) | ||
.assertTextEquals("1") | ||
|
||
assertTrue(stepper.fetchSemanticsNode().config.contains(StepperSemanticsActions.DecreaseValue)) | ||
assertTrue(stepper.fetchSemanticsNode().config.contains(StepperSemanticsActions.IncreaseValue)) | ||
} | ||
} |