mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
test(input): exercise the real duplicate bindings step and check another saved preset
This commit is contained in:
1 parent
714a090f4f
commit
cc29854356
3 files changed
+18
-15
No files matched your search
@@ -59,9 +59,14 @@ internal fun InputSurfaceElement.duplicate(id: String, siblings: List<InputSurfa
|
||||
return copy(id = id, control = kind.control, name = named(number), x = px, y = py).bounded()
|
||||
}
|
||||
|
||||
internal fun InputAction.carriedTo(source: InputSurfaceElement): InputAction =
|
||||
private fun InputAction.carriedTo(source: InputSurfaceElement): InputAction =
|
||||
if (this is InputAction.Native && target == null && source.id.startsWith("legacy:")) InputAction.Native(source.control) else this
|
||||
|
||||
internal fun SavedInputBindings.withDuplicate(source: InputSurfaceElement, copy: InputSurfaceElement) = copy(
|
||||
elements = elements + (copy.id to action(source).carriedTo(source)),
|
||||
clicks = if (source.hasClick) clicks + (copy.id to clickAction(source)) else clicks,
|
||||
)
|
||||
|
||||
internal val QUICK_BUTTONS = listOf(InputCommand.STEAM, InputCommand.QUICK_ACCESS, InputCommand.KEYBOARD)
|
||||
|
||||
val InputSurfaceElement.quickButton: InputCommand? get() = when {
|
||||
|
||||
@@ -109,9 +109,10 @@ private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputB
|
||||
}
|
||||
fun duplicate(e: InputSurfaceElement) {
|
||||
val copy = e.duplicate(newInputId(), elements)
|
||||
val bound = preset.copy(elements = actions, clicks = clicks).withDuplicate(e, copy)
|
||||
checkpoint()
|
||||
actions = actions + (copy.id to action(e).carriedTo(e))
|
||||
if (e.hasClick) clicks = clicks + (copy.id to clickAction(e))
|
||||
actions = bound.elements
|
||||
clicks = bound.clicks
|
||||
elements = elements + copy
|
||||
selected = copy.id
|
||||
}
|
||||
|
||||
@@ -224,9 +224,7 @@ class InputLayoutToolsTest {
|
||||
for (source in layout.elements) {
|
||||
val copy = source.duplicate("copy", layout.elements)
|
||||
assertEquals(copy.kind.control, copy.control)
|
||||
val actions = mapOf(copy.id to base.action(source).carriedTo(source))
|
||||
val clicks = if (source.hasClick) mapOf(copy.id to base.clickAction(source)) else emptyMap()
|
||||
val preset = base.copy(elements = actions, clicks = clicks)
|
||||
val preset = base.copy(elements = base.elements.filterKeys { it == source.id }, clicks = base.clicks.filterKeys { it == source.id }).withDuplicate(source, copy)
|
||||
library.withLayout(layout.copy(elements = layout.elements + copy)).withPreset(preset).validate()
|
||||
assertEquals(InputAction.Native(source.control), preset.action(copy))
|
||||
if (source.hasClick) assertEquals(base.clickAction(source), preset.clickAction(copy))
|
||||
@@ -243,26 +241,25 @@ class InputLayoutToolsTest {
|
||||
elements = mapOf(button.id to InputAction.Keys(listOf(30)), pad.id to InputAction.Pointer(500f)),
|
||||
clicks = mapOf(pad.id to InputAction.MouseButton(273)),
|
||||
)
|
||||
val other = base.copy(elements = mapOf(button.id to InputAction.Keys(listOf(31))))
|
||||
val other = base.copy(id = "other", name = "Other", elements = mapOf(button.id to InputAction.Keys(listOf(31))))
|
||||
val fixture = library.withLayout(layout).withPreset(custom).withPreset(other).validate()
|
||||
var elements = layout.elements
|
||||
var actions = custom.elements
|
||||
var clicks = custom.clicks
|
||||
var result = custom
|
||||
for (source in listOf(button, pad)) {
|
||||
val copy = source.duplicate("copy-${source.id}", elements)
|
||||
actions = actions + (copy.id to custom.copy(elements = actions).action(source).carriedTo(source))
|
||||
if (source.hasClick) clicks = clicks + (copy.id to custom.copy(elements = actions, clicks = clicks).clickAction(source))
|
||||
result = result.withDuplicate(source, copy)
|
||||
elements = elements + copy
|
||||
}
|
||||
val result = custom.copy(elements = actions, clicks = clicks)
|
||||
library.withLayout(layout.copy(elements = elements)).withPreset(result).validate()
|
||||
val updated = fixture.withLayout(layout.copy(elements = elements)).withPreset(result).validate()
|
||||
assertEquals(other, updated.preset(other.id))
|
||||
assertEquals(InputAction.Keys(listOf(30)), result.action(elements.first { it.id == "copy-${button.id}" }))
|
||||
assertEquals(InputAction.Pointer(500f), result.action(elements.first { it.id == "copy-${pad.id}" }))
|
||||
assertEquals(InputAction.MouseButton(273), result.clickAction(elements.first { it.id == "copy-${pad.id}" }))
|
||||
assertEquals(custom.action(button), result.action(button))
|
||||
assertEquals(custom.action(pad), result.action(pad))
|
||||
assertEquals(custom.clickAction(pad), result.clickAction(pad))
|
||||
assertEquals(InputAction.Keys(listOf(31)), other.action(button))
|
||||
assertEquals(base.action(pad), other.action(pad))
|
||||
assertEquals(InputAction.Keys(listOf(31)), updated.preset(other.id).action(button))
|
||||
assertEquals(base.action(pad), updated.preset(other.id).action(pad))
|
||||
}
|
||||
|
||||
@Test fun duplicateNamesNeverExceedTheNameLimit() {
|
||||
|
||||
Reference in new issue
Block a user