Repository navigation
Unit Test : Key Mapping Menu — DeviceSettings & UI Behavior #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ikostan
merged 8 commits into
main
from
unit-test-3-keymapping-menu-device-tabs-ui-behavior
Jan 29, 2026
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ffd66ef
Unit Test Plan: 3. Key Mapping Menu — DeviceSettings & UI Behavior #349
ikostan 32e7ac3
Update test/gut/test_key_mapping_menu.gd
ikostan 198846e
Setting button_pressed does not emit the toggled signal.
ikostan acb30eb
Fragile assertion for gamepad label validation.
ikostan 5f0f733
Calling private methods (_on_pressed, _input) directly couples tests …
ikostan b4ff578
Update test_key_mapping_menu.gd
ikostan 66cf456
Remove duplicated default keyboard assignment.
ikostan 1154e2b
Hardcoded UI string may be fragile.
ikostan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # test_key_mapping_menu.gd | ||
| # GUT unit tests for Key Mapping Menu — Device Settings & UI Behavior (Issue #349) | ||
| # Adapted to actual implementation: CheckButtons (Keyboard/Gamepad) with ButtonGroup + dynamic update | ||
| # of remap_buttons (no TabContainer or separate show/hide lists; single list with device-specific labels). | ||
| # Tests verify switching updates current_device + button text, reset calls Settings.reset_to_defaults per device, | ||
| # and label updates after simulated remapping. | ||
| # References: key_mapping.gd, key_mapping_menu.tscn, input_remap_button.gd | ||
| # Assumes Settings.reset_to_defaults(device_type: String) exists and properly resets per-device events. | ||
| # Run with GUT framework. | ||
|
|
||
| extends GutTest | ||
|
|
||
| var menu: CanvasLayer = null | ||
| var keyboard_btn: CheckButton = null | ||
| var gamepad_btn: CheckButton = null | ||
| var reset_btn: Button = null | ||
| var remap_buttons: Array = [] | ||
|
|
||
|
|
||
| func before_each() -> void: | ||
| menu = load("res://scenes/key_mapping_menu.tscn").instantiate() # Adjust path if needed | ||
| add_child(menu) | ||
|
|
||
| # Get UI references | ||
| keyboard_btn = menu.get_node("Panel/Options/DeviceTypeContainer/Keyboard") | ||
| gamepad_btn = menu.get_node("Panel/Options/DeviceTypeContainer/Gamepad") | ||
| reset_btn = menu.get_node("Panel/Options/BtnContainer/ControlResetButton") | ||
|
|
||
| remap_buttons = menu.get_tree().get_nodes_in_group("remap_buttons") as Array[InputRemapButton] | ||
|
|
||
| # Default to keyboard (as in _ready) | ||
| keyboard_btn.button_pressed = true | ||
| menu._ready() # Ensure signals & updates run | ||
|
|
||
|
|
||
| func after_each() -> void: | ||
| if is_instance_valid(menu): | ||
| menu.queue_free() | ||
|
|
||
|
|
||
| # UI-01: Switch to keyboard settings | ||
| func test_ui_01_switch_to_keyboard() -> void: | ||
| gut.p("UI-01: Keyboard switch updates all remap_buttons to KEYBOARD device.") | ||
| keyboard_btn.button_pressed = true | ||
| # Verify keyboard device active, gamepad inactive | ||
| assert_true(keyboard_btn.button_pressed, "Keyboard CheckButton should be pressed") | ||
| assert_false(gamepad_btn.button_pressed, "Gamepad CheckButton should be inactive") | ||
| # All remap buttons updated to KEYBOARD | ||
| for btn: Variant in remap_buttons: | ||
| assert_eq(btn.current_device, InputRemapButton.DeviceType.KEYBOARD, | ||
| "Remap button device should be KEYBOARD after keyboard switch") | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| # UI-02: Switch to gamepad settings | ||
| func test_ui_02_switch_to_gamepad() -> void: | ||
| gut.p("UI-02: Gamepad switch updates all remap_buttons to GAMEPAD device.") | ||
| gamepad_btn.button_pressed = true | ||
| # Assertions | ||
| assert_true(gamepad_btn.button_pressed) | ||
| assert_false(keyboard_btn.button_pressed) | ||
| for btn: Variant in remap_buttons: | ||
| assert_eq(btn.current_device, InputRemapButton.DeviceType.GAMEPAD, | ||
| "Remap button device should be GAMEPAD after gamepad switch") | ||
| # Example: SpeedUp button text should reflect gamepad label (e.g. contains "Stick" or button name after update) | ||
| var speed_up_btn: Button = menu.get_node("Panel/Options/KeyMapContainer/PlayerKeyMap/KeyMappingSpeedUp/SpeedUpInputRemap") | ||
| assert_true(speed_up_btn.text.contains("Stick") or speed_up_btn.text.contains("Button") or speed_up_btn.text.length() > 1, | ||
| "Gamepad label should be descriptive (not a single key char)") | ||
|
|
||
|
|
||
| # UI-03: Reset button in keyboard mode | ||
| func test_ui_03_reset_in_keyboard() -> void: | ||
| gut.p("UI-03: Reset in keyboard mode resets keyboard actions via Settings.reset_to_defaults('keyboard'); gamepad unaffected.") | ||
| keyboard_btn.button_pressed = true | ||
| # Simulate a temporary non-default remap, then reset | ||
| var speed_up_btn: Button = menu.get_node("Panel/Options/KeyMapContainer/PlayerKeyMap/KeyMappingSpeedUp/SpeedUpInputRemap") | ||
| speed_up_btn.button_pressed = true | ||
| speed_up_btn._on_pressed() # Manually trigger the pressed handler to start listening | ||
| # | ||
| var temp_event := InputEventKey.new() | ||
| temp_event.physical_keycode = Key.KEY_Z # Non-default | ||
| temp_event.pressed = true # Ensure pressed for the condition in _input | ||
| speed_up_btn._input(temp_event) | ||
| reset_btn.pressed.emit() # Triggers _on_reset_pressed("keyboard") + update_all_remap_buttons | ||
| # Keyboard actions should now reflect defaults (not the temp "Z") | ||
| # Exact default text depends on Settings; here we verify update occurred + not unbound | ||
| assert_ne(speed_up_btn.text, "Z", "Keyboard reset should restore default (not keep temp remap)") | ||
| assert_ne(speed_up_btn.text, "Unbound", "Keyboard buttons should have default labels after reset") | ||
|
|
||
|
|
||
| # UI-04: Reset button in gamepad mode | ||
| func test_ui_04_reset_in_gamepad() -> void: | ||
| gut.p("UI-04: Reset in gamepad mode resets gamepad actions via Settings.reset_to_defaults('gamepad'); keyboard unaffected.") | ||
| gamepad_btn.button_pressed = true | ||
| # Temporary remap | ||
| var fire_btn: Button = menu.get_node("Panel/Options/KeyMapContainer/PlayerKeyMap/KeyMappingFire/FireInputRemap") | ||
| fire_btn.button_pressed = true | ||
| fire_btn._on_pressed() # Manually trigger the pressed handler to start listening | ||
| # | ||
| var temp_event := InputEventJoypadButton.new() | ||
| temp_event.button_index = JOY_BUTTON_B | ||
| temp_event.pressed = true # Ensure pressed for the condition in _input | ||
| fire_btn._input(temp_event) | ||
| # | ||
| reset_btn.pressed.emit() | ||
| # Assertions | ||
| assert_ne(fire_btn.text, "B", "Gamepad reset should restore default") | ||
| assert_ne(fire_btn.text, "Unbound") | ||
|
|
||
|
|
||
| # UI-05: Label update after remapping action (test both devices) | ||
| func test_ui_05_label_update_after_remapping() -> void: | ||
| gut.p("UI-05: Remapping updates UI text to reflect new InputEvent for both keyboard and gamepad tabs.") | ||
| # Keyboard remap | ||
| keyboard_btn.button_pressed = true | ||
| var left_btn: Button = menu.get_node("Panel/Options/KeyMapContainer/PlayerKeyMap/KeyMappingLeft/LeftInputRemap") | ||
| left_btn.button_pressed = true | ||
| left_btn._on_pressed() # Manually trigger the pressed handler to start listening | ||
| assert_eq(left_btn.text, "Press a key or controller button/axis...") | ||
| # | ||
| var key_event := InputEventKey.new() | ||
| key_event.physical_keycode = Key.KEY_A | ||
| key_event.pressed = true | ||
| left_btn._input(key_event) | ||
| # Assertions | ||
| assert_false(left_btn.listening) | ||
| assert_eq(left_btn.text, "A", "Keyboard remap should update button text to new key label") | ||
| # Gamepad remap | ||
| gamepad_btn.button_pressed = true | ||
| left_btn.button_pressed = true | ||
| left_btn._on_pressed() # Manually trigger the pressed handler to start listening | ||
| # | ||
| var joy_event := InputEventJoypadButton.new() | ||
| joy_event.button_index = JOY_BUTTON_DPAD_LEFT | ||
| joy_event.pressed = true | ||
| joy_event.device = -1 | ||
| left_btn._input(joy_event) | ||
| assert_eq(left_btn.text, "D-Pad Left", "Gamepad remap should update button text to new joypad label") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.