summaryrefslogtreecommitdiff
path: root/HutchTests
diff options
context:
space:
mode:
Diffstat (limited to 'HutchTests')
-rw-r--r--HutchTests/HomeViewModelTests.swift52
-rw-r--r--HutchTests/InboxViewModelTests.swift55
2 files changed, 55 insertions, 52 deletions
diff --git a/HutchTests/HomeViewModelTests.swift b/HutchTests/HomeViewModelTests.swift
index fe4229f..e4f6d9a 100644
--- a/HutchTests/HomeViewModelTests.swift
+++ b/HutchTests/HomeViewModelTests.swift
@@ -90,6 +90,58 @@ struct HomeViewModelTests {
}
@Test
+ func deduplicateInboxThreadsCollapsesMessagesIntoOneThreadSummary() {
+ let list = InboxMailingListReference(
+ id: 1,
+ rid: "list",
+ name: "hutch-devel",
+ owner: Entity(canonicalName: "~owner")
+ )
+ let first = InboxThreadSummary(
+ rootEmailID: 10,
+ rootMessageID: "message-1",
+ threadRootEmailIDs: [10],
+ threadRootMessageIDs: ["message-1"],
+ listID: list.id,
+ listRID: list.rid,
+ listName: list.name,
+ listOwner: list.owner,
+ subject: "Re: [PATCH] add search",
+ latestSender: Entity(canonicalName: "~alice"),
+ lastActivityAt: Date(timeIntervalSince1970: 100),
+ messageCount: 1,
+ repo: "hutch",
+ containsPatch: true,
+ isUnread: true
+ )
+ let second = InboxThreadSummary(
+ rootEmailID: 11,
+ rootMessageID: "message-2",
+ threadRootEmailIDs: [11],
+ threadRootMessageIDs: ["message-2"],
+ listID: list.id,
+ listRID: list.rid,
+ listName: list.name,
+ listOwner: list.owner,
+ subject: "[PATCH] add search",
+ latestSender: Entity(canonicalName: "~bob"),
+ lastActivityAt: Date(timeIntervalSince1970: 200),
+ messageCount: 2,
+ repo: "hutch",
+ containsPatch: true,
+ isUnread: true
+ )
+
+ let deduplicated = HomeViewModel.deduplicateInboxThreads([first, second])
+
+ #expect(deduplicated.count == 1)
+ #expect(deduplicated[0].rootEmailID == 11)
+ #expect(deduplicated[0].threadRootEmailIDs == [10, 11])
+ #expect(deduplicated[0].threadRootMessageIDs == ["message-1", "message-2"])
+ #expect(deduplicated[0].messageCount == 2)
+ }
+
+ @Test
func matchesCurrentUserAssigneeNormalizesCanonicalNameAndUsername() {
let currentUser = User(
id: 42,
diff --git a/HutchTests/InboxViewModelTests.swift b/HutchTests/InboxViewModelTests.swift
index a5a0428..7bfc199 100644
--- a/HutchTests/InboxViewModelTests.swift
+++ b/HutchTests/InboxViewModelTests.swift
@@ -6,9 +6,9 @@ struct InboxViewModelTests {
@Test
func derivesRepositoryNameFromCommonPatchListSuffixes() {
- #expect(InboxViewModel.deriveRepositoryName(from: "hut-devel") == "hut")
- #expect(InboxViewModel.deriveRepositoryName(from: "git.patches") == "git")
- #expect(InboxViewModel.deriveRepositoryName(from: "discuss") == nil)
+ #expect(InboxThreadUtilities.deriveRepositoryName(from: "hut-devel") == "hut")
+ #expect(InboxThreadUtilities.deriveRepositoryName(from: "git.patches") == "git")
+ #expect(InboxThreadUtilities.deriveRepositoryName(from: "discuss") == nil)
}
@Test
@@ -166,55 +166,6 @@ struct InboxViewModelTests {
}
@Test
- func inboxFilterSeparatesPatchThreadsFromDiscussionThreads() {
- let baseList = InboxMailingListReference(
- id: 1,
- rid: "list",
- name: "hutch-devel",
- owner: Entity(canonicalName: "~owner")
- )
- let patchThread = InboxThreadSummary(
- rootEmailID: 10,
- rootMessageID: "message-1",
- threadRootEmailIDs: [10],
- threadRootMessageIDs: ["message-1"],
- listID: baseList.id,
- listRID: baseList.rid,
- listName: baseList.name,
- listOwner: baseList.owner,
- subject: "[PATCH] add search",
- latestSender: Entity(canonicalName: "~alice"),
- lastActivityAt: Date(timeIntervalSince1970: 100),
- messageCount: 1,
- repo: "hutch",
- containsPatch: true,
- isUnread: true
- )
- let discussionThread = InboxThreadSummary(
- rootEmailID: 11,
- rootMessageID: "message-2",
- threadRootEmailIDs: [11],
- threadRootMessageIDs: ["message-2"],
- listID: baseList.id,
- listRID: baseList.rid,
- listName: baseList.name,
- listOwner: baseList.owner,
- subject: "release planning",
- latestSender: Entity(canonicalName: "~bob"),
- lastActivityAt: Date(timeIntervalSince1970: 200),
- messageCount: 2,
- repo: "hutch",
- containsPatch: false,
- isUnread: true
- )
-
- let threads = [patchThread, discussionThread]
-
- #expect(InboxViewModel.filterThreads(threads, filter: .patches).map(\.rootEmailID) == [10])
- #expect(InboxViewModel.filterThreads(threads, filter: .discussions).map(\.rootEmailID) == [11])
- }
-
- @Test
func segmentsPatchBodyAndTreatsSignatureAsPlainText() {
let body = """
From: Christian Cleberg <[email protected]>