import XCTest /// The per-week schedule sheet has to be reachable from the home and show the /// premium upsell to free users — neither is visible to a unit test. final class WeekScheduleUITests: XCTestCase { func testWeekScheduleSheetOpensFromHome() throws { let app = XCUIApplication() app.launchArguments += ["-AppleLanguages", "(en)", "-AppleLocale", "en_US", "UITEST_DISABLE_ANALYTICS"] app.launch() if !app.otherElements["home_root"].waitForExistence(timeout: 5) { for id in ["onboarding_cta_welcome", "onboarding_cta_meal_windows", "onboarding_cta_weekends", "onboarding_cta_calendar", "onboarding_cta_first_dishes", "onboarding_cta_week_ready_skip", "onboarding_cta_paywall_skip"] { let button = app.buttons[id] if button.waitForExistence(timeout: 10) { button.tap() } } XCTAssertTrue(app.otherElements["home_root"].waitForExistence(timeout: 15), "Home never appeared") } let scheduleButton = app.buttons["This week only"] XCTAssertTrue(scheduleButton.waitForExistence(timeout: 10), "Week schedule button not found on the home") scheduleButton.tap() XCTAssertTrue(app.navigationBars["This week only"].waitForExistence(timeout: 5), "Week schedule sheet did not open") XCTAssertTrue(app.switches["Breakfast"].waitForExistence(timeout: 5), "Meal toggles missing") XCTAssertTrue(app.switches["Include weekends"].exists, "Weekend toggle missing") // Free install: the sheet sells premium instead of applying changes. XCTAssertTrue(app.staticTexts["Customising a single week is Premium"].exists, "Premium upsell missing for a free user") XCTAssertFalse(app.buttons["Apply"].isEnabled, "Apply must stay disabled without premium") let screenshot = app.screenshot() let attachment = XCTAttachment(screenshot: screenshot) attachment.name = "week-schedule-sheet" attachment.lifetime = .keepAlways add(attachment) try? screenshot.pngRepresentation.write(to: URL(fileURLWithPath: "/tmp/mealmood-week-schedule-sheet.png")) } }