Fix question review interactions

This commit is contained in:
hz
2026-07-15 20:19:47 -05:00
parent ea0c602ab4
commit 17c136ef40
2 changed files with 141 additions and 50 deletions
+67
View File
@@ -8,6 +8,9 @@ func _initialize() -> void:
_test_reference_url_filter()
_test_correct_feedback_does_not_auto_advance()
_test_correct_review_locks_answer_interactions()
_test_eliminated_choice_uses_rich_text_strikeout()
_test_explanation_highlighting_has_no_status_heading()
_test_collapsed_followup_review_expands()
quit(1 if failures > 0 else 0)
@@ -74,6 +77,70 @@ func _test_correct_review_locks_answer_interactions() -> void:
player.free()
func _test_eliminated_choice_uses_rich_text_strikeout() -> void:
var player = load("res://scripts/ui/question_player.gd").new()
player.choice_buttons.append(Button.new())
player.choice_percent_labels.append(Label.new())
var strike_label := RichTextLabel.new()
strike_label.bbcode_enabled = true
player.choice_top_labels.append(strike_label)
player.choice_followup_panels.append(PanelContainer.new())
player.eliminated = ["A"]
player.presented_choices = [{"id": "A", "text": "Observation only"}]
player._set_choice_button_text(0, player.presented_choices[0])
_assert(player.choice_buttons[0].text == "", "eliminated choice should not use combining characters in button text")
_assert(strike_label.text == "[s]A. Observation only[/s]", "eliminated choice should use native rich-text strikeout")
_assert(not "[eliminated]" in strike_label.text, "eliminated choice should not include a redundant label")
player.choice_buttons[0].free()
player.choice_percent_labels[0].free()
strike_label.free()
player.choice_followup_panels[0].free()
player.free()
func _test_explanation_highlighting_has_no_status_heading() -> void:
var player = load("res://scripts/ui/question_player.gd").new()
player.explanation_label = RichTextLabel.new()
player.explanation_label.bbcode_enabled = true
player.explanation_plain_text = "The key finding supports observation."
player.explanation_highlights[""] = [{"start": 4, "end": 15}]
player._render_explanation()
_assert(not player.explanation_label.text.begins_with("[b]Correct"), "explanation should not repeat the inferred correct status")
_assert("[bgcolor=yellow]" in player.explanation_label.text, "explanation text should support highlighting")
player.explanation_label.free()
player.free()
func _test_collapsed_followup_review_expands() -> void:
var player = load("res://scripts/ui/question_player.gd").new()
var panel := PanelContainer.new()
var content := VBoxContainer.new()
panel.add_child(content)
player.choice_buttons.append(Button.new())
player.choice_percent_labels.append(Label.new())
player.choice_top_labels.append(RichTextLabel.new())
player.choice_followup_panels.append(panel)
player.choice_followup_contents.append(content)
player.next_button = Button.new()
player.presented_choices = [{"id": "B", "text": "Wrong answer"}]
player.followup_states["B"] = {
"choice_id": "B", "choice_text": "Wrong answer", "prompt": "Why?",
"selected_option_text": "Finding", "was_correct": false,
"teaching_point": "Review the finding.", "resolved": true, "collapsed": true
}
player._render_followup_state("B")
var review_button := content.get_child(0) as Button
_assert(review_button != null, "collapsed follow-up should render a review button")
review_button.pressed.emit()
_assert(not bool(player.followup_states["B"].get("collapsed", true)), "review button should expand the resolved follow-up")
player.choice_buttons[0].free()
player.choice_percent_labels[0].free()
player.choice_top_labels[0].free()
player.next_button.free()
panel.free()
player.free()
func _assert(condition: bool, message: String) -> void:
if condition:
return