Browse Source

web: Add tests for `AutoComplete` attribute for different elements

pull/870/head
Oleksandr Karpovich 4 years ago
parent
commit
d94c185125
  1. 2
      web/core/src/jsMain/kotlin/androidx/compose/web/attributes/Attrs.kt
  2. 6
      web/core/src/jsMain/kotlin/androidx/compose/web/attributes/PredefinedAttrValues.kt
  3. 43
      web/core/src/jsTest/kotlin/elements/InputsGenerateCorrectHtmlTests.kt

2
web/core/src/jsMain/kotlin/androidx/compose/web/attributes/Attrs.kt

@ -211,7 +211,7 @@ fun AttrsBuilder<HTMLOptionElement>.label(value: String) =
/* Select attributes */
fun AttrsBuilder<HTMLSelectElement>.autocomplete(value: AutoComplete) =
fun AttrsBuilder<HTMLSelectElement>.autoComplete(value: AutoComplete) =
attr("autocomplete", value.unsafeCast<String>())
fun AttrsBuilder<HTMLSelectElement>.autofocus() =

6
web/core/src/jsMain/kotlin/androidx/compose/web/attributes/PredefinedAttrValues.kt

@ -1,5 +1,3 @@
@file:Suppress("Unused", "NOTHING_TO_INLINE", "NESTED_CLASS_IN_EXTERNAL_INTERFACE", "INLINE_EXTERNAL_DECLARATION", "WRONG_BODY_OF_EXTERNAL_DECLARATION", "NESTED_EXTERNAL_DECLARATION", "ClassName")
package org.jetbrains.compose.web.attributes
import org.w3c.dom.events.Event
@ -168,6 +166,7 @@ enum class Scope(val str: String) {
/**
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
*/
@Suppress("Unused", "NOTHING_TO_INLINE", "NESTED_CLASS_IN_EXTERNAL_INTERFACE", "INLINE_EXTERNAL_DECLARATION", "WRONG_BODY_OF_EXTERNAL_DECLARATION", "NESTED_EXTERNAL_DECLARATION", "ClassName")
external interface AutoComplete {
external companion object {
/**
@ -184,7 +183,7 @@ external interface AutoComplete {
/**
*The field expects the value to be a person's full name. Using "name" rather than breaking the name down into its components is generally preferred because it avoids dealing with the wide diversity of human names and how they are structured; however, you can use the following autocomplete values if you do need to break the name down into its components:
*/
inline val Name get() = AutoComplete("name")
inline val name get() = AutoComplete("name")
/**
* The prefix or title, such as "Mrs.", "Mr.", "Miss", "Ms.", "Dr.", or "Mlle.".
@ -436,4 +435,5 @@ external interface AutoComplete {
}
}
@Suppress("NOTHING_TO_INLINE")
inline fun AutoComplete(value: String) = value.unsafeCast<AutoComplete>()

43
web/core/src/jsTest/kotlin/elements/InputsGenerateCorrectHtmlTests.kt

@ -1,5 +1,8 @@
package org.jetbrains.compose.web.core.tests.elements
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.getValue
import org.jetbrains.compose.web.attributes.*
import org.jetbrains.compose.web.core.tests.runTest
import org.jetbrains.compose.web.dom.*
@ -391,9 +394,47 @@ class InputsGenerateCorrectHtmlTests {
fun textInputWithAutoComplete() = runTest {
composition {
TextInput {
autoComplete(AutoComplete.Name)
autoComplete(AutoComplete.name)
}
}
assertEquals("""<input type="text" autocomplete="name">""", root.innerHTML)
}
@Test
fun textAreaWithAutoComplete() = runTest {
composition {
TextArea({
autoComplete(AutoComplete.email)
}, value = "")
}
assertEquals("""<textarea autocomplete="email"></textarea>""", root.innerHTML)
}
@Test
fun formWithAutoComplete() = runTest {
var autoCompleteEnabled by mutableStateOf(true)
composition {
Form(attrs = {
autoComplete(autoCompleteEnabled)
})
}
assertEquals("""<form autocomplete="on"></form>""", root.innerHTML)
autoCompleteEnabled = false
waitChanges()
assertEquals("""<form autocomplete="off"></form>""", root.innerHTML)
}
@Test
fun selectWithAutoComplete() = runTest {
composition {
Select({
autoComplete(AutoComplete.tel)
})
}
assertEquals("""<select autocomplete="tel"></select>""", root.innerHTML)
}
}

Loading…
Cancel
Save