extends GutTest const GameScene = preload("res://scenes/Game.tscn") const AchievementManagerType = preload("res://scripts/domain/meta/achievement_manager.gd") const TitleEngineType = preload("res://scripts/domain/meta/title_engine.gd") var game: Game func before_each() -> void: game = GameScene.instantiate() add_child_autofree(game) await get_tree().process_frame func test_real_hit_unlocks_reward_toast_journal_claim_and_title_refresh() -> void: game.achievement_manager = AchievementManagerType.new([ { "id": "first_hit", "name": "Premier coup", "trigger": "player_hit_landed", "conditions": [], "reward_category": "aventurier", "reward_tier": "bronze", }, ]) game.title_engine = TitleEngineType.new([ {"id": "greenhorn", "name": "Bleu", "rank": 0, "conditions": []}, {"id": "striker", "name": "Frappeur", "rank": 1, "conditions": [{"type": "flag", "flag": "achv_first_hit", "equals": true}]}, ]) var state := game.get_game_state() state.enemies[&"goblin"].cell = state.player.cell + Vector2i.RIGHT state.player.weapon_damage = 1 await _dispatch_key(KEY_RIGHT) var panel := game.get_node("HUD/AchievementPanel") as PanelContainer assert_string_contains((game.get_node("HUD/AchievementToast") as Label).text, "Premier coup") assert_true(game.get_run_state().recent_events(game.get_run_state().log.size()).any(func(event: GameEvent) -> bool: return event.kind == &"achievement_unlocked")) assert_eq(game.get_run_state().current_title_id, &"striker") var permanent_title := game.get_node_or_null("HUD/TitleLabel") as Label var notification := game.get_node_or_null("HUD/TitleNotificationLabel") as Label var notification_timer := game.get_node_or_null("HUD/TitleNotificationTimer") as Timer assert_not_null(permanent_title) assert_not_null(notification, "HUD requires a separate temporary TitleNotificationLabel") assert_not_null(notification_timer, "HUD requires TitleNotificationTimer") if permanent_title != null: assert_eq(permanent_title.text, "Étage 0", "The permanent TopBar title remains the current floor") if notification == null or notification_timer == null: return assert_true(notification.visible, "A newly earned title needs a temporary notification") assert_eq(notification.text, "Frappeur") assert_true(notification_timer.one_shot) assert_eq(notification_timer.wait_time, 5.0) # The real five-second expiry is intentionally verified by the dedicated # transition test below, rather than manually emitting this timer's signal. if permanent_title != null: assert_eq(permanent_title.text, "Étage 0") await _dispatch_key(KEY_L) assert_true(panel.visible) assert_string_contains((panel.get_node("Body") as RichTextLabel).get_parsed_text(), "Récompense à réclamer") await _dispatch_key(KEY_ENTER) assert_true(game.get_run_state().recent_events(3).any(func(event: GameEvent) -> bool: return event.kind == &"achievement_reward_claimed")) assert_string_contains((panel.get_node("Body") as RichTextLabel).get_parsed_text(), "Récompense reçue") func test_title_notification_only_announces_real_transitions_and_expires_after_its_timer() -> void: var permanent_title := game.get_node_or_null("HUD/TitleLabel") as Label var notification := game.get_node_or_null("HUD/TitleNotificationLabel") as Label var notification_timer := game.get_node_or_null("HUD/TitleNotificationTimer") as Timer assert_not_null(permanent_title) assert_not_null(notification) assert_not_null(notification_timer) if permanent_title == null or notification == null or notification_timer == null: return assert_false(notification.visible, "Initialization must not announce the established title") assert_eq(notification.text, "") assert_eq(permanent_title.text, "Étage 0") game._refresh_title() assert_false(notification.visible, "Refreshing the same current title stays silent") assert_eq(permanent_title.text, "Étage 0") game.title_engine = TitleEngineType.new([]) game._refresh_title() assert_false(notification.visible, "Losing a title or receiving no title stays silent") assert_eq(notification.text, "") assert_eq(permanent_title.text, "Étage 0") game.title_engine = TitleEngineType.new([ {"id": "renewed", "name": "Renouveau", "rank": 1, "conditions": []}, ]) game._refresh_title() assert_true(notification.visible, "A real title transition needs a temporary notification") assert_eq(notification.text, "Renouveau") assert_true(notification_timer.time_left > 0.0) assert_eq(permanent_title.text, "Étage 0") game.title_engine = TitleEngineType.new([]) game._refresh_title() assert_false(notification.visible, "A title loss clears an in-flight notification") assert_eq(notification.text, "") assert_eq(permanent_title.text, "Étage 0") game.title_engine = TitleEngineType.new([ {"id": "renewed", "name": "Renouveau", "rank": 1, "conditions": []}, ]) game._refresh_title() assert_true(notification.visible, "Regaining a title is a real transition") await notification_timer.timeout await get_tree().process_frame assert_false(notification.visible, "The actual five-second timer hides the notification") assert_eq(notification.text, "") assert_eq(permanent_title.text, "Étage 0") func _dispatch_key(keycode: Key) -> void: Input.parse_input_event(_key_event(keycode, true)) await get_tree().process_frame Input.parse_input_event(_key_event(keycode, false)) await get_tree().process_frame func _key_event(keycode: Key, pressed: bool) -> InputEventKey: var event := InputEventKey.new() event.keycode = keycode event.physical_keycode = keycode event.pressed = pressed return event