diff --git a/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/ControlledInputsTests.kt b/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/ControlledInputsTests.kt index 11782dd5fc..4ffc5fdb39 100644 --- a/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/ControlledInputsTests.kt +++ b/web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/ControlledInputsTests.kt @@ -137,6 +137,36 @@ class ControlledInputsTests { } } + val checkBoxMutableValueChangesThroughOnChange by testCase { + var checked by remember { mutableStateOf(false) } + + P { TestText(checked.toString()) } + + Div { + CheckboxInput(checked = checked) { + id("checkbox") + onChange { event -> + checked = event.value + } + } + } + } + + val checkBoxMutableValueChangesForEveryOnChange by testCase { + var checked by remember { mutableStateOf(true) } + + P { TestText(checked.toString()) } + + Div { + CheckboxInput(checked = checked) { + id("checkbox") + onChange { event -> + checked = event.value + } + } + } + } + val checkBoxDefaultCheckedChangesDoesntAffectState by testCase { var checked by remember { mutableStateOf(true) } @@ -188,6 +218,29 @@ class ControlledInputsTests { } } + val radioMutableCheckedChangesThroughOnChange by testCase { + var checked by remember { mutableStateOf(0) } + + TestText("Checked - $checked") + + Div { + RadioInput(checked = checked == 1) { + id("radio1") + name("group1") + onChange { event -> + if (event.value) checked = 1 + } + } + RadioInput(checked = checked == 2) { + id("radio2") + name("group1") + onChange { event -> + if (event.value) checked = 2 + } + } + } + } + val numberHardcodedNeverChanges by testCase { var typedValue by remember { mutableStateOf("None") } TestText(value = typedValue) diff --git a/web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/ControlledInputsTests.kt b/web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/ControlledInputsTests.kt index 071a4ec3c6..4c24ee65c0 100644 --- a/web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/ControlledInputsTests.kt +++ b/web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/ControlledInputsTests.kt @@ -145,6 +145,41 @@ class ControlledInputsTests : BaseIntegrationTests() { check(checkbox.isSelected) } + @ResolveDrivers + fun checkBoxMutableValueChangesThroughOnChange(driver: WebDriver) { + driver.openTestPage("checkBoxMutableValueChangesThroughOnChange") + driver.waitTextToBe(value = "false") + + val checkbox = driver.findElement(By.id("checkbox")) + check(!checkbox.isSelected) + + checkbox.click() + + driver.waitTextToBe(value = "true") + check(checkbox.isSelected) + } + + @ResolveDrivers + fun checkBoxMutableValueChangesForEveryOnChange(driver: WebDriver) { + driver.openTestPage("checkBoxMutableValueChangesForEveryOnChange") + driver.waitTextToBe(value = "true") + + val checkbox = driver.findElement(By.id("checkbox")) + check(checkbox.isSelected) + + checkbox.click() + driver.waitTextToBe(value = "false") + check(!checkbox.isSelected) + + checkbox.click() + driver.waitTextToBe(value = "true") + check(checkbox.isSelected) + + checkbox.click() + driver.waitTextToBe(value = "false") + check(!checkbox.isSelected) + } + @ResolveDrivers fun checkBoxDefaultCheckedChangesDoesntAffectState(driver: WebDriver) { driver.openTestPage("checkBoxDefaultCheckedChangesDoesntAffectState") @@ -216,6 +251,30 @@ class ControlledInputsTests : BaseIntegrationTests() { check(!radio2.isSelected) } + @ResolveDrivers + fun radioMutableCheckedChangesThroughOnChange(driver: WebDriver) { + driver.openTestPage("radioMutableCheckedChanges") + driver.waitTextToBe(value = "Checked - 0") + + val radio1 = driver.findElement(By.id("radio1")) + val radio2 = driver.findElement(By.id("radio2")) + + check(!radio1.isSelected) + check(!radio2.isSelected) + + radio2.click() + driver.waitTextToBe(value = "Checked - 2") + + check(!radio1.isSelected) + check(radio2.isSelected) + + radio1.click() + driver.waitTextToBe(value = "Checked - 1") + + check(radio1.isSelected) + check(!radio2.isSelected) + } + @ResolveDrivers fun numberHardcodedNeverChanges(driver: WebDriver) { driver.openTestPage("numberHardcodedNeverChanges")