Files
honeyDueKMP/iosApp/HoneyDueUITests/Framework/TestFlows.swift
T
Trey T c52ce4d497 Re-architect iOS XCUITest suite: per-test isolation + domain organization
Migrate the XCUITest suite off the legacy shared-account model (and the
prior Django-style auth assumptions) to a parallel-safe, domain-organized
architecture, validated end-to-end against the live Kratos stack.

Isolation (parallel-safe by construction):
- Core/Fixtures/TestAccount.swift: each test mints its own pre-verified
  Kratos identity (uit_<domain>_<uuid>@test.honeydue.local), logs in, seeds
  under its own token, and deletes the identity in teardown (cascading all
  data + clearing Kratos). No shared testuser; parallel workers no longer race.
- AuthenticatedUITestCase rewritten to that model (member surface preserved);
  adds requiresResidence / seedAccountPreconditions to seed UI-gated data
  BEFORE login (a fresh account is empty at login).

Organization (255 tests preserved, none dropped):
- 21 domain suites under Auth/ Onboarding/ Residence/ Task/ Contractor/
  Document/ Sharing/ Navigation/ Smoke/ CrossCutting/ E2E/, consistent
  <Domain>UITests naming. Removes the Suite1..11 / AAA_ / ZZ_ / Tests/Rebuild
  naming chaos and the overlapping task/residence/auth suites.

Runner + test plans:
- run_ui_tests.sh: Smoke gate -> Seed -> Parallel(8 workers) -> Sweep. The
  parallel phase runs the whole target minus phase-managed suites via
  -skip-testing, so new suites auto-include (no hand-maintained list to drift).
  Drops the 2-worker cap and Suite6 isolation (isolation made them moot).
- HoneyDueUITests.xctestplan skips the 4 phase-managed suites; adds Smoke.xctestplan.

Kratos auth fixes folded in (login/verify/reset endpoints removed under Kratos):
real Mailpit verification codes replace the obsolete fixed "123456"; teardown
deletes Kratos identities; admin-panel login uses the correct seeded password.

Build green; isolation, parallelism, and the precondition/sharing migrations
validated against the live stack (0 leaked accounts).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 16:26:50 -05:00

118 lines
4.4 KiB
Swift

import XCTest
enum TestFlows {
@discardableResult
static func navigateToLoginFromOnboarding(app: XCUIApplication) -> LoginScreenObject {
let login = LoginScreenObject(app: app)
// If already on standalone login screen, return immediately.
// Use a generous timeout the app may still be rendering after launch.
if app.textFields[UITestID.Auth.usernameField].waitForExistence(timeout: 10)
|| app.otherElements[UITestID.Root.login].waitForExistence(timeout: 3) {
login.waitForLoad()
return login
}
// Check if onboarding is actually present before trying to navigate from it
let onboardingRoot = app.otherElements[UITestID.Root.onboarding]
if onboardingRoot.waitForExistence(timeout: 5) {
// Navigate from onboarding welcome
let welcome = OnboardingWelcomeScreen(app: app)
welcome.waitForLoad()
welcome.tapAlreadyHaveAccount()
login.waitForLoad()
return login
}
// Fallback: use ensureOnLoginScreen which handles all edge cases
UITestHelpers.ensureOnLoginScreen(app: app)
login.waitForLoad()
return login
}
@discardableResult
static func navigateStartFreshToCreateAccount(
app: XCUIApplication,
residenceName: String = "UI Test Residence"
) -> OnboardingCreateAccountScreen {
let welcome = OnboardingWelcomeScreen(app: app)
welcome.waitForLoad()
welcome.tapStartFresh()
let valueProps = OnboardingValuePropsScreen(app: app)
valueProps.waitForLoad()
valueProps.tapContinue()
let nameResidence = OnboardingNameResidenceScreen(app: app)
nameResidence.waitForLoad()
nameResidence.enterResidenceName(residenceName)
nameResidence.tapContinue()
let createAccount = OnboardingCreateAccountScreen(app: app)
createAccount.waitForLoad()
return createAccount
}
/// Type credentials into the login screen and tap login.
/// Assumes the app is already showing the login screen.
static func loginWithCredentials(app: XCUIApplication, username: String, password: String) {
let login = LoginScreenObject(app: app)
login.waitForLoad()
login.enterUsername(username)
login.enterPassword(password)
let loginButton = app.buttons[UITestID.Auth.loginButton]
loginButton.waitUntilHittable(timeout: 10).tap()
}
/// Drive the full forgot password verify code reset password flow.
/// The recovery code is read from Mailpit password reset is a Kratos
/// recovery flow now, so Kratos emails a real 6-digit code (no fixed code).
static func completeForgotPasswordFlow(
app: XCUIApplication,
email: String,
newPassword: String,
confirmPassword: String? = nil
) throws {
let confirm = confirmPassword ?? newPassword
// Step 1: Enter email on forgot password screen
let forgotScreen = ForgotPasswordScreen(app: app)
forgotScreen.waitForLoad()
forgotScreen.enterEmail(email)
forgotScreen.tapSendCode()
// Step 2: Enter the real Kratos recovery code (emailed Mailpit locally)
let verifyScreen = VerifyResetCodeScreen(app: app)
verifyScreen.waitForLoad()
let code = TestAccountAPIClient.latestVerificationCode(for: email) ?? ""
verifyScreen.enterCode(code)
verifyScreen.tapVerify()
// Step 3: Enter new password
let resetScreen = ResetPasswordScreen(app: app)
try resetScreen.waitForLoad()
resetScreen.enterNewPassword(newPassword)
resetScreen.enterConfirmPassword(confirm)
resetScreen.tapReset()
}
@discardableResult
static func openRegisterFromLogin(app: XCUIApplication) -> RegisterScreenObject {
let login: LoginScreenObject
// Wait for login screen elements instead of instantaneous .exists checks
if app.textFields[UITestID.Auth.usernameField].waitForExistence(timeout: 10)
|| app.otherElements[UITestID.Root.login].waitForExistence(timeout: 3) {
login = LoginScreenObject(app: app)
login.waitForLoad()
} else {
login = navigateToLoginFromOnboarding(app: app)
}
login.tapSignUp()
let register = RegisterScreenObject(app: app)
register.waitForLoad()
return register
}
}