mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
test(sidecar): pin pressKey keycode mapping and unknown-key rejection
This commit is contained in:
1 parent
4b1832a8a4
commit
66f301562d
1 file changed
+23
@@ -2,10 +2,33 @@ package dev.sanderling.sidecar
|
|||||||
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFailsWith
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class InputTextTest {
|
class InputTextTest {
|
||||||
|
|
||||||
|
// A logical key name must map to the right Android keycode; a typo'd table
|
||||||
|
// entry would silently dispatch the wrong key (e.g. 'back' issuing HOME).
|
||||||
|
@Test fun pressKeyDispatchesMappedKeycode() {
|
||||||
|
val cases = mapOf(
|
||||||
|
"back" to "KEYCODE_BACK",
|
||||||
|
"enter" to "KEYCODE_ENTER",
|
||||||
|
"up" to "KEYCODE_DPAD_UP",
|
||||||
|
)
|
||||||
|
for ((key, keycode) in cases) {
|
||||||
|
val commands = mutableListOf<List<String>>()
|
||||||
|
StubDriverBackend("android") { commands.add(it) }.pressKey(key)
|
||||||
|
assertEquals(listOf(listOf("shell", "input", "keyevent", keycode)), commands, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun pressKeyRejectsUnknownKeyInsteadOfSilentlyDoingNothing() {
|
||||||
|
val commands = mutableListOf<List<String>>()
|
||||||
|
val backend = StubDriverBackend("android") { commands.add(it) }
|
||||||
|
assertFailsWith<IllegalArgumentException> { backend.pressKey("zorp") }
|
||||||
|
assertTrue(commands.isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
@Test fun inputTextTypesAtCursorWithoutClearing() {
|
@Test fun inputTextTypesAtCursorWithoutClearing() {
|
||||||
val commands = mutableListOf<List<String>>()
|
val commands = mutableListOf<List<String>>()
|
||||||
val backend = StubDriverBackend("android") { commands.add(it) }
|
val backend = StubDriverBackend("android") { commands.add(it) }
|
||||||
|
|||||||
Reference in new issue
Block a user