Fix normal radio report submission
The radio button was connected only to the emergency hold handlers, so a normal Send request never reached _submit. Connect pressed for non-emergency calls while keeping hold-to-confirm exclusive to emergencies, and add tests for click, short-hold rejection and full emergency hold. Headless 249/249, Python 94/94.
This commit is contained in:
1 parent
aa51ee331e
commit
fac9b002c3
9 files changed
+62
-8
No files matched your search
@@ -105,6 +105,7 @@ func _init() -> void:
|
||||
action_button.text = "Send request"
|
||||
action_button.button_down.connect(func(): _start_hold())
|
||||
action_button.button_up.connect(func(): _stop_hold(false))
|
||||
action_button.pressed.connect(_on_action_pressed)
|
||||
buttons.add_child(action_button)
|
||||
var cancel_btn := Button.new()
|
||||
cancel_btn.text = "Cancel"
|
||||
@@ -144,6 +145,12 @@ func open(controller: Object, emergency: bool, truth: Dictionary) -> void:
|
||||
_hold_time = 0.0
|
||||
visible = true
|
||||
|
||||
## Non-emergency requests are a normal click. Emergency calls require the
|
||||
## press-and-hold path, so the click release must not submit early.
|
||||
func _on_action_pressed() -> void:
|
||||
if not _emergency:
|
||||
_submit()
|
||||
|
||||
func _start_hold() -> void:
|
||||
_holding = _emergency
|
||||
_hold_time = 0.0
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
extends RefCounted
|
||||
## Radio form submission: normal calls send on click; emergency calls require
|
||||
## the documented hold and do not submit on a quick release.
|
||||
|
||||
const RadioPanel := preload("res://src/game/ui/radio_panel.gd")
|
||||
|
||||
func test_normal_radio_sends_on_click() -> bool:
|
||||
var panel: RadioPanel = RadioPanel.new()
|
||||
var got := {}
|
||||
panel.submitted.connect(func(report, emergency):
|
||||
got["report"] = report
|
||||
got["emergency"] = emergency)
|
||||
panel.open(null, false, {})
|
||||
panel.action_button.pressed.emit()
|
||||
var a := TestUtils.check(got.has("report"), "normal click emits a report")
|
||||
var b := TestUtils.check(not bool(got.get("emergency", true)), "normal report is not emergency")
|
||||
var c := TestUtils.check(not panel.visible, "panel closes after sending")
|
||||
var d := TestUtils.check_eq(str(got.get("report", {}).get("location", "")), "front entrance",
|
||||
"default location is included")
|
||||
panel.free()
|
||||
return a and b and c and d
|
||||
|
||||
func test_emergency_requires_hold() -> bool:
|
||||
var panel: RadioPanel = RadioPanel.new()
|
||||
var calls := {"count": 0}
|
||||
panel.submitted.connect(func(_report, _emergency):
|
||||
calls["count"] = int(calls["count"]) + 1)
|
||||
panel.open(null, true, {})
|
||||
panel.action_button.pressed.emit()
|
||||
var a := TestUtils.check_eq(int(calls["count"]), 0, "quick emergency click does not send")
|
||||
panel.action_button.button_down.emit()
|
||||
panel._process(0.2)
|
||||
panel.action_button.button_up.emit()
|
||||
var b := TestUtils.check_eq(int(calls["count"]), 0, "short hold does not send")
|
||||
panel.action_button.button_down.emit()
|
||||
panel._process(RadioPanel.HOLD_NEEDED + 0.1)
|
||||
var c := TestUtils.check_eq(int(calls["count"]), 1, "full hold sends exactly once")
|
||||
panel.free()
|
||||
return a and b and c
|
||||
Reference in new issue
Block a user