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>
This commit is contained in:
Trey T
2026-03-23 15:05:37 -05:00
parent 0ca4a44bac
commit 4df8707b92
67 changed files with 3085 additions and 4853 deletions

View File

@@ -1,162 +1,101 @@
import XCTest
/// Critical path tests for authentication flows.
///
/// Validates login, logout, registration entry, and password reset entry.
/// Zero sleep() calls all waits are condition-based.
final class AuthCriticalPathTests: XCTestCase {
var app: XCUIApplication!
override func setUp() {
super.setUp()
continueAfterFailure = false
addUIInterruptionMonitor(withDescription: "System Alert") { alert in
let buttons = ["Allow", "OK", "Don't Allow", "Not Now", "Dismiss", "Allow While Using App"]
for label in buttons {
let button = alert.buttons[label]
if button.exists {
button.tap()
return true
}
}
return false
}
app = TestLaunchConfig.launchApp()
}
override func tearDown() {
app = nil
super.tearDown()
}
/// Tests login, logout, registration entry, forgot password entry.
final class AuthCriticalPathTests: BaseUITestCase {
override var relaunchBetweenTests: Bool { true }
// MARK: - Helpers
/// Navigate to the login screen, handling onboarding welcome if present.
private func navigateToLogin() -> LoginScreen {
let login = LoginScreen(app: app)
private func navigateToLogin() {
let loginField = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
if loginField.waitForExistence(timeout: defaultTimeout) { return }
// Already on login screen
if login.emailField.waitForExistence(timeout: 5) {
return login
// On onboarding tap login button
let onboardingLogin = app.buttons[AccessibilityIdentifiers.Onboarding.loginButton]
if onboardingLogin.waitForExistence(timeout: navigationTimeout) {
onboardingLogin.tap()
}
// On onboarding welcome tap "Already have an account?" to reach login
let onboardingLogin = app.descendants(matching: .any)
.matching(identifier: UITestID.Onboarding.loginButton).firstMatch
if onboardingLogin.waitForExistence(timeout: 10) {
if onboardingLogin.isHittable {
onboardingLogin.tap()
} else {
onboardingLogin.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).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
}
_ = login.emailField.waitForExistence(timeout: 10)
RunLoop.current.run(until: Date().addingTimeInterval(0.5))
}
return login
XCTAssertTrue(tabBar.exists, "Should reach main app after login")
}
// MARK: - Login
func testLoginWithValidCredentials() {
let login = navigateToLogin()
guard login.emailField.exists else {
// Already logged in verify main screen
let main = MainTabScreen(app: app)
XCTAssertTrue(main.isDisplayed, "Main screen should be visible when already logged in")
return
}
let user = TestFixtures.TestUser.existing
login.login(email: user.email, password: user.password)
let main = MainTabScreen(app: app)
let reached = main.residencesTab.waitForExistence(timeout: 15)
|| app.tabBars.firstMatch.waitForExistence(timeout: 3)
if !reached {
// Dump view hierarchy for diagnosis
XCTFail("Should navigate to main screen after login. App state:\n\(app.debugDescription)")
return
}
loginAsTestUser()
XCTAssertTrue(app.tabBars.firstMatch.exists, "Tab bar should be visible after login")
}
func testLoginWithInvalidCredentials() {
let login = navigateToLogin()
guard login.emailField.exists else {
return // Already logged in, skip
}
navigateToLogin()
login.login(email: "invaliduser", password: "wrongpassword")
let login = LoginScreenObject(app: app)
login.enterUsername("invaliduser")
login.enterPassword("wrongpassword")
app.buttons[AccessibilityIdentifiers.Authentication.loginButton].tap()
// Should stay on login screen email field should still exist
XCTAssertTrue(
login.emailField.waitForExistence(timeout: 10),
"Should remain on login screen after invalid credentials"
)
// Tab bar should NOT appear
let tabBar = app.tabBars.firstMatch
XCTAssertFalse(tabBar.exists, "Tab bar should not appear after failed login")
// 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() {
let login = navigateToLogin()
if login.emailField.exists {
let user = TestFixtures.TestUser.existing
login.login(email: user.email, password: user.password)
}
loginAsTestUser()
UITestHelpers.logout(app: app)
let main = MainTabScreen(app: app)
guard main.residencesTab.waitForExistence(timeout: 15) else {
XCTFail("Main screen did not appear — app may be on onboarding or verification")
return
}
main.logout()
// Should be back on login screen or onboarding
let loginAfterLogout = LoginScreen(app: app)
let reachedLogin = loginAfterLogout.emailField.waitForExistence(timeout: 30)
|| app.otherElements["ui.root.login"].waitForExistence(timeout: 5)
if !reachedLogin {
// Check if we landed on onboarding instead
let onboardingLogin = app.descendants(matching: .any)
.matching(identifier: UITestID.Onboarding.loginButton).firstMatch
if onboardingLogin.waitForExistence(timeout: 5) {
// Onboarding is acceptable logout succeeded
return
}
XCTFail("Should return to login or onboarding screen after logout. App state:\n\(app.debugDescription)")
}
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() {
let login = navigateToLogin()
guard login.emailField.exists else {
return // Already logged in, skip
}
navigateToLogin()
app.buttons[AccessibilityIdentifiers.Authentication.signUpButton].tap()
let register = login.tapSignUp()
XCTAssertTrue(register.isDisplayed, "Registration screen should appear after tapping Sign Up")
let registerUsername = app.textFields[AccessibilityIdentifiers.Authentication.registerUsernameField]
XCTAssertTrue(registerUsername.waitForExistence(timeout: navigationTimeout), "Registration form should appear")
}
// MARK: - Forgot Password Entry
// MARK: - Forgot Password
func testForgotPasswordButtonExists() {
let login = navigateToLogin()
guard login.emailField.exists else {
return // Already logged in, skip
}
XCTAssertTrue(
login.forgotPasswordButton.waitForExistence(timeout: 5),
"Forgot password button should exist on login screen"
)
navigateToLogin()
let forgotButton = app.buttons[AccessibilityIdentifiers.Authentication.forgotPasswordButton]
XCTAssertTrue(forgotButton.waitForExistence(timeout: defaultTimeout), "Forgot password button should exist")
}
}