Browse Source

web: add tests for onChange event for checkbox and radiobutton (#1411)

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
pull/1452/head
Oleksandr Karpovich 3 years ago committed by GitHub
parent
commit
1066bcab40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 53
      web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/ControlledInputsTests.kt
  2. 59
      web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/ControlledInputsTests.kt

53
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 { val checkBoxDefaultCheckedChangesDoesntAffectState by testCase {
var checked by remember { mutableStateOf(true) } 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 { val numberHardcodedNeverChanges by testCase {
var typedValue by remember { mutableStateOf("None") } var typedValue by remember { mutableStateOf("None") }
TestText(value = typedValue) TestText(value = typedValue)

59
web/integration-core/src/jvmTest/kotlin/org/jetbrains/compose/web/tests/integration/ControlledInputsTests.kt

@ -145,6 +145,41 @@ class ControlledInputsTests : BaseIntegrationTests() {
check(checkbox.isSelected) 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 @ResolveDrivers
fun checkBoxDefaultCheckedChangesDoesntAffectState(driver: WebDriver) { fun checkBoxDefaultCheckedChangesDoesntAffectState(driver: WebDriver) {
driver.openTestPage("checkBoxDefaultCheckedChangesDoesntAffectState") driver.openTestPage("checkBoxDefaultCheckedChangesDoesntAffectState")
@ -216,6 +251,30 @@ class ControlledInputsTests : BaseIntegrationTests() {
check(!radio2.isSelected) 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 @ResolveDrivers
fun numberHardcodedNeverChanges(driver: WebDriver) { fun numberHardcodedNeverChanges(driver: WebDriver) {
driver.openTestPage("numberHardcodedNeverChanges") driver.openTestPage("numberHardcodedNeverChanges")

Loading…
Cancel
Save