Stabilize unit and UI tests for SportsTime
This commit is contained in:
@@ -26,7 +26,7 @@ final class ItineraryReorderingLogicTests: XCTestCase {
|
||||
for element in elements {
|
||||
switch element {
|
||||
case .day(let num):
|
||||
let date = Calendar.current.date(byAdding: .day, value: num - 1, to: testDate)!
|
||||
let date = TestClock.calendar.date(byAdding: .day, value: num - 1, to: testDate)!
|
||||
items.append(.dayHeader(dayNumber: num, date: date))
|
||||
|
||||
case .game(let city, let day):
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -249,13 +249,13 @@ final class ItinerarySemanticTravelTests: XCTestCase {
|
||||
/// For each proposedRow, simulate → compute (day, sortOrder) → constraints.isValidPosition must match.
|
||||
func test_E_computeValidDestinationRows_matchesConstraintsValidation() {
|
||||
let gameA = H.makeRichGame(city: "CityA", hour: 19, baseDate: testDate)
|
||||
let gameBDate = Calendar.current.date(byAdding: .day, value: 3, to: testDate)!
|
||||
let gameBDate = TestClock.calendar.date(byAdding: .day, value: 3, to: testDate)!
|
||||
let gameB = H.makeRichGame(city: "CityB", hour: 19, baseDate: gameBDate)
|
||||
let travel = H.makeTravelSegment(from: "CityA", to: "CityB")
|
||||
|
||||
let day2Date = Calendar.current.date(byAdding: .day, value: 1, to: testDate)!
|
||||
let day3Date = Calendar.current.date(byAdding: .day, value: 2, to: testDate)!
|
||||
let day4Date = Calendar.current.date(byAdding: .day, value: 3, to: testDate)!
|
||||
let day2Date = TestClock.calendar.date(byAdding: .day, value: 1, to: testDate)!
|
||||
let day3Date = TestClock.calendar.date(byAdding: .day, value: 2, to: testDate)!
|
||||
let day4Date = TestClock.calendar.date(byAdding: .day, value: 3, to: testDate)!
|
||||
|
||||
let items: [ItineraryRowItem] = [
|
||||
.dayHeader(dayNumber: 1, date: testDate),
|
||||
@@ -316,7 +316,7 @@ final class ItinerarySemanticTravelTests: XCTestCase {
|
||||
func test_E_customItemValidDestinations_matchesConstraints() {
|
||||
let game = H.makeRichGame(city: "Detroit", hour: 19, baseDate: testDate)
|
||||
let customItem = H.makeCustomItem(day: 1, sortOrder: 2.0, title: "Lunch")
|
||||
let day2Date = Calendar.current.date(byAdding: .day, value: 1, to: testDate)!
|
||||
let day2Date = TestClock.calendar.date(byAdding: .day, value: 1, to: testDate)!
|
||||
|
||||
let items: [ItineraryRowItem] = [
|
||||
.dayHeader(dayNumber: 1, date: testDate),
|
||||
|
||||
@@ -11,7 +11,7 @@ import Foundation
|
||||
/// Shared test fixtures for itinerary tests
|
||||
enum ItineraryTestHelpers {
|
||||
static let testTripId = UUID()
|
||||
static let testDate = Date()
|
||||
static let testDate = TestClock.now
|
||||
|
||||
// MARK: - Day Helpers
|
||||
|
||||
@@ -20,7 +20,7 @@ enum ItineraryTestHelpers {
|
||||
ItineraryDayData(
|
||||
id: i + 1,
|
||||
dayNumber: i + 1,
|
||||
date: Calendar.current.date(byAdding: .day, value: i, to: baseDate)!,
|
||||
date: TestClock.calendar.date(byAdding: .day, value: i, to: baseDate)!,
|
||||
games: [],
|
||||
items: [],
|
||||
travelBefore: nil
|
||||
@@ -29,7 +29,7 @@ enum ItineraryTestHelpers {
|
||||
}
|
||||
|
||||
static func dayAfter(_ date: Date) -> Date {
|
||||
Calendar.current.date(byAdding: .day, value: 1, to: date)!
|
||||
TestClock.calendar.date(byAdding: .day, value: 1, to: date)!
|
||||
}
|
||||
|
||||
// MARK: - Travel Helpers
|
||||
@@ -56,9 +56,9 @@ enum ItineraryTestHelpers {
|
||||
// MARK: - Game Helpers
|
||||
|
||||
static func makeRichGame(city: String, hour: Int, baseDate: Date = testDate) -> RichGame {
|
||||
var dateComponents = Calendar.current.dateComponents([.year, .month, .day], from: baseDate)
|
||||
var dateComponents = TestClock.calendar.dateComponents([.year, .month, .day], from: baseDate)
|
||||
dateComponents.hour = hour
|
||||
let gameTime = Calendar.current.date(from: dateComponents)!
|
||||
let gameTime = TestClock.calendar.date(from: dateComponents)!
|
||||
|
||||
let game = Game(
|
||||
id: "game-\(city)-\(UUID().uuidString.prefix(4))",
|
||||
|
||||
@@ -14,7 +14,7 @@ final class TravelPlacementTests: XCTestCase {
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private let calendar = Calendar.current
|
||||
private let calendar = TestClock.calendar
|
||||
|
||||
/// Create a date for May 2026 at a given day number.
|
||||
private func may(_ day: Int) -> Date {
|
||||
|
||||
Reference in New Issue
Block a user