Files
honeyDueKMP/iosApp/HoneyDueUITests/CriticalPath/AuthCriticalPathTests.swift
Trey T 4df8707b92 UI test infrastructure overhaul — 58% to 96% pass rate (231/241)
Major infrastructure changes:
- BaseUITestCase: per-suite app termination via class setUp() prevents
  stale state when parallel clones share simulators
- relaunchBetweenTests override for suites that modify login/onboarding state
- focusAndType: dedicated SecureTextField path handles iOS strong password
  autofill suggestions (Choose My Own Password / Not Now dialogs)
- LoginScreenObject: tapSignUp/tapForgotPassword use scrollIntoView for
  offscreen buttons instead of simple swipeUp
- Removed all coordinate taps from ForgotPasswordScreen, VerifyResetCodeScreen,
  ResetPasswordScreen (Rule 3 compliance)
- Removed all usleep calls from screen objects (Rule 14 compliance)

App fixes exposed by tests:
- ContractorsListView: added onDismiss to sheet for list refresh after save
- AllTasksView: added Task.RefreshButton accessibility identifier
- AccessibilityIdentifiers: added Task.refreshButton
- DocumentsWarrantiesView: onDismiss handler for document list refresh
- Various form views: textContentType, submitLabel, onSubmit for keyboard flow

Test fixes:
- PasswordResetTests: handle auto-login after reset (app skips success screen)
- AuthenticatedUITestCase: refreshTasks() helper for kanban toolbar button
- All pre-login suites use relaunchBetweenTests for test independence
- Deleted dead code: AuthenticatedTestCase, SeededTestData, SeedTests,
  CleanupTests, old Suite0/2/3, Suite1_RegistrationRebuildTests

10 remaining failures: 5 iOS strong password autofill (simulator env),
3 pull-to-refresh gesture on empty lists, 2 feature coverage edge cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 15:05:37 -05:00

102 lines
3.9 KiB
Swift

import XCTest
/// Critical path tests for authentication flows.
/// Tests login, logout, registration entry, forgot password entry.
final class AuthCriticalPathTests: BaseUITestCase {
override var relaunchBetweenTests: Bool { true }
// MARK: - Helpers
private func navigateToLogin() {
let loginField = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
if loginField.waitForExistence(timeout: defaultTimeout) { return }
// On onboarding tap login button
let onboardingLogin = app.buttons[AccessibilityIdentifiers.Onboarding.loginButton]
if onboardingLogin.waitForExistence(timeout: navigationTimeout) {
onboardingLogin.tap()
}
loginField.waitForExistenceOrFail(timeout: navigationTimeout, message: "Login screen should appear")
}
private func loginAsTestUser() {
navigateToLogin()
let login = LoginScreenObject(app: app)
login.enterUsername("testuser")
login.enterPassword("TestPass123!")
app.buttons[AccessibilityIdentifiers.Authentication.loginButton].tap()
// Wait for main app or verification gate
let tabBar = app.tabBars.firstMatch
let verification = VerificationScreen(app: app)
let deadline = Date().addingTimeInterval(loginTimeout)
while Date() < deadline {
if tabBar.exists { return }
if verification.codeField.exists {
verification.enterCode(TestAccountAPIClient.debugVerificationCode)
verification.submitCode()
_ = tabBar.waitForExistence(timeout: loginTimeout)
return
}
RunLoop.current.run(until: Date().addingTimeInterval(0.5))
}
XCTAssertTrue(tabBar.exists, "Should reach main app after login")
}
// MARK: - Login
func testLoginWithValidCredentials() {
loginAsTestUser()
XCTAssertTrue(app.tabBars.firstMatch.exists, "Tab bar should be visible after login")
}
func testLoginWithInvalidCredentials() {
navigateToLogin()
let login = LoginScreenObject(app: app)
login.enterUsername("invaliduser")
login.enterPassword("wrongpassword")
app.buttons[AccessibilityIdentifiers.Authentication.loginButton].tap()
// Should stay on login screen
let loginField = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
XCTAssertTrue(loginField.waitForExistence(timeout: navigationTimeout), "Should remain on login screen after invalid credentials")
XCTAssertFalse(app.tabBars.firstMatch.exists, "Tab bar should not appear after failed login")
}
// MARK: - Logout
func testLogoutFlow() {
loginAsTestUser()
UITestHelpers.logout(app: app)
let loginField = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
let onboardingLogin = app.buttons[AccessibilityIdentifiers.Onboarding.loginButton]
let loggedOut = loginField.waitForExistence(timeout: loginTimeout)
|| onboardingLogin.waitForExistence(timeout: navigationTimeout)
XCTAssertTrue(loggedOut, "Should return to login or onboarding after logout")
}
// MARK: - Registration Entry
func testSignUpButtonNavigatesToRegistration() {
navigateToLogin()
app.buttons[AccessibilityIdentifiers.Authentication.signUpButton].tap()
let registerUsername = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
XCTAssertTrue(registerUsername.waitForExistence(timeout: navigationTimeout), "Registration form should appear")
}
// MARK: - Forgot Password
func testForgotPasswordButtonExists() {
navigateToLogin()
let forgotButton = app.buttons[AccessibilityIdentifiers.Authentication.forgotPasswordButton]
XCTAssertTrue(forgotButton.waitForExistence(timeout: defaultTimeout), "Forgot password button should exist")
}
}