| 1 | import AppKit |
| 2 | import XCTest |
| 3 | |
| 4 | @testable import CallsKit |
| 5 | |
| 6 | final class ChatWindowTests: XCTestCase { |
| 7 | @MainActor func testClosingAndReopeningRetainsDraftWithoutDuplicatingWindow() { |
| 8 | NSApplication.shared.setActivationPolicy(.prohibited) |
| 9 | let call = Call(playAudio: false) |
| 10 | let presentation = MacChatWindow() |
| 11 | presentation.draft.text = "Keep this unsent message" |
| 12 | presentation.open(call: call) |
| 13 | XCTAssertTrue(presentation.isOpen) |
| 14 | let first = NSApp.windows.first { $0.title == "Chat — Calls" } |
| 15 | XCTAssertNotNil(first) |
| 16 | presentation.open(call: call) |
| 17 | XCTAssertEqual(NSApp.windows.filter { $0.title == "Chat — Calls" }.count, 1) |
| 18 | presentation.close() |
| 19 | XCTAssertFalse(presentation.isOpen) |
| 20 | XCTAssertEqual(presentation.draft.text, "Keep this unsent message") |
| 21 | presentation.open(call: call) |
| 22 | XCTAssertTrue(presentation.isOpen) |
| 23 | XCTAssertEqual(presentation.draft.text, "Keep this unsent message") |
| 24 | presentation.close() |
| 25 | } |
| 26 | |
| 27 | @MainActor func testWindowCloseButtonUpdatesPresentationState() { |
| 28 | NSApplication.shared.setActivationPolicy(.prohibited) |
| 29 | let presentation = MacChatWindow() |
| 30 | presentation.open(call: Call(playAudio: false)) |
| 31 | let window = NSApp.windows.first { $0.title == "Chat — Calls" } |
| 32 | XCTAssertNotNil(window) |
| 33 | window?.performClose(nil) |
| 34 | XCTAssertFalse(presentation.isOpen) |
| 35 | } |
| 36 | } |
| 37 | |