diff options
| author | Christian Cleberg <[email protected]> | 2026-04-12 22:52:33 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-12 22:52:33 -0500 |
| commit | 72f860e0e171f6aac4e7d896e7a571147dbcb5c5 (patch) | |
| tree | c62c9c9325292f65e6f72372a38b35760cc937b1 /HutchTests/ScopedSearchHistoryStoreTests.swift | |
| parent | 576bb6c2432a15f5138771c06019b55fd2244e15 (diff) | |
| download | hutch-72f860e0e171f6aac4e7d896e7a571147dbcb5c5.tar.gz hutch-72f860e0e171f6aac4e7d896e7a571147dbcb5c5.tar.bz2 hutch-72f860e0e171f6aac4e7d896e7a571147dbcb5c5.zip | |
feat: add search and recent queries
Implements: https://todo.sr.ht/~ccleberg/hutch/47
Implements: https://todo.sr.ht/~ccleberg/hutch/48
Diffstat (limited to 'HutchTests/ScopedSearchHistoryStoreTests.swift')
| -rw-r--r-- | HutchTests/ScopedSearchHistoryStoreTests.swift | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/HutchTests/ScopedSearchHistoryStoreTests.swift b/HutchTests/ScopedSearchHistoryStoreTests.swift new file mode 100644 index 0000000..856d69f --- /dev/null +++ b/HutchTests/ScopedSearchHistoryStoreTests.swift @@ -0,0 +1,54 @@ +import Foundation +import Testing +@testable import Hutch + +struct ScopedSearchHistoryStoreTests { + + @Test + func recordsMostRecentUniqueSearchPerScopeFirst() { + let suiteName = "ScopedSearchHistoryStoreTests-\(UUID().uuidString)" + let defaults = UserDefaults(suiteName: suiteName)! + defer { defaults.removePersistentDomain(forName: suiteName) } + + ScopedSearchHistoryStore.record( + query: "hutch", + scopeID: "repositories", + defaults: defaults, + now: Date(timeIntervalSince1970: 100) + ) + ScopedSearchHistoryStore.record( + query: "running", + scopeID: "builds", + defaults: defaults, + now: Date(timeIntervalSince1970: 200) + ) + ScopedSearchHistoryStore.record( + query: "Hutch", + scopeID: "repositories", + defaults: defaults, + now: Date(timeIntervalSince1970: 300) + ) + + let repositoryHistory = ScopedSearchHistoryStore.load(scopeID: "repositories", defaults: defaults) + let buildHistory = ScopedSearchHistoryStore.load(scopeID: "builds", defaults: defaults) + + #expect(repositoryHistory.map(\.query) == ["Hutch"]) + #expect(repositoryHistory.first?.createdAt == Date(timeIntervalSince1970: 300)) + #expect(buildHistory.map(\.query) == ["running"]) + } + + @Test + func clearsOnlyRequestedScope() { + let suiteName = "ScopedSearchHistoryStoreTests-\(UUID().uuidString)" + let defaults = UserDefaults(suiteName: suiteName)! + defer { defaults.removePersistentDomain(forName: suiteName) } + + ScopedSearchHistoryStore.record(query: "repo", scopeID: "repositories", defaults: defaults) + ScopedSearchHistoryStore.record(query: "ticket", scopeID: "tickets.rid", defaults: defaults) + + ScopedSearchHistoryStore.clear(scopeID: "repositories", defaults: defaults) + + #expect(ScopedSearchHistoryStore.load(scopeID: "repositories", defaults: defaults).isEmpty) + #expect(ScopedSearchHistoryStore.load(scopeID: "tickets.rid", defaults: defaults).map(\.query) == ["ticket"]) + } +} |
