79423e3511
El bug de los pasos 5 y 6 era invisible a los tests unitarios: el contrato de datos estaba bien, lo que fallaba era que la vista se desmontaba antes de pintar el aha moment y el paywall. Hace falta recorrer la UI de verdad. Anade el target MealMoodUITests (solo simulador, sin firma) y un test que hace el onboarding entero en instalacion limpia y comprueba que Week Ready y el paywall aparecen antes de la Home. Los CTA del onboarding llevan ahora accessibilityIdentifier para que el test no dependa de los textos, que estan en 6 idiomas. Validado en los dos sentidos: pasa con el fix, y revirtiendo temporalmente markFinished: false falla en la asercion de Week Ready. Suite completa: 27 tests. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Ks8uUcMA9mjypVK7F2Pkt
71 lines
2.9 KiB
Swift
71 lines
2.9 KiB
Swift
import XCTest
|
|
|
|
/// Walks the whole onboarding on a clean install.
|
|
///
|
|
/// This exists because of a bug that no unit test could see: the flow used to
|
|
/// write `onboardingCompleted` at the dishes step, which swapped the root view
|
|
/// for the home and silently skipped the last two steps — the Week Ready "aha
|
|
/// moment" and the paywall. Shipped in 2.0 and live for a week before GA4
|
|
/// (no step 5/6 events despite completions) gave it away.
|
|
final class OnboardingFlowUITests: XCTestCase {
|
|
|
|
private var app: XCUIApplication!
|
|
|
|
override func setUpWithError() throws {
|
|
continueAfterFailure = false
|
|
app = XCUIApplication()
|
|
// Pin the language so the run doesn't depend on the simulator's locale.
|
|
app.launchArguments += ["-AppleLanguages", "(en)", "-AppleLocale", "en_US"]
|
|
}
|
|
|
|
func testOnboardingReachesWeekReadyAndPaywallBeforeTheHome() {
|
|
app.launch()
|
|
dismissSystemAlertIfPresent()
|
|
|
|
tap("onboarding_cta_welcome", "welcome")
|
|
tap("onboarding_cta_meal_windows", "meal windows")
|
|
tap("onboarding_cta_weekends", "weekends")
|
|
tap("onboarding_cta_calendar", "calendar")
|
|
tap("onboarding_cta_first_dishes", "first dishes")
|
|
|
|
// The two steps the bug used to skip.
|
|
let weekReady = app.staticTexts["onboarding_week_ready_title"]
|
|
XCTAssertTrue(weekReady.waitForExistence(timeout: 10),
|
|
"Week Ready (the aha moment) never appeared — the flow skipped step 5")
|
|
|
|
tap("onboarding_cta_week_ready_skip", "week ready")
|
|
|
|
let paywallSkip = app.buttons["onboarding_cta_paywall_skip"]
|
|
XCTAssertTrue(paywallSkip.waitForExistence(timeout: 10),
|
|
"The paywall never appeared — the flow skipped step 6")
|
|
paywallSkip.tap()
|
|
|
|
// Only now should onboarding hand over to the home.
|
|
XCTAssertTrue(app.otherElements["home_root"].waitForExistence(timeout: 15),
|
|
"Onboarding finished but the home never came up")
|
|
}
|
|
|
|
// MARK: Helpers
|
|
|
|
private func tap(_ identifier: String, _ step: String, file: StaticString = #filePath, line: UInt = #line) {
|
|
let button = app.buttons[identifier]
|
|
XCTAssertTrue(button.waitForExistence(timeout: 15),
|
|
"Never reached the \(step) step", file: file, line: line)
|
|
button.tap()
|
|
dismissSystemAlertIfPresent()
|
|
}
|
|
|
|
/// The simulator can raise an Apple Account / iCloud prompt on launch, which
|
|
/// would swallow the taps that follow.
|
|
private func dismissSystemAlertIfPresent() {
|
|
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
|
|
for label in ["Not Now", "Cancel", "Don't Allow", "Allow"] {
|
|
let button = springboard.buttons[label]
|
|
if button.exists && button.isHittable {
|
|
button.tap()
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|