Stabilize unit and UI tests for SportsTime

This commit is contained in:
treyt
2026-02-18 13:00:15 -06:00
parent 1488be7c1f
commit 20ac1a7e59
49 changed files with 432 additions and 325 deletions

View File

@@ -14,15 +14,15 @@ struct ItinerarySectionBuilderTests {
// MARK: - Helpers
private func makeTripDays(count: Int, startDate: Date = Date()) -> [Date] {
private func makeTripDays(count: Int, startDate: Date = TestClock.now) -> [Date] {
(0..<count).map {
Calendar.current.date(byAdding: .day, value: $0, to: Calendar.current.startOfDay(for: startDate))!
TestClock.calendar.date(byAdding: .day, value: $0, to: TestClock.calendar.startOfDay(for: startDate))!
}
}
private func makeTrip(
cities: [String] = ["New York", "Boston"],
startDate: Date = Date(),
startDate: Date = TestClock.now,
daysPerStop: Int = 1,
gameIds: [[String]] = []
) -> (Trip, [Date]) {
@@ -50,7 +50,7 @@ struct ItinerarySectionBuilderTests {
@Test("builds one section per day")
func buildsSectionsForEachDay() {
let startDate = Calendar.current.startOfDay(for: Date())
let startDate = TestClock.calendar.startOfDay(for: TestClock.now)
let (trip, days) = makeTrip(cities: ["New York", "Boston", "Philadelphia"], startDate: startDate)
let sections = ItinerarySectionBuilder.build(
@@ -72,7 +72,7 @@ struct ItinerarySectionBuilderTests {
@Test("games filtered correctly by date")
func gamesOnFiltersCorrectly() {
let startDate = Calendar.current.startOfDay(for: Date())
let startDate = TestClock.calendar.startOfDay(for: TestClock.now)
let gameDate = startDate
let game = TestFixtures.game(sport: .mlb, city: "New York", dateTime: gameDate)
let richGame = TestFixtures.richGame(game: game, homeCity: "New York")
@@ -108,7 +108,7 @@ struct ItinerarySectionBuilderTests {
@Test("travel segments appear in sections")
func travelSegmentsAppear() {
let startDate = Calendar.current.startOfDay(for: Date())
let startDate = TestClock.calendar.startOfDay(for: TestClock.now)
let travel = TestFixtures.travelSegment(from: "New York", to: "Boston")
let (baseTrip, days) = makeTrip(
cities: ["New York", "Boston"],
@@ -153,7 +153,7 @@ struct ItinerarySectionBuilderTests {
@Test("custom items included when allowCustomItems is true")
func customItemsIncluded() {
let startDate = Calendar.current.startOfDay(for: Date())
let startDate = TestClock.calendar.startOfDay(for: TestClock.now)
let (trip, days) = makeTrip(cities: ["New York"], startDate: startDate)
let customItem = ItineraryItem(