chore: Add basic tests for Studio's layer manipulation (#3164)

chore: Add test behaviors for Studio testing

chore: Add basic tests for studio layer adjustment

chore: Fixes from code review
This commit is contained in:
Nicolas Munnich
2026-01-08 01:01:05 +01:00
committed by GitHub
parent 70ab6b243a
commit 19582174f3
38 changed files with 573 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
s/.*layer_changed/layer_changed/p
s/.*hid_listener_keycode_//p
s/.*on_remove_layer_binding_pressed/remove_layer/p
s/.*tog_keymap_binding_pressed/tog_pressed/p

View File

@@ -0,0 +1,5 @@
-DCONFIG_ZMK_BEHAVIOR_METADATA=y
-DCONFIG_ZMK_BEHAVIOR_LOCAL_IDS=y
-DCONFIG_ZMK_KEYMAP_LAYER_REORDERING=y
-DCONFIG_ZMK_KEYMAP_SETTINGS_STORAGE=y
-DCONFIG_SETTINGS=y

View File

@@ -0,0 +1,8 @@
tog_pressed: position 1 layer 1
layer_changed: layer 1 state 1 locked 1
remove_layer: Removed layer at index 0
pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
tog_pressed: position 1 layer 1
pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00
released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00

View File

@@ -0,0 +1 @@
CONFIG_ZMK_TEST_BEHAVIORS=y

View File

@@ -0,0 +1,26 @@
#include <dt-bindings/zmk/keys.h>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/kscan_mock.h>
#include "../behavior_keymap.dtsi"
// Test removing layer 0: layer 1 becomes bottom layer
&kscan {
events = <
// toggle layer 1 on
ZMK_MOCK_PRESS(0,1,10)
ZMK_MOCK_RELEASE(0,1,10)
// remove layer 0
ZMK_MOCK_PRESS(1,0,10)
ZMK_MOCK_RELEASE(1,0,10)
// press position 0,0 - should output B (layer 1)
ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_RELEASE(0,0,10)
// try to toggle layer 1 off
ZMK_MOCK_PRESS(0,1,10)
ZMK_MOCK_RELEASE(0,1,10)
// press position 0,0 - should output B
// (layer 1 is now the bottom layer, so shouldn't be disabled)
ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_RELEASE(0,0,10)
>;
};

View File

@@ -0,0 +1,2 @@
This test fails because the keymap function handling position state changes doesn't work correctly when the default layer is removed.
The iteration loop's end condition is incorrect.