Stabilize unit and UI tests for SportsTime
This commit is contained in:
@@ -33,7 +33,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("stayDuration: same day arrival and departure returns 1")
|
||||
func stayDuration_sameDay() {
|
||||
let calendar = Calendar.current
|
||||
let calendar = TestClock.calendar
|
||||
let arrivalDate = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
|
||||
let departureDate = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
|
||||
|
||||
@@ -44,7 +44,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("stayDuration: 2-day stay returns 2")
|
||||
func stayDuration_twoDays() {
|
||||
let calendar = Calendar.current
|
||||
let calendar = TestClock.calendar
|
||||
let arrivalDate = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
|
||||
let departureDate = calendar.date(from: DateComponents(year: 2026, month: 6, day: 16))!
|
||||
|
||||
@@ -55,7 +55,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("stayDuration: week-long stay")
|
||||
func stayDuration_weekLong() {
|
||||
let calendar = Calendar.current
|
||||
let calendar = TestClock.calendar
|
||||
let arrivalDate = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
|
||||
let departureDate = calendar.date(from: DateComponents(year: 2026, month: 6, day: 22))!
|
||||
|
||||
@@ -66,7 +66,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("stayDuration: minimum is 1 even if dates are reversed")
|
||||
func stayDuration_minimumIsOne() {
|
||||
let calendar = Calendar.current
|
||||
let calendar = TestClock.calendar
|
||||
let arrivalDate = calendar.date(from: DateComponents(year: 2026, month: 6, day: 20))!
|
||||
let departureDate = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
|
||||
|
||||
@@ -79,7 +79,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("hasGames: true when games array is non-empty")
|
||||
func hasGames_true() {
|
||||
let now = Date()
|
||||
let now = TestClock.now
|
||||
let stop = makeStop(arrivalDate: now, departureDate: now, games: ["game1", "game2"])
|
||||
|
||||
#expect(stop.hasGames == true)
|
||||
@@ -87,7 +87,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("hasGames: false when games array is empty")
|
||||
func hasGames_false() {
|
||||
let now = Date()
|
||||
let now = TestClock.now
|
||||
let stop = makeStop(arrivalDate: now, departureDate: now, games: [])
|
||||
|
||||
#expect(stop.hasGames == false)
|
||||
@@ -97,7 +97,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("formattedDateRange: single date for 1-day stay")
|
||||
func formattedDateRange_singleDay() {
|
||||
let calendar = Calendar.current
|
||||
let calendar = TestClock.calendar
|
||||
let date = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
|
||||
|
||||
let stop = makeStop(arrivalDate: date, departureDate: date)
|
||||
@@ -108,7 +108,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("formattedDateRange: range for multi-day stay")
|
||||
func formattedDateRange_multiDay() {
|
||||
let calendar = Calendar.current
|
||||
let calendar = TestClock.calendar
|
||||
let arrival = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
|
||||
let departure = calendar.date(from: DateComponents(year: 2026, month: 6, day: 18))!
|
||||
|
||||
@@ -126,8 +126,8 @@ struct TripStopTests {
|
||||
stopNumber: 1,
|
||||
city: "Boston",
|
||||
state: "MA",
|
||||
arrivalDate: Date(),
|
||||
departureDate: Date()
|
||||
arrivalDate: TestClock.now,
|
||||
departureDate: TestClock.now
|
||||
)
|
||||
|
||||
#expect(stop.locationDescription == "Boston, MA")
|
||||
@@ -137,7 +137,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("Invariant: stayDuration >= 1")
|
||||
func invariant_stayDurationAtLeastOne() {
|
||||
let calendar = Calendar.current
|
||||
let calendar = TestClock.calendar
|
||||
|
||||
// Test various date combinations
|
||||
let testCases: [(arrival: DateComponents, departure: DateComponents)] = [
|
||||
@@ -158,7 +158,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("Invariant: hasGames equals !games.isEmpty")
|
||||
func invariant_hasGamesConsistent() {
|
||||
let now = Date()
|
||||
let now = TestClock.now
|
||||
|
||||
let stopWithGames = makeStop(arrivalDate: now, departureDate: now, games: ["game1"])
|
||||
#expect(stopWithGames.hasGames == !stopWithGames.games.isEmpty)
|
||||
@@ -171,7 +171,7 @@ struct TripStopTests {
|
||||
|
||||
@Test("Property: isRestDay defaults to false")
|
||||
func property_isRestDayDefault() {
|
||||
let now = Date()
|
||||
let now = TestClock.now
|
||||
let stop = makeStop(arrivalDate: now, departureDate: now)
|
||||
|
||||
#expect(stop.isRestDay == false)
|
||||
@@ -183,8 +183,8 @@ struct TripStopTests {
|
||||
stopNumber: 1,
|
||||
city: "City",
|
||||
state: "ST",
|
||||
arrivalDate: Date(),
|
||||
departureDate: Date(),
|
||||
arrivalDate: TestClock.now,
|
||||
departureDate: TestClock.now,
|
||||
isRestDay: true
|
||||
)
|
||||
|
||||
@@ -198,8 +198,8 @@ struct TripStopTests {
|
||||
city: "City",
|
||||
state: "ST",
|
||||
coordinate: nil,
|
||||
arrivalDate: Date(),
|
||||
departureDate: Date(),
|
||||
arrivalDate: TestClock.now,
|
||||
departureDate: TestClock.now,
|
||||
stadium: nil,
|
||||
lodging: nil,
|
||||
notes: nil
|
||||
|
||||
Reference in New Issue
Block a user