Stabilize unit and UI tests for SportsTime
This commit is contained in:
@@ -53,7 +53,7 @@ struct HistoricalGameQueryTests {
|
||||
/// - Expected Behavior: Returns date in yyyy-MM-dd format (Eastern time)
|
||||
@Test("normalizedDateString: formats as yyyy-MM-dd")
|
||||
func normalizedDateString_format() {
|
||||
var calendar = Calendar.current
|
||||
var calendar = TestClock.calendar
|
||||
calendar.timeZone = TimeZone(identifier: "America/New_York")!
|
||||
let date = calendar.date(from: DateComponents(year: 2026, month: 6, day: 15))!
|
||||
|
||||
@@ -64,7 +64,7 @@ struct HistoricalGameQueryTests {
|
||||
|
||||
@Test("normalizedDateString: pads single-digit months")
|
||||
func normalizedDateString_padMonth() {
|
||||
var calendar = Calendar.current
|
||||
var calendar = TestClock.calendar
|
||||
calendar.timeZone = TimeZone(identifier: "America/New_York")!
|
||||
let date = calendar.date(from: DateComponents(year: 2026, month: 3, day: 5))!
|
||||
|
||||
@@ -77,7 +77,7 @@ struct HistoricalGameQueryTests {
|
||||
|
||||
@Test("init: stores sport correctly")
|
||||
func init_storesSport() {
|
||||
let query = HistoricalGameQuery(sport: .nba, date: Date())
|
||||
let query = HistoricalGameQuery(sport: .nba, date: TestClock.now)
|
||||
#expect(query.sport == .nba)
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ struct HistoricalGameQueryTests {
|
||||
func init_storesTeams() {
|
||||
let query = HistoricalGameQuery(
|
||||
sport: .mlb,
|
||||
date: Date(),
|
||||
date: TestClock.now,
|
||||
homeTeamAbbrev: "NYY",
|
||||
awayTeamAbbrev: "BOS"
|
||||
)
|
||||
@@ -96,7 +96,7 @@ struct HistoricalGameQueryTests {
|
||||
|
||||
@Test("init: team abbreviations default to nil")
|
||||
func init_defaultNilTeams() {
|
||||
let query = HistoricalGameQuery(sport: .mlb, date: Date())
|
||||
let query = HistoricalGameQuery(sport: .mlb, date: TestClock.now)
|
||||
|
||||
#expect(query.homeTeamAbbrev == nil)
|
||||
#expect(query.awayTeamAbbrev == nil)
|
||||
@@ -117,7 +117,7 @@ struct HistoricalGameResultTests {
|
||||
) -> HistoricalGameResult {
|
||||
HistoricalGameResult(
|
||||
sport: .mlb,
|
||||
gameDate: Date(),
|
||||
gameDate: TestClock.now,
|
||||
homeTeamAbbrev: "NYY",
|
||||
awayTeamAbbrev: "BOS",
|
||||
homeTeamName: "Yankees",
|
||||
@@ -214,7 +214,7 @@ struct ScoreResolutionResultTests {
|
||||
private func makeHistoricalResult() -> HistoricalGameResult {
|
||||
HistoricalGameResult(
|
||||
sport: .mlb,
|
||||
gameDate: Date(),
|
||||
gameDate: TestClock.now,
|
||||
homeTeamAbbrev: "NYY",
|
||||
awayTeamAbbrev: "BOS",
|
||||
homeTeamName: "Yankees",
|
||||
|
||||
@@ -87,7 +87,7 @@ struct GameMatchResultTests {
|
||||
homeTeamId: "home_team",
|
||||
awayTeamId: "away_team",
|
||||
stadiumId: "stadium_1",
|
||||
dateTime: Date(),
|
||||
dateTime: TestClock.now,
|
||||
sport: .mlb,
|
||||
season: "2026"
|
||||
)
|
||||
@@ -194,7 +194,7 @@ struct GameMatchCandidateTests {
|
||||
homeTeamId: "home_team",
|
||||
awayTeamId: "away_team",
|
||||
stadiumId: "stadium_1",
|
||||
dateTime: Date(),
|
||||
dateTime: TestClock.now,
|
||||
sport: .mlb,
|
||||
season: "2026"
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ struct ScrapedGameTests {
|
||||
sport: Sport = .mlb
|
||||
) -> ScrapedGame {
|
||||
ScrapedGame(
|
||||
date: Date(),
|
||||
date: TestClock.now,
|
||||
homeTeam: homeTeam,
|
||||
awayTeam: awayTeam,
|
||||
homeScore: homeScore,
|
||||
@@ -69,7 +69,7 @@ struct ScrapedGameTests {
|
||||
|
||||
@Test("ScrapedGame: stores date")
|
||||
func scrapedGame_date() {
|
||||
let date = Date()
|
||||
let date = TestClock.now
|
||||
let game = ScrapedGame(
|
||||
date: date,
|
||||
homeTeam: "Home",
|
||||
|
||||
@@ -18,7 +18,7 @@ struct PhotoMetadataTests {
|
||||
// MARK: - Test Data
|
||||
|
||||
private func makeMetadata(
|
||||
captureDate: Date? = Date(),
|
||||
captureDate: Date? = TestClock.now,
|
||||
coordinates: CLLocationCoordinate2D? = CLLocationCoordinate2D(latitude: 40.0, longitude: -74.0)
|
||||
) -> PhotoMetadata {
|
||||
PhotoMetadata(captureDate: captureDate, coordinates: coordinates)
|
||||
@@ -45,7 +45,7 @@ struct PhotoMetadataTests {
|
||||
/// - Expected Behavior: true when captureDate is provided
|
||||
@Test("hasValidDate: true when captureDate provided")
|
||||
func hasValidDate_true() {
|
||||
let metadata = makeMetadata(captureDate: Date())
|
||||
let metadata = makeMetadata(captureDate: TestClock.now)
|
||||
#expect(metadata.hasValidDate == true)
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ struct PhotoMetadataTests {
|
||||
|
||||
@Test("Both valid: location and date both provided")
|
||||
func bothValid() {
|
||||
let metadata = makeMetadata(captureDate: Date(), coordinates: CLLocationCoordinate2D(latitude: 0, longitude: 0))
|
||||
let metadata = makeMetadata(captureDate: TestClock.now, coordinates: CLLocationCoordinate2D(latitude: 0, longitude: 0))
|
||||
#expect(metadata.hasValidLocation == true)
|
||||
#expect(metadata.hasValidDate == true)
|
||||
}
|
||||
@@ -101,7 +101,7 @@ struct PhotoMetadataTests {
|
||||
|
||||
@Test("Only date: coordinates nil")
|
||||
func onlyDate() {
|
||||
let metadata = makeMetadata(captureDate: Date(), coordinates: nil)
|
||||
let metadata = makeMetadata(captureDate: TestClock.now, coordinates: nil)
|
||||
#expect(metadata.hasValidLocation == false)
|
||||
#expect(metadata.hasValidDate == true)
|
||||
}
|
||||
@@ -121,7 +121,7 @@ struct PhotoMetadataTests {
|
||||
/// - Invariant: hasValidDate == (captureDate != nil)
|
||||
@Test("Invariant: hasValidDate equals captureDate check")
|
||||
func invariant_hasValidDateEqualsCaptureCheck() {
|
||||
let withDate = makeMetadata(captureDate: Date())
|
||||
let withDate = makeMetadata(captureDate: TestClock.now)
|
||||
let withoutDate = makeMetadata(captureDate: nil)
|
||||
|
||||
#expect(withDate.hasValidDate == (withDate.captureDate != nil))
|
||||
|
||||
@@ -41,8 +41,8 @@ struct RouteDescriptionInputTests {
|
||||
state: "XX",
|
||||
coordinate: nycCoord,
|
||||
games: games,
|
||||
arrivalDate: Date(),
|
||||
departureDate: Date().addingTimeInterval(86400),
|
||||
arrivalDate: TestClock.now,
|
||||
departureDate: TestClock.now.addingTimeInterval(86400),
|
||||
location: LocationInput(name: city, coordinate: nycCoord),
|
||||
firstGameStart: nil
|
||||
)
|
||||
@@ -54,7 +54,7 @@ struct RouteDescriptionInputTests {
|
||||
homeTeamId: "team1",
|
||||
awayTeamId: "team2",
|
||||
stadiumId: "stadium1",
|
||||
dateTime: Date(),
|
||||
dateTime: TestClock.now,
|
||||
sport: sport,
|
||||
season: "2026",
|
||||
isPlayoff: false
|
||||
|
||||
@@ -22,8 +22,8 @@ struct SuggestedTripTests {
|
||||
preferences: TripPreferences(
|
||||
planningMode: .dateRange,
|
||||
sports: [.mlb],
|
||||
startDate: Date(),
|
||||
endDate: Date().addingTimeInterval(86400 * 7),
|
||||
startDate: TestClock.now,
|
||||
endDate: TestClock.now.addingTimeInterval(86400 * 7),
|
||||
leisureLevel: .moderate
|
||||
),
|
||||
stops: [],
|
||||
@@ -339,7 +339,7 @@ struct CrossCountryFeatureTripTests {
|
||||
idPrefix: String
|
||||
) -> [Game] {
|
||||
var games: [Game] = []
|
||||
let calendar = Calendar.current
|
||||
let calendar = TestClock.calendar
|
||||
|
||||
for (index, stadium) in stadiums.enumerated() {
|
||||
let gameDate = calendar.date(byAdding: .day, value: index * spacingDays, to: startDate) ?? startDate
|
||||
@@ -373,7 +373,7 @@ struct CrossCountryFeatureTripTests {
|
||||
idPrefix: "e2w"
|
||||
)
|
||||
|
||||
let secondLegStart = Calendar.current.date(
|
||||
let secondLegStart = TestClock.calendar.date(
|
||||
byAdding: .day,
|
||||
value: (sortedEastToWest.count * spacingDays) + 2,
|
||||
to: baseDate
|
||||
|
||||
Reference in New Issue
Block a user