diff options
| author | Christian Cleberg <[email protected]> | 2026-03-18 20:23:58 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-03-18 20:23:58 -0500 |
| commit | c41cd437acde4e4f4c0781cebd4d5f4bf9517bb9 (patch) | |
| tree | 28bf13b89e36774720d015a26a8979b567ad0be9 /HutchTests/RepositoryListViewModelTests.swift | |
| parent | 1745311950fd68ad81957b3ba64f8566cd86ce19 (diff) | |
| parent | 4dd920558a1c7174c0e9a5b872325df36e363516 (diff) | |
| download | hutch-c41cd437acde4e4f4c0781cebd4d5f4bf9517bb9.tar.gz hutch-c41cd437acde4e4f4c0781cebd4d5f4bf9517bb9.tar.bz2 hutch-c41cd437acde4e4f4c0781cebd4d5f4bf9517bb9.zip | |
v1.2: Merge branch 'dev'
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) + ) + } +} |
