oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1#if os(macOS)
2import Foundation
3import Testing
4import RastrilloApple
5@testable import DocsMac
6
7@MainActor @Test func windowsReuseDocumentsWithinAccountAndOriginOnly() {
8 let windows = DocsWindows()
9 let first = NativeHTTP(origin: URL(string: "https://first.invalid")!)
10 let second = NativeHTTP(origin: URL(string: "https://second.invalid")!)
11 let document: String = "same"
12 let id = windows.reserve(account: "a", document: document, title: "One", client: first)
13 #expect(windows.reserve(account: "a", document: document, title: "Renamed", client: first) == id)
14 #expect(windows.entries.count == 1)
15 #expect(!windows.canSignOut("a"))
16 #expect(windows.reserve(account: "b", document: document, title: "Other account", client: first) != id)
17 #expect(windows.reserve(account: "a", document: document, title: "Other server", client: second) != id)
18 #expect(windows.entries.count == 3)
19 windows.setOpen(id, false)
20 #expect(!windows.canSignOut("a"))
21 for entry in windows.entries where entry.account == "a" { windows.setOpen(entry.id, false) }
22 #expect(windows.canSignOut("a"))
23 windows.updateRecents([(document, "Current title")], account: "a", client: first)
24 #expect(windows.entries.first(where: { $0.id == id })?.title == "Current title")
25 #expect(windows.entries.first(where: { $0.id == id })?.isOpen == false)
26}
27@MainActor @Test func draftWindowsKeepAccountAndIdentityThroughAttachment() {
28 let windows = DocsWindows()
29 let client = NativeHTTP(origin: URL(string: "https://draft.invalid")!)
30 let first = windows.reserveDraft(account: "a", client: client)
31 let second = windows.reserveDraft(account: "a", client: client)
32 #expect(first != second)
33 #expect(!windows.canSignOut("a"))
34 windows.activeAccount = "b"
35 windows.attach(first, document: "created", title: "Renamed")
36 #expect(windows.entries.first(where: { $0.id == first })?.account == "a")
37 #expect(windows.entries.first(where: { $0.id == first })?.isDraft == false)
38 #expect(windows.reserve(account: "a", document: "created", title: "Renamed", client: client) == first)
39 windows.setOpen(second, false)
40 #expect(!windows.entries.contains(where: { $0.id == second }))
41 windows.setOpen(first, false)
42 #expect(windows.canSignOut("a"))
43}
44#endif
45