#if os(macOS) import Foundation import Testing import RastrilloApple @testable import DocsMac @MainActor @Test func windowsReuseDocumentsWithinAccountAndOriginOnly() { let windows = DocsWindows() let first = NativeHTTP(origin: URL(string: "https://first.invalid")!) let second = NativeHTTP(origin: URL(string: "https://second.invalid")!) let document: String = "same" let id = windows.reserve(account: "a", document: document, title: "One", client: first) #expect(windows.reserve(account: "a", document: document, title: "Renamed", client: first) == id) #expect(windows.entries.count == 1) #expect(!windows.canSignOut("a")) #expect(windows.reserve(account: "b", document: document, title: "Other account", client: first) != id) #expect(windows.reserve(account: "a", document: document, title: "Other server", client: second) != id) #expect(windows.entries.count == 3) windows.setOpen(id, false) #expect(!windows.canSignOut("a")) for entry in windows.entries where entry.account == "a" { windows.setOpen(entry.id, false) } #expect(windows.canSignOut("a")) windows.updateRecents([(document, "Current title")], account: "a", client: first) #expect(windows.entries.first(where: { $0.id == id })?.title == "Current title") #expect(windows.entries.first(where: { $0.id == id })?.isOpen == false) } @MainActor @Test func draftWindowsKeepAccountAndIdentityThroughAttachment() { let windows = DocsWindows() let client = NativeHTTP(origin: URL(string: "https://draft.invalid")!) let first = windows.reserveDraft(account: "a", client: client) let second = windows.reserveDraft(account: "a", client: client) #expect(first != second) #expect(!windows.canSignOut("a")) windows.activeAccount = "b" windows.attach(first, document: "created", title: "Renamed") #expect(windows.entries.first(where: { $0.id == first })?.account == "a") #expect(windows.entries.first(where: { $0.id == first })?.isDraft == false) #expect(windows.reserve(account: "a", document: "created", title: "Renamed", client: client) == first) windows.setOpen(second, false) #expect(!windows.entries.contains(where: { $0.id == second })) windows.setOpen(first, false) #expect(windows.canSignOut("a")) } #endif