Skip to content

Unit Test : Key Mapping Menu — DeviceSettings & UI Behavior - #362

Merged
ikostan merged 8 commits into
mainfrom
unit-test-3-keymapping-menu-device-tabs-ui-behavior
Jan 29, 2026
Merged

Unit Test : Key Mapping Menu — DeviceSettings & UI Behavior#362
ikostan merged 8 commits into
mainfrom
unit-test-3-keymapping-menu-device-tabs-ui-behavior

Conversation

@ikostan

@ikostan ikostan commented Jan 29, 2026

Copy link
Copy Markdown
Owner

name: Default Pull Request Template
about: Suggesting changes to SkyLockAssault
title: ''
labels: ''
assignees: ''

Description

What does this PR do? (e.g., "Fixes player jump physics in level 2" or "Adds
new enemy AI script")

Related Issue

Closes #ISSUE_NUMBER (if applicable)

Changes

  • List key changes here (e.g., "Updated Jump.gd to use Godot 4.4's new Tween
    system")
  • Any breaking changes? (e.g., "Deprecated old signal; migrate to new one")

Testing

  • Ran the game in Godot v4.5 editor—describe what you tested (e.g., "Jump
    works on Win10 with 60 FPS")
  • Any new unit tests added? (Link to test scene if yes)
  • Screenshots/GIFs if UI-related: (Attach below)

Checklist

  • Code follows Godot style guide (e.g., snake_case for variables)
  • No console errors in editor/output
  • Ready for review!

Additional Notes

Anything else? (e.g., "Tested on Win10 64-bit; needs Linux validation")

Summary by Sourcery

Add unit tests for the key mapping menu’s device switching, reset behavior, and remap label updates, and centralize the remap prompt text in a global constant.

Enhancements:

  • Centralize the key remap prompt text as a shared global constant used by the remap button UI.

Tests:

  • Add GUT tests covering keyboard/gamepad switching, per-device reset behavior, and label updates after key and gamepad remapping in the key mapping menu.

Summary by CodeRabbit

  • Tests
    • Added UI tests for the Key Mapping Menu covering device switching (keyboard vs. gamepad), remapping flows, label updates after remapping, and reset actions that restore defaults; tests simulate interactions and verify per-device labels, listening state updates, and consistent behavior across input types.

✏️ Tip: You can customize this high-level summary in your review settings.

@sourcery-ai

sourcery-ai Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a shared remap prompt text constant and refactors the input remap button to use it, and introduces a new GUT test suite validating the key mapping menu’s device switching, reset behavior per device, and label updates after remapping for keyboard and gamepad inputs.

Sequence diagram for key remap button press using shared prompt text

sequenceDiagram
    actor Player
    participant KeyMappingMenu
    participant InputRemapButton
    participant Globals

    Player->>KeyMappingMenu: select action to remap
    KeyMappingMenu->>InputRemapButton: trigger _on_pressed()
    InputRemapButton->>InputRemapButton: set listening = true
    InputRemapButton->>Globals: access REMAP_PROMPT_TEXT
    Globals-->>InputRemapButton: REMAP_PROMPT_TEXT value
    InputRemapButton->>InputRemapButton: set text = REMAP_PROMPT_TEXT
    Player->>InputRemapButton: press key or controller input
    InputRemapButton->>InputRemapButton: set listening = false
    InputRemapButton->>InputRemapButton: update_button_text()
Loading

Class diagram for Globals and InputRemapButton remap prompt constant

classDiagram
    class Globals {
        <<Node>>
        enum LogLevel
        +current_log_level: LogLevel
        +enable_debug_logging: bool
        +difficulty: float
        +options_open: bool
        +previous_scene: String
        +options_scene: PackedScene
        +next_scene: String
        +REMAP_PROMPT_TEXT: String
        +_ready(): void
    }

    class InputRemapButton {
        <<Button>>
        -listening: bool
        +_ready(): void
        +_on_pressed(): void
        +update_button_text(): void
    }

    Globals <.. InputRemapButton : uses REMAP_PROMPT_TEXT
Loading

File-Level Changes

Change Details Files
Introduce a shared constant for the remap prompt text and use it in the input remap button instead of a hard-coded string.
  • Add REMAP_PROMPT_TEXT constant to the Globals singleton for reuse across UI components.
  • Replace the inline remap prompt string in the input remap button pressed handler with the shared global constant.
scripts/globals.gd
scripts/input_remap_button.gd
Add GUT unit tests covering key mapping menu device selection, reset behavior, and remap label updates for keyboard and gamepad.
  • Instantiate the key mapping menu scene in tests and cache references to keyboard/gamepad toggle buttons, reset button, and remap buttons group.
  • Add tests verifying that toggling between keyboard and gamepad updates remap button current_device and example button labels appropriately.
  • Add tests exercising reset behavior for keyboard and gamepad modes, ensuring defaults are restored and actions are not left unbound.
  • Add tests simulating remap flows by calling _on_pressed and _input on remap buttons with synthetic InputEventKey and InputEventJoypadButton events, asserting listening state and label text updates including the shared remap prompt text.
test/gut/test_key_mapping_menu.gd

Assessment against linked issues

Issue Objective Addressed Explanation
#349 Add GUT-based unit tests for the Key Mapping Menu covering device-specific UI behavior (UI-01 to UI-05: keyboard/gamepad switching, per-device reset behavior, and label updates after remapping).
#349 Use mock keyboard and gamepad input events in the tests to simulate remapping interactions without real input devices.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • These tests rely heavily on calling internal methods like _ready(), _on_pressed(), and _input() directly; consider driving the behavior via public signals/inputs where possible to reduce coupling to implementation details.
  • Assertions that depend on exact or partially descriptive button text (e.g. "A", "D-Pad Left", or contains("Stick")) may be brittle against localization or label changes; using properties like the bound InputEvent or a stable mapping helper would make the tests more robust.
  • The remap_buttons loop types each element as Variant; if the group is guaranteed to contain InputRemapButton instances, annotate the array and loop variable with that type to catch mismatches at edit-time.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- These tests rely heavily on calling internal methods like `_ready()`, `_on_pressed()`, and `_input()` directly; consider driving the behavior via public signals/inputs where possible to reduce coupling to implementation details.
- Assertions that depend on exact or partially descriptive button text (e.g. `"A"`, `"D-Pad Left"`, or `contains("Stick")`) may be brittle against localization or label changes; using properties like the bound `InputEvent` or a stable mapping helper would make the tests more robust.
- The `remap_buttons` loop types each element as `Variant`; if the group is guaranteed to contain `InputRemapButton` instances, annotate the array and loop variable with that type to catch mismatches at edit-time.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai

coderabbitai Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a new GUT test file exercising the Key Mapping Menu UI: device switching (keyboard/gamepad), remap button states and labels, reset flows, and remap interaction simulations across five test cases.

Changes

Cohort / File(s) Summary
New GUT test
test/gut/test_key_mapping_menu.gd
Adds a 137–147 line GUT test covering scene setup, device toggle behavior, remap_buttons initialization and current_device, keyboard/gamepad reset flows, and label updates after remaps (UI-01..UI-05).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related issues

Poem

🐰 I hopped through menus, buttons bright and neat,

I toggled keys and pads with nimble feet,
I pressed reset and watched the labels dance,
Remaps whispered back at every chance,
A rabbit cheers — the tests passed in a beat.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description uses the correct template but all sections contain placeholder text with checkmarks rather than actual content. Replace template placeholders in Description, Changes, Testing, and Additional Notes sections with specific details about the unit tests added and validation performed.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding unit tests for the Key Mapping Menu with a focus on device settings and UI behavior, which directly matches the test file's content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@test/gut/test_key_mapping_menu.gd`:
- Line 33: Remove the manual call to menu._ready() after add_child() to avoid
duplicate initialization; instead, after calling add_child(menu) wait a frame to
allow Godot to run the node lifecycle (e.g., await get_tree().process_frame or
yield(get_tree(), "idle_frame") depending on engine version) or assert the
specific initialized state you need—update the test in test_key_mapping_menu.gd
to call add_child(menu) and then wait for a process frame rather than invoking
menu._ready() directly.
- Around line 42-51: The test test_ui_01_switch_to_keyboard sets
keyboard_btn.button_pressed directly which does not emit the toggled signal, so
it may not exercise the menu's device-switch logic; update the test to simulate
a real user toggle by emitting the toggled signal or calling the CheckButton’s
pressed action (e.g., call emit_signal("toggled", true) or invoke the same
method the UI uses to handle toggles) on keyboard_btn (and ensure gamepad_btn
reflects the prior state from before_each) and then assert that each
remap_buttons entry has current_device == InputRemapButton.DeviceType.KEYBOARD
to verify the actual switch path is executed.
🧹 Nitpick comments (4)
test/gut/test_key_mapping_menu.gd (4)

64-67: Fragile assertion for gamepad label validation.

The condition text.contains("Stick") or text.contains("Button") or text.length() > 1 is overly permissive—any two-character string would pass. This doesn't reliably verify that the label reflects a gamepad-specific input.

Consider checking against known gamepad label patterns or verifying the button's current_device property instead:

Proposed improvement
 	# 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)")
+	# Verify it's not showing a keyboard key (single letter) and has meaningful gamepad text
+	assert_false(speed_up_btn.text.length() == 1 and speed_up_btn.text.to_upper() == speed_up_btn.text,
+		"Gamepad label should not be a single keyboard key character")
+	assert_ne(speed_up_btn.text, "Unbound", "Gamepad should have a default binding")

75-82: Calling private methods (_on_pressed, _input) directly couples tests to implementation.

Invoking _on_pressed() and _input() directly tests internal implementation rather than observable behavior. If these method names change, all tests break even if functionality is preserved.

This is a common tradeoff in UI testing—simulating real input in GUT is complex. If this approach is intentional, consider adding a comment documenting why direct method calls are used, or extract these into helper methods to isolate the coupling.


118-118: Hardcoded UI string may be fragile.

The expected text "Press a key or controller button/axis..." is hardcoded. If this prompt changes in the implementation, the test will fail even though functionality is correct.

Consider extracting this string to a constant shared with the implementation, or using a partial match (e.g., assert_true(left_btn.text.contains("Press"))) for more resilient assertions.


126-137: Expected label strings depend on Godot's internal formatting.

The assertions expect exact strings "A" and "D-Pad Left" which depend on how Godot formats InputEvent.as_text() or similar. These could vary across Godot versions.

If this is acceptable for your target Godot version, consider adding a comment noting the version dependency. Otherwise, consider more flexible assertions or extracting label formatting to a testable utility.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e4d5e8 and ffd66ef.

📒 Files selected for processing (1)
  • test/gut/test_key_mapping_menu.gd
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Browser Functional Tests / test
🔇 Additional comments (2)
test/gut/test_key_mapping_menu.gd (2)

36-38: LGTM!

Proper cleanup using is_instance_valid() check before queue_free().


90-107: LGTM!

Follows the same pattern as test_ui_03. The same notes about private method calls apply, but the test logic is consistent and the assertions appropriately verify reset behavior.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread test/gut/test_key_mapping_menu.gd Outdated
Comment thread test/gut/test_key_mapping_menu.gd
ikostan and others added 5 commits January 28, 2026 20:46
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
In Godot 4, programmatically setting button_pressed = true on a CheckButton does not trigger the toggled signal. If the menu's device-switching logic relies on that signal, this test may not actually exercise the switching code path.

Since keyboard_btn.button_pressed = true is already set in before_each, this test may pass trivially without verifying the switching behavior.

Consider emitting the signal explicitly or testing the actual transition from gamepad to keyboard.
The condition text.contains("Stick") or text.contains("Button") or text.length() > 1 is overly permissive—any two-character string would pass. This doesn't reliably verify that the label reflects a gamepad-specific input.

Consider checking against known gamepad label patterns or verifying the button's current_device property instead
…to implementation.

Invoking _on_pressed() and _input() directly tests internal implementation rather than observable behavior. If these method names change, all tests break even if functionality is preserved.

This is a common tradeoff in UI testing—simulating real input in GUT is complex. If this approach is intentional, consider adding a comment documenting why direct method calls are used, or extract these into helper methods to isolate the coupling.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@test/gut/test_key_mapping_menu.gd`:
- Around line 67-74: Replace the brittle string-heuristic checks on the Button
text (speed_up_btn / SpeedUpInputRemap) with assertions against the actual bound
input event or InputMap entries: retrieve the remap control's bound InputEvent
(or use InputMap.get_action_list with the speed-up action name) and assert the
event is a gamepad type (e.g., InputEventJoypadButton or InputEventJoypadMotion)
and not an InputEventKey, and also assert that an event exists (not unbound).
Use the SpeedUpInputRemap node reference to locate the binding instead of
inspecting speed_up_btn.text.
🧹 Nitpick comments (1)
test/gut/test_key_mapping_menu.gd (1)

28-31: Remove duplicated default keyboard assignment.

The second keyboard_btn.button_pressed = true is redundant and adds noise.

♻️ Proposed cleanup
-	# Default to keyboard (as in _ready)
-	keyboard_btn.button_pressed = true
-	# Default to keyboard (as in _ready)
-	keyboard_btn.button_pressed = true
+	# Default to keyboard (as in _ready)
+	keyboard_btn.button_pressed = true
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 198846e and b4ff578.

📒 Files selected for processing (1)
  • test/gut/test_key_mapping_menu.gd
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Browser Functional Tests / test

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread test/gut/test_key_mapping_menu.gd
The second keyboard_btn.button_pressed = true is redundant and adds noise.
The expected text "Press a key or controller button/axis..." is hardcoded. If this prompt changes in the implementation, the test will fail even though functionality is correct.

Consider extracting this string to a constant shared with the implementation, or using a partial match (e.g., assert_true(left_btn.text.contains("Press"))) for more resilient assertions.
@ikostan

ikostan commented Jan 29, 2026

Copy link
Copy Markdown
Owner Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The tests reach into private methods like _on_pressed() and _input() on the remap buttons, which tightly couples them to the internal implementation; consider driving these flows via public signals or higher-level menu handlers so future refactors don’t break tests unnecessarily.
  • In test_key_mapping_menu.gd, the use of hard-coded node paths (e.g. Panel/Options/KeyMapContainer/PlayerKeyMap/...) makes the tests brittle against UI layout changes; you might instead rely on groups, exported references, or helper getters from the menu script to locate key remap buttons.
  • The remap_buttons array is typed as Array with elements accessed as Variant; you can tighten this to Array[InputRemapButton] (and drop the Variant annotation in the loop) to catch type issues at compile time and improve readability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The tests reach into private methods like `_on_pressed()` and `_input()` on the remap buttons, which tightly couples them to the internal implementation; consider driving these flows via public signals or higher-level menu handlers so future refactors don’t break tests unnecessarily.
- In `test_key_mapping_menu.gd`, the use of hard-coded node paths (e.g. `Panel/Options/KeyMapContainer/PlayerKeyMap/...`) makes the tests brittle against UI layout changes; you might instead rely on groups, exported references, or helper getters from the menu script to locate key remap buttons.
- The `remap_buttons` array is typed as `Array` with elements accessed as `Variant`; you can tighten this to `Array[InputRemapButton]` (and drop the `Variant` annotation in the loop) to catch type issues at compile time and improve readability.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ikostan

ikostan commented Jan 29, 2026

Copy link
Copy Markdown
Owner Author

Hey - I've left some high level feedback:

  • The tests reach into private methods like _on_pressed() and _input() on the remap buttons, which tightly couples them to the internal implementation; consider driving these flows via public signals or higher-level menu handlers so future refactors don’t break tests unnecessarily.
  • In test_key_mapping_menu.gd, the use of hard-coded node paths (e.g. Panel/Options/KeyMapContainer/PlayerKeyMap/...) makes the tests brittle against UI layout changes; you might instead rely on groups, exported references, or helper getters from the menu script to locate key remap buttons.
  • The remap_buttons array is typed as Array with elements accessed as Variant; you can tighten this to Array[InputRemapButton] (and drop the Variant annotation in the loop) to catch type issues at compile time and improve readability.

Prompt for AI Agents

Please address the comments from this code review:

## Overall Comments
- The tests reach into private methods like `_on_pressed()` and `_input()` on the remap buttons, which tightly couples them to the internal implementation; consider driving these flows via public signals or higher-level menu handlers so future refactors don’t break tests unnecessarily.
- In `test_key_mapping_menu.gd`, the use of hard-coded node paths (e.g. `Panel/Options/KeyMapContainer/PlayerKeyMap/...`) makes the tests brittle against UI layout changes; you might instead rely on groups, exported references, or helper getters from the menu script to locate key remap buttons.
- The `remap_buttons` array is typed as `Array` with elements accessed as `Variant`; you can tighten this to `Array[InputRemapButton]` (and drop the `Variant` annotation in the loop) to catch type issues at compile time and improve readability.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Won't fix any of it, those are minor issues in my opinion.

@ikostan
ikostan merged commit 24c5b30 into main Jan 29, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Sky Lock Assault Project Jan 29, 2026
@ikostan
ikostan deleted the unit-test-3-keymapping-menu-device-tabs-ui-behavior branch January 29, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Unit Test Plan: 3. Key Mapping Menu — DeviceSettings & UI Behavior

1 participant