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

@@ -213,7 +213,7 @@ struct TravelEstimatorTests {
@Test("calculateTravelDays: zero hours returns departure day only")
func calculateTravelDays_zeroHours_returnsDepartureDay() {
let departure = Date()
let departure = TestClock.now
let days = TravelEstimator.calculateTravelDays(departure: departure, drivingHours: 0)
#expect(days.count == 1)
@@ -221,7 +221,7 @@ struct TravelEstimatorTests {
@Test("calculateTravelDays: 1-8 hours returns single day")
func calculateTravelDays_1to8Hours_returnsSingleDay() {
let departure = Date()
let departure = TestClock.now
for hours in [1.0, 4.0, 7.0, 8.0] {
let days = TravelEstimator.calculateTravelDays(departure: departure, drivingHours: hours)
@@ -231,7 +231,7 @@ struct TravelEstimatorTests {
@Test("calculateTravelDays: 8.01-16 hours returns two days")
func calculateTravelDays_8to16Hours_returnsTwoDays() {
let departure = Date()
let departure = TestClock.now
for hours in [8.01, 12.0, 16.0] {
let days = TravelEstimator.calculateTravelDays(departure: departure, drivingHours: hours)
@@ -241,7 +241,7 @@ struct TravelEstimatorTests {
@Test("calculateTravelDays: 16.01-24 hours returns three days")
func calculateTravelDays_16to24Hours_returnsThreeDays() {
let departure = Date()
let departure = TestClock.now
for hours in [16.01, 20.0, 24.0] {
let days = TravelEstimator.calculateTravelDays(departure: departure, drivingHours: hours)
@@ -251,9 +251,9 @@ struct TravelEstimatorTests {
@Test("calculateTravelDays: all dates are start of day")
func calculateTravelDays_allDatesAreStartOfDay() {
let calendar = Calendar.current
let calendar = TestClock.calendar
// Use a specific time that's not midnight
var components = calendar.dateComponents([.year, .month, .day], from: Date())
var components = calendar.dateComponents([.year, .month, .day], from: TestClock.now)
components.hour = 14
components.minute = 30
let departure = calendar.date(from: components)!
@@ -269,8 +269,8 @@ struct TravelEstimatorTests {
@Test("calculateTravelDays: consecutive days")
func calculateTravelDays_consecutiveDays() {
let calendar = Calendar.current
let departure = Date()
let calendar = TestClock.calendar
let departure = TestClock.now
let days = TravelEstimator.calculateTravelDays(departure: departure, drivingHours: 24)
#expect(days.count == 3)
@@ -414,21 +414,21 @@ struct TravelEstimatorTests {
@Test("Edge: calculateTravelDays with exactly 8 hours")
func edge_calculateTravelDays_exactly8Hours() {
let departure = Date()
let departure = TestClock.now
let days = TravelEstimator.calculateTravelDays(departure: departure, drivingHours: 8.0)
#expect(days.count == 1, "Exactly 8 hours should be 1 day")
}
@Test("Edge: calculateTravelDays just over 8 hours")
func edge_calculateTravelDays_justOver8Hours() {
let departure = Date()
let departure = TestClock.now
let days = TravelEstimator.calculateTravelDays(departure: departure, drivingHours: 8.001)
#expect(days.count == 2, "Just over 8 hours should be 2 days")
}
@Test("Edge: negative driving hours treated as minimum 1 day")
func edge_negativeDrivingHours() {
let departure = Date()
let departure = TestClock.now
let days = TravelEstimator.calculateTravelDays(departure: departure, drivingHours: -5)
#expect(days.count >= 1, "Negative hours should still return at least 1 day")
}
@@ -445,8 +445,8 @@ struct TravelEstimatorTests {
state: state,
coordinate: coordinate,
games: [],
arrivalDate: Date(),
departureDate: Date(),
arrivalDate: TestClock.now,
departureDate: TestClock.now,
location: LocationInput(name: city, coordinate: coordinate),
firstGameStart: nil
)