import AppKit import XCTest @testable import CallsKit final class ChatWindowTests: XCTestCase { @MainActor func testClosingAndReopeningRetainsDraftWithoutDuplicatingWindow() { NSApplication.shared.setActivationPolicy(.prohibited) let call = Call(playAudio: false) let presentation = MacChatWindow() presentation.draft.text = "Keep this unsent message" presentation.open(call: call) XCTAssertTrue(presentation.isOpen) let first = NSApp.windows.first { $0.title == "Chat — Calls" } XCTAssertNotNil(first) presentation.open(call: call) XCTAssertEqual(NSApp.windows.filter { $0.title == "Chat — Calls" }.count, 1) presentation.close() XCTAssertFalse(presentation.isOpen) XCTAssertEqual(presentation.draft.text, "Keep this unsent message") presentation.open(call: call) XCTAssertTrue(presentation.isOpen) XCTAssertEqual(presentation.draft.text, "Keep this unsent message") presentation.close() } @MainActor func testWindowCloseButtonUpdatesPresentationState() { NSApplication.shared.setActivationPolicy(.prohibited) let presentation = MacChatWindow() presentation.open(call: Call(playAudio: false)) let window = NSApp.windows.first { $0.title == "Chat — Calls" } XCTAssertNotNil(window) window?.performClose(nil) XCTAssertFalse(presentation.isOpen) } }