diff options
| author | Christian Cleberg <[email protected]> | 2026-03-22 20:42:45 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-03-22 20:42:45 -0500 |
| commit | 1f8b7a23529462c3c332753d33810b5c9f692bbc (patch) | |
| tree | 17526dae77a7579b270e6b9cca6224c9020f772d /HutchTests | |
| parent | e03791d6c15ee0caac033d1b1b390c5d65a69d57 (diff) | |
| download | hutch-1f8b7a23529462c3c332753d33810b5c9f692bbc.tar.gz hutch-1f8b7a23529462c3c332753d33810b5c9f692bbc.tar.bz2 hutch-1f8b7a23529462c3c332753d33810b5c9f692bbc.zip | |
feat: add search to builds, trackers, tickets, pastes, mailing lists, and inbox
Diffstat (limited to 'HutchTests')
| -rw-r--r-- | HutchTests/BuildListViewModelTests.swift | 55 | ||||
| -rw-r--r-- | HutchTests/InboxViewModelTests.swift | 52 | ||||
| -rw-r--r-- | HutchTests/TrackerListViewModelTests.swift | 58 |
3 files changed, 165 insertions, 0 deletions
diff --git a/HutchTests/BuildListViewModelTests.swift b/HutchTests/BuildListViewModelTests.swift new file mode 100644 index 0000000..a5c2483 --- /dev/null +++ b/HutchTests/BuildListViewModelTests.swift @@ -0,0 +1,55 @@ +import Foundation +import Testing +@testable import Hutch + +struct BuildListViewModelTests { + + @Test + func filteredJobsReturnsAllWhenSearchTextIsEmpty() { + let jobs = [makeJob(id: 1, tags: ["ci"]), makeJob(id: 2, tags: [])] + let filtered = filterJobs(jobs, query: "") + + #expect(filtered.count == 2) + } + + @Test + func filteredJobsMatchesByTag() { + let jobs = [makeJob(id: 1, tags: ["ci", "deploy"]), makeJob(id: 2, tags: ["lint"])] + let filtered = filterJobs(jobs, query: "deploy") + + #expect(filtered.map(\.id) == [1]) + } + + @Test + func filteredJobsMatchesByJobId() { + let jobs = [makeJob(id: 42, tags: []), makeJob(id: 99, tags: [])] + let filtered = filterJobs(jobs, query: "42") + + #expect(filtered.map(\.id) == [42]) + } + + private func filterJobs(_ jobs: [JobSummary], query: String) -> [JobSummary] { + let q = query.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() + guard !q.isEmpty else { return jobs } + return jobs.filter { + String($0.id).contains(q) || + $0.tags.contains { $0.lowercased().contains(q) } || + ($0.note?.lowercased().contains(q) == true) || + ($0.image?.lowercased().contains(q) == true) + } + } + + private func makeJob(id: Int, tags: [String]) -> JobSummary { + JobSummary( + id: id, + created: Date(), + updated: Date(), + status: .success, + note: nil, + tags: tags, + visibility: nil, + image: nil, + tasks: [] + ) + } +} diff --git a/HutchTests/InboxViewModelTests.swift b/HutchTests/InboxViewModelTests.swift index b202d03..597bbc2 100644 --- a/HutchTests/InboxViewModelTests.swift +++ b/HutchTests/InboxViewModelTests.swift @@ -114,6 +114,58 @@ struct InboxViewModelTests { } @Test + func mailingListThreadFilterMatchesSubjectAndSender() { + let baseList = InboxMailingListReference( + id: 1, + rid: "list", + name: "hutch-devel", + owner: Entity(canonicalName: "~owner") + ) + let threads = [ + InboxThreadSummary( + rootEmailID: 10, + rootMessageID: "message-1", + threadRootEmailIDs: [10], + threadRootMessageIDs: ["message-1"], + listID: baseList.id, + listRID: baseList.rid, + listName: baseList.name, + listOwner: baseList.owner, + subject: "Re: [PATCH] add search", + latestSender: Entity(canonicalName: "~alice"), + lastActivityAt: Date(timeIntervalSince1970: 100), + messageCount: 1, + repo: "hutch", + containsPatch: true, + isUnread: true + ), + 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 subjectMatches = MailingListDetailViewModel.filterThreads(threads, matching: "search") + let senderMatches = MailingListDetailViewModel.filterThreads(threads, matching: "~bob") + + #expect(subjectMatches.map(\.rootEmailID) == [10]) + #expect(senderMatches.map(\.rootEmailID) == [11]) + } + + @Test func segmentsPatchBodyAndTreatsSignatureAsPlainText() { let body = """ From: Christian Cleberg <[email protected]> diff --git a/HutchTests/TrackerListViewModelTests.swift b/HutchTests/TrackerListViewModelTests.swift index 1caedea..7e927af 100644 --- a/HutchTests/TrackerListViewModelTests.swift +++ b/HutchTests/TrackerListViewModelTests.swift @@ -13,4 +13,62 @@ struct TrackerListViewModelTests { #expect(error.localizedDescription == "GraphQL error: A tracker named bugs already exists") } + + @Test + func filteredTrackersReturnsAllWhenSearchTextIsEmpty() { + let trackers = [ + makeTracker(id: 1, name: "bugs", description: "Bug tracker", owner: "~owner"), + makeTracker(id: 2, name: "ideas", description: nil, owner: "~team") + ] + + let filtered = filterTrackers(trackers, query: "") + + #expect(filtered.count == 2) + } + + @Test + func filteredTrackersMatchesDescription() { + let trackers = [ + makeTracker(id: 1, name: "bugs", description: "Production incidents", owner: "~owner"), + makeTracker(id: 2, name: "ideas", description: "Feature requests", owner: "~team") + ] + + let filtered = filterTrackers(trackers, query: "incident") + + #expect(filtered.map(\.id) == [1]) + } + + @Test + func filteredTrackersMatchesOwner() { + let trackers = [ + makeTracker(id: 1, name: "bugs", description: nil, owner: "~owner"), + makeTracker(id: 2, name: "ideas", description: nil, owner: "~team") + ] + + let filtered = filterTrackers(trackers, query: "~team") + + #expect(filtered.map(\.id) == [2]) + } + + private func filterTrackers(_ trackers: [TrackerSummary], query: String) -> [TrackerSummary] { + let q = query.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() + guard !q.isEmpty else { return trackers } + return trackers.filter { + $0.name.lowercased().contains(q) || + ($0.description?.lowercased().contains(q) == true) || + $0.owner.canonicalName.lowercased().contains(q) + } + } + + private func makeTracker(id: Int, name: String, description: String?, owner: String) -> TrackerSummary { + TrackerSummary( + id: id, + rid: "rid-\(id)", + name: name, + description: description, + visibility: .public, + updated: Date(), + owner: Entity(canonicalName: owner) + ) + } } |
