summaryrefslogtreecommitdiff
path: root/HutchTests/HomeViewModelTests.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-20 12:42:09 -0500
committerChristian Cleberg <[email protected]>2026-04-20 12:42:09 -0500
commit454c459394437f346a2d08d59a5504c0f6ec299f (patch)
treedd7dc1521aec859cb7b093c922ea61ea5efac7a9 /HutchTests/HomeViewModelTests.swift
parent32c0e55b0713a15094c1640e7af70e0ed19d78d6 (diff)
downloadhutch-454c459394437f346a2d08d59a5504c0f6ec299f.tar.gz
hutch-454c459394437f346a2d08d59a5504c0f6ec299f.tar.bz2
hutch-454c459394437f346a2d08d59a5504c0f6ec299f.zip
feat: user-defined time period for recent builds card
- limit Home failed-build counts to a configurable lookback window and add the setting under Behavior. - make the Recent and Builds rows fully tappable across the entire cell and add coverage for the new failed-build filtering. Fixes: https://todo.sr.ht/~ccleberg/hutch/67
Diffstat (limited to 'HutchTests/HomeViewModelTests.swift')
-rw-r--r--HutchTests/HomeViewModelTests.swift71
1 files changed, 71 insertions, 0 deletions
diff --git a/HutchTests/HomeViewModelTests.swift b/HutchTests/HomeViewModelTests.swift
index 72f2e71..fe4229f 100644
--- a/HutchTests/HomeViewModelTests.swift
+++ b/HutchTests/HomeViewModelTests.swift
@@ -19,6 +19,77 @@ struct HomeViewModelTests {
}
@Test
+ func failedBuildsWithinLookbackExcludeOlderFailures() {
+ let now = Date(timeIntervalSince1970: 60 * 60 * 24 * 20)
+ let recentFailure = HomeBuildItem(
+ job: JobSummary(
+ id: 1,
+ created: now.addingTimeInterval(-(60 * 60 * 24)),
+ updated: now.addingTimeInterval(-(60 * 60 * 24)),
+ status: .failed,
+ note: nil,
+ tags: [],
+ visibility: nil,
+ image: nil,
+ tasks: []
+ ),
+ repositoryName: nil,
+ repositoryOwner: nil
+ )
+ let oldFailure = HomeBuildItem(
+ job: JobSummary(
+ id: 2,
+ created: now.addingTimeInterval(-(60 * 60 * 24 * 10)),
+ updated: now.addingTimeInterval(-(60 * 60 * 24 * 10)),
+ status: .timeout,
+ note: nil,
+ tags: [],
+ visibility: nil,
+ image: nil,
+ tasks: []
+ ),
+ repositoryName: nil,
+ repositoryOwner: nil
+ )
+ let recentSuccess = HomeBuildItem(
+ job: JobSummary(
+ id: 3,
+ created: now.addingTimeInterval(-(60 * 60 * 24)),
+ updated: now.addingTimeInterval(-(60 * 60 * 24)),
+ status: .success,
+ note: nil,
+ tags: [],
+ visibility: nil,
+ image: nil,
+ tasks: []
+ ),
+ repositoryName: nil,
+ repositoryOwner: nil
+ )
+
+ let filtered = HomeViewModel.failedBuilds(
+ in: [recentFailure, oldFailure, recentSuccess],
+ lookbackDays: 7,
+ now: now,
+ calendar: Calendar(identifier: .gregorian)
+ )
+
+ #expect(filtered.map(\.job.id) == [1])
+ }
+
+ @Test
+ func failedBuildLookbackDaysFallsBackToDefaultWhenUnsetOrInvalid() {
+ let defaults = UserDefaults(suiteName: #function)!
+ defaults.removePersistentDomain(forName: #function)
+
+ #expect(HomeViewModel.failedBuildLookbackDays(defaults: defaults) == HomeViewModel.defaultFailedBuildLookbackDays)
+
+ defaults.set(99, forKey: AppStorageKeys.homeFailedBuildLookbackDays)
+
+ #expect(HomeViewModel.failedBuildLookbackDays(defaults: defaults) == HomeViewModel.defaultFailedBuildLookbackDays)
+ }
+
+ @Test
func matchesCurrentUserAssigneeNormalizesCanonicalNameAndUsername() {
let currentUser = User(
id: 42,