Files
FamilyMealPlanner/MealMoodUITests/OnboardingFlowUITests.swift
T
alexandrev-tibco cfa9769a06 2.0.2: evento de fallo de compra + analytics off en UI tests
premium_purchase_failed con reason (cancelled/pending/unverified/error) en todas
las salidas no exitosas de StoreManager.purchase. Hasta ahora un usuario que se
echaba atras y uno al que le fallaba la compra eran indistinguibles: los dos
dejaban un premium_upgrade_tapped huerfano. El caso de Aleman (6 taps en 2 dias,
cero compras) no se puede diagnosticar sin esto.

Los UI tests dejan de mandar eventos a GA4 de produccion: launch argument
UITEST_DISABLE_ANALYTICS que hace no-op logEvent y apaga la recoleccion de
Firebase, para cortar tambien los automaticos (first_open, session_start,
screen_view). Ya habian contaminado los datos: los eventos de pasos 5/6 bajo la
version 2.0 eran ejecuciones de test, no usuarios.

Detalle que costo encontrar: setAnalyticsCollectionEnabled persiste entre
lanzamientos, asi que se escribe siempre (!isDisabled) y no solo al apagar. Si
no, un unico test dejaba analytics muerto para siempre en esa instalacion.
Verificado por pares de lanzamientos: con flag acaba en disabled, sin flag
vuelve a enabled.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Ks8uUcMA9mjypVK7F2Pkt
2026-08-13 14:02:35 +02:00

76 lines
3.2 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"]
// Keep synthetic runs out of the production GA4 property. Literal on
// purpose: a UI test bundle doesn't link the app target, so it can't
// reference AnalyticsService.launchArgumentDisablingAnalytics keep the
// two in sync by hand.
app.launchArguments.append("UITEST_DISABLE_ANALYTICS")
}
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
}
}
}
}