# test_whisper_chat_parity.gd —— 40250 独立私聊窗口与任务栏闪烁通知回归测试 extends SceneTree const SystemClass = preload("res://whisper_chat_system.gd") var _passed: int = 0 var _failed: int = 0 func _assert(cond: bool, msg: String) -> void: if cond: _passed += 1 print(" [PASS] %s" % msg) else: _failed += 1 printerr(" [FAIL] %s" % msg) func _init() -> void: print("\n=== Running test_whisper_chat_parity (Batch 27 Direction 2) ===") _test_conversation_lifecycle() _test_taskbar_blinking_notification() _test_gamemaster_identification() _test_ignore_blacklist_filtering() _test_bidirectional_messaging() print("\n=== Result: %d Passed, %d Failed ===" % [_passed, _failed]) if _failed == 0: print("ALL TESTS PASSED!\n") else: printerr("SOME TESTS FAILED!\n") quit(0 if _failed == 0 else 1) func _test_conversation_lifecycle() -> void: print("\n--- Test 1: Conversation Lifecycle (Open / Minimize / Close) ---") var w = SystemClass.new("Hero") var conv = w.open_conversation("Alice") _assert(conv != null, "Opened conversation with Alice") _assert(conv.state == SystemClass.DialogState.VISIBLE, "Conversation is VISIBLE") w.minimize_conversation("Alice") _assert(conv.state == SystemClass.DialogState.MINIMIZED, "Conversation MINIMIZED to taskbar") w.close_conversation("Alice") _assert(conv.state == SystemClass.DialogState.CLOSED, "Conversation CLOSED") func _test_taskbar_blinking_notification() -> void: print("\n--- Test 2: Taskbar Blinking & Unread Count ---") var w = SystemClass.new("Hero") # Receive message from Bob without active window var r = w.receive_whisper("Bob", "Hello there!") _assert(r["delivered"] == true, "Message delivered") _assert(r["triggered_blink"] == true, "Triggered taskbar blinking notification") var conv = w.conversations["Bob"] _assert(conv.is_blinking == true, "Bob's conversation is blinking") _assert(conv.unread_count == 1, "Unread count is 1") # Receive second message w.receive_whisper("Bob", "Are you there?") _assert(conv.unread_count == 2, "Unread count increased to 2") # Open conversation: should clear blinking and unread count w.open_conversation("Bob") _assert(conv.is_blinking == false, "Blinking cleared upon opening") _assert(conv.unread_count == 0, "Unread count reset to 0") _assert(conv.state == SystemClass.DialogState.VISIBLE, "Conversation state restored to VISIBLE") func _test_gamemaster_identification() -> void: print("\n--- Test 3: Game Master [GM] Identification ---") var w = SystemClass.new("Hero") var r = w.receive_whisper("[GM]Admin", "Server maintenance in 10 minutes.") _assert(r["delivered"] == true, "GM message delivered") var conv = w.conversations["[GM]Admin"] _assert(conv.is_gamemaster == true, "Identified as Game Master") _assert(conv.history[0].is_gm == true, "Message tagged with is_gm flag") func _test_ignore_blacklist_filtering() -> void: print("\n--- Test 4: Ignore Blacklist Filtering ---") var w = SystemClass.new("Hero") # Blacklist Spammer var is_ign = w.toggle_ignore_target("Spammer") _assert(is_ign == true, "Spammer added to ignore blacklist") _assert(w.is_ignored("Spammer") == true, "Spammer is ignored") # Receive whisper from Spammer var r = w.receive_whisper("Spammer", "Buy gold cheap!") _assert(r["delivered"] == false, "Spammer whisper rejected") _assert(r["blocked_by_ignore"] == true, "Blocked by ignore filter") _assert(w.get_blinking_conversations().is_empty(), "No blinking notifications triggered for ignored user") # Un-ignore Spammer var is_ign_again = w.toggle_ignore_target("Spammer") _assert(is_ign_again == false, "Spammer removed from ignore blacklist") var r2 = w.receive_whisper("Spammer", "Now you can hear me") _assert(r2["delivered"] == true, "Whisper delivered after un-ignoring") func _test_bidirectional_messaging() -> void: print("\n--- Test 5: Bidirectional Messaging History ---") var w = SystemClass.new("Hero") w.send_whisper("Alice", "Hey Alice, let's do Demon Tower!") w.current_time += 10 w.receive_whisper("Alice", "Sure, meet at DT entrance!") var conv = w.conversations["Alice"] _assert(conv.history.size() == 2, "Conversation history contains 2 messages") _assert(conv.history[0].sender == "Hero", "First message sent by Hero") _assert(conv.history[1].sender == "Alice", "Second message sent by Alice") _assert(conv.history[1].timestamp == 1010, "Timestamp recorded correctly")