summaryrefslogtreecommitdiff
path: root/HutchTests
diff options
context:
space:
mode:
Diffstat (limited to 'HutchTests')
-rw-r--r--HutchTests/HutchIntentsTests.swift29
-rw-r--r--HutchTests/SystemStatusWidgetSnapshotTests.swift31
2 files changed, 60 insertions, 0 deletions
diff --git a/HutchTests/HutchIntentsTests.swift b/HutchTests/HutchIntentsTests.swift
index 94ecbf0..3cb7ad6 100644
--- a/HutchTests/HutchIntentsTests.swift
+++ b/HutchTests/HutchIntentsTests.swift
@@ -72,4 +72,33 @@ struct HutchIntentsTests {
#expect(loaded?.unreadInboxThreads == 5)
#expect(loaded?.assignedOpenTickets == 3)
}
+
+ @Test
+ func needsAttentionSnapshotsAreIsolatedPerAccount() {
+ let defaultsName = "HutchIntentsTests-builds-isolation-\(UUID().uuidString)"
+ let defaults = UserDefaults(suiteName: defaultsName)!
+ defer { defaults.removePersistentDomain(forName: defaultsName) }
+
+ let firstSnapshot = NeedsAttentionSnapshot(
+ unreadInboxThreads: 1,
+ assignedOpenTickets: 2,
+ failedBuilds: 3,
+ updatedAt: Date(timeIntervalSince1970: 100)
+ )
+ let secondSnapshot = NeedsAttentionSnapshot(
+ unreadInboxThreads: 8,
+ assignedOpenTickets: 5,
+ failedBuilds: 1,
+ updatedAt: Date(timeIntervalSince1970: 200)
+ )
+
+ NeedsAttentionSnapshotStore.save(firstSnapshot, accountID: "account-a", defaults: defaults)
+ NeedsAttentionSnapshotStore.save(secondSnapshot, accountID: "account-b", defaults: defaults)
+
+ #expect(NeedsAttentionSnapshotStore.load(accountID: "account-a", defaults: defaults)?.unreadInboxThreads == 1)
+ #expect(NeedsAttentionSnapshotStore.load(accountID: "account-b", defaults: defaults)?.unreadInboxThreads == 8)
+
+ ActiveAccountContextStore.save("account-a", defaults: defaults)
+ #expect(NeedsAttentionSnapshotStore.load(defaults: defaults)?.failedBuilds == 3)
+ }
}
diff --git a/HutchTests/SystemStatusWidgetSnapshotTests.swift b/HutchTests/SystemStatusWidgetSnapshotTests.swift
index ddb74b1..7121804 100644
--- a/HutchTests/SystemStatusWidgetSnapshotTests.swift
+++ b/HutchTests/SystemStatusWidgetSnapshotTests.swift
@@ -65,6 +65,37 @@ struct SystemStatusWidgetSnapshotTests {
}
@Test
+ func snapshotsAreIsolatedPerAccount() {
+ let defaultsName = "SystemStatusWidgetSnapshotTests-isolation-\(UUID().uuidString)"
+ let defaults = UserDefaults(suiteName: defaultsName)!
+ defer { defaults.removePersistentDomain(forName: defaultsName) }
+
+ let firstSnapshot = SystemStatusWidgetSnapshot(
+ services: [.init(id: "git", name: "git.sr.ht", status: "Operational", requiresAttention: false)],
+ hasDisruption: false,
+ overallStatusText: "All monitored services operational",
+ bannerSummary: "",
+ updatedAt: Date(timeIntervalSince1970: 100)
+ )
+ let secondSnapshot = SystemStatusWidgetSnapshot(
+ services: [.init(id: "builds", name: "builds.sr.ht", status: "Degraded", requiresAttention: true)],
+ hasDisruption: true,
+ overallStatusText: "Experiencing disruptions",
+ bannerSummary: "builds.sr.ht disrupted",
+ updatedAt: Date(timeIntervalSince1970: 200)
+ )
+
+ SystemStatusWidgetSnapshotStore.save(firstSnapshot, accountID: "account-a", defaults: defaults)
+ SystemStatusWidgetSnapshotStore.save(secondSnapshot, accountID: "account-b", defaults: defaults)
+
+ #expect(SystemStatusWidgetSnapshotStore.load(accountID: "account-a", defaults: defaults)?.services.first?.name == "git.sr.ht")
+ #expect(SystemStatusWidgetSnapshotStore.load(accountID: "account-b", defaults: defaults)?.services.first?.name == "builds.sr.ht")
+
+ ActiveAccountContextStore.save("account-b", defaults: defaults)
+ #expect(SystemStatusWidgetSnapshotStore.load(defaults: defaults)?.bannerSummary == "builds.sr.ht disrupted")
+ }
+
+ @Test
func unavailableSnapshotHasEmptyServices() {
let snapshot = SystemStatusWidgetSnapshot.unavailable
#expect(snapshot.services.isEmpty)