Files
Sportstime/SportsTimeUITests/Tests/HomeTests.swift
2026-02-20 00:06:38 -06:00

166 lines
5.6 KiB
Swift

//
// HomeTests.swift
// SportsTimeUITests
//
// Tests for the Home tab: hero card, start planning, toolbar button, and recent trips.
// QA Sheet: F-012, F-013, F-014, F-017, F-018, F-019, F-020
//
import XCTest
final class HomeTests: BaseUITestCase {
/// F-012: Hero card displays "Adventure Awaits" text visible, Start Planning tappable.
@MainActor
func testF012_HeroCardDisplaysCorrectly() {
let home = HomeScreen(app: app)
home.waitForLoad()
XCTAssertTrue(home.adventureAwaitsText.exists,
"Hero card should display 'Adventure Awaits'")
XCTAssertTrue(home.startPlanningButton.isHittable,
"Start Planning button should be tappable")
captureScreenshot(named: "F012-HeroCard")
}
/// F-013: Start Planning opens wizard sheet with "Plan a Trip" title.
@MainActor
func testF013_StartPlanningOpensWizard() {
let home = HomeScreen(app: app)
home.waitForLoad()
home.tapStartPlanning()
let wizard = TripWizardScreen(app: app)
wizard.waitForLoad()
XCTAssertTrue(wizard.navigationTitle.exists,
"Wizard should show 'Plan a Trip' title")
captureScreenshot(named: "F013-WizardOpened")
}
/// F-020: Create trip toolbar button (+) opens the same wizard sheet.
@MainActor
func testF020_CreateTripToolbarButtonOpensWizard() {
let home = HomeScreen(app: app)
home.waitForLoad()
home.createTripToolbarButton.waitUntilHittable(
timeout: BaseUITestCase.shortTimeout
).tap()
let wizard = TripWizardScreen(app: app)
wizard.waitForLoad()
XCTAssertTrue(wizard.navigationTitle.exists,
"Toolbar '+' button should open trip wizard")
captureScreenshot(named: "F020-ToolbarCreateTrip")
}
/// F-014: Featured trips carousel loads and is visible.
@MainActor
func testF014_FeaturedTripsCarouselLoads() {
let home = HomeScreen(app: app)
home.waitForLoad()
// Featured trips load asynchronously wait for them to appear
// Then scroll to make them visible. Use the app itself as scroll target
// since NavigationStack + ScrollView can nest scroll containers.
let section = home.featuredTripsSection
if !section.waitForExistence(timeout: BaseUITestCase.longTimeout) {
// Try scrolling to find it
section.scrollIntoView(in: app.scrollViews.firstMatch, maxScrolls: 15)
}
XCTAssertTrue(section.exists,
"Featured trips section should be visible")
captureScreenshot(named: "F014-FeaturedTrips")
}
/// F-017: Recent trips section shows saved trips with "See All" link on Home tab.
@MainActor
func testF017_RecentTripsSectionWithSavedTrips() {
// Plan a trip and select the first option
let (_, detail) = TestFlows.planAndSelectFirstTrip(app: app)
// Save the trip
detail.assertSaveState(isSaved: false)
detail.tapFavorite()
detail.assertSaveState(isSaved: true)
captureScreenshot(named: "F017-TripSaved")
// Navigate back: Detail Options Wizard Cancel (dismiss sheet)
app.navigationBars.buttons.firstMatch.tap()
app.navigationBars.buttons.firstMatch
.waitUntilHittable(timeout: BaseUITestCase.shortTimeout).tap()
TripWizardScreen(app: app).tapCancel()
// We're back on Home tab. Wait for it to load.
let home = HomeScreen(app: app)
home.waitForLoad()
// Scroll to find the recent trips section
let recentTrips = home.recentTripsSection
var scrollAttempts = 0
while !recentTrips.exists && scrollAttempts < 15 {
app.swipeUp(velocity: .slow)
scrollAttempts += 1
}
XCTAssertTrue(recentTrips.exists,
"Recent trips section should appear after saving a trip")
// Verify "See All" link is visible
let seeAllText = app.staticTexts["See All"]
XCTAssertTrue(seeAllText.exists,
"'See All' link should be visible in recent trips section")
captureScreenshot(named: "F017-RecentTripsSection")
}
/// F-018: Fresh launch with no saved trips Recent Trips section should not appear.
@MainActor
func testF018_RecentTripsSectionHiddenNoSavedTrips() {
let home = HomeScreen(app: app)
home.waitForLoad()
// Scroll down to check the full home tab
var scrollAttempts = 0
while scrollAttempts < 5 {
app.swipeUp(velocity: .slow)
scrollAttempts += 1
}
// Recent trips section should NOT exist on a fresh launch
XCTAssertFalse(
home.recentTripsSection.exists,
"Recent trips section should not appear when no trips are saved"
)
captureScreenshot(named: "F018-NoRecentTrips")
}
/// F-019: Planning tips section is visible at bottom of home tab.
@MainActor
func testF019_PlanningTipsSectionVisible() {
let home = HomeScreen(app: app)
home.waitForLoad()
// Tips section is at the very bottom need to scroll far down.
// The home screen has nested scroll views; swipe on the main view.
let section = home.tipsSection
var scrollAttempts = 0
while !section.exists && scrollAttempts < 15 {
app.swipeUp(velocity: .slow)
scrollAttempts += 1
}
XCTAssertTrue(section.exists,
"Planning tips section should be visible")
captureScreenshot(named: "F019-PlanningTips")
}
}