diff options
| author | Christian Cleberg <[email protected]> | 2026-03-18 19:32:07 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-03-18 19:32:07 -0500 |
| commit | 796c39d8ff08829bd695bc4e7497a147640eb79a (patch) | |
| tree | e1a0ed451c14db87d70145e9a63cd4e82d71158a /HutchTests/RepositoryListViewModelTests.swift | |
| parent | bb8fae4d1145266de4f5117a3b8c48f2ccacb0be (diff) | |
| download | hutch-796c39d8ff08829bd695bc4e7497a147640eb79a.tar.gz hutch-796c39d8ff08829bd695bc4e7497a147640eb79a.tar.bz2 hutch-796c39d8ff08829bd695bc4e7497a147640eb79a.zip | |
cache repository search results and gate remote refreshes
Diffstat (limited to 'HutchTests/RepositoryListViewModelTests.swift')
| -rw-r--r-- | HutchTests/RepositoryListViewModelTests.swift | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/HutchTests/RepositoryListViewModelTests.swift b/HutchTests/RepositoryListViewModelTests.swift new file mode 100644 index 0000000..d6e76bf --- /dev/null +++ b/HutchTests/RepositoryListViewModelTests.swift @@ -0,0 +1,50 @@ +import Foundation +import Testing +@testable import Hutch + +struct RepositoryListViewModelTests { + + @Test + @MainActor + func searchIndexRefreshRequiresMinimumQueryLength() { + #expect(RepositoryListViewModel.shouldRefreshSearchIndex(for: "ab") == false) + #expect(RepositoryListViewModel.shouldRefreshSearchIndex(for: "abc") == true) + #expect(RepositoryListViewModel.shouldRefreshSearchIndex(for: " abc ") == true) + } + + @Test + @MainActor + func filterRepositoriesMatchesNameAndDescriptionLocally() { + let repositories = [ + makeRepository(id: 1, service: .git, name: "Hutch", description: "SourceHut client"), + makeRepository(id: 2, service: .hg, name: "Mail", description: "patch queue"), + makeRepository(id: 3, service: .git, name: "Tree", description: nil) + ] + + let nameMatches = RepositoryListViewModel.filterRepositories(repositories, matching: "hut") + let descriptionMatches = RepositoryListViewModel.filterRepositories(repositories, matching: "patch") + + #expect(nameMatches.map(\.id) == [1]) + #expect(descriptionMatches.map(\.id) == [2]) + } + + @MainActor + private func makeRepository( + id: Int, + service: SRHTService, + name: String, + description: String? + ) -> RepositorySummary { + RepositorySummary( + id: id, + rid: "rid-\(id)", + service: service, + name: name, + description: description, + visibility: .public, + updated: Date(timeIntervalSince1970: TimeInterval(id)), + owner: Entity(canonicalName: "~owner"), + head: Reference(name: "main", target: nil) + ) + } +} |
