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

@@ -2,6 +2,8 @@ import XCTest
final class AuthenticationTests: BaseUITestCase {
override var completeOnboarding: Bool { true }
override var relaunchBetweenTests: Bool { true }
func testF201_OnboardingLoginEntryShowsLoginScreen() {
let login = TestFlows.navigateToLoginFromOnboarding(app: app)
login.waitForLoad(timeout: defaultTimeout)
@@ -16,18 +18,26 @@ final class AuthenticationTests: BaseUITestCase {
}
func testF203_RegisterSheetCanOpenAndDismiss() {
let register = TestFlows.openRegisterFromLogin(app: app)
let login = TestFlows.navigateToLoginFromOnboarding(app: app)
login.waitForLoad(timeout: defaultTimeout)
login.tapSignUp()
let register = RegisterScreenObject(app: app)
register.waitForLoad(timeout: navigationTimeout)
register.tapCancel()
let login = LoginScreenObject(app: app)
login.waitForLoad(timeout: defaultTimeout)
login.waitForLoad(timeout: navigationTimeout)
}
func testF204_RegisterFormAcceptsInput() {
let register = TestFlows.openRegisterFromLogin(app: app)
register.waitForLoad(timeout: defaultTimeout)
let login = TestFlows.navigateToLoginFromOnboarding(app: app)
login.waitForLoad(timeout: defaultTimeout)
login.tapSignUp()
XCTAssertTrue(app.buttons[UITestID.Auth.registerButton].exists)
let register = RegisterScreenObject(app: app)
register.waitForLoad(timeout: navigationTimeout)
XCTAssertTrue(app.buttons[UITestID.Auth.registerButton].exists, "Register button should exist on register form")
}
func testF205_LoginButtonDisabledWhenCredentialsAreEmpty() {
@@ -39,15 +49,13 @@ final class AuthenticationTests: BaseUITestCase {
XCTAssertFalse(loginButton.isEnabled, "Login button should be disabled when username/password are empty")
}
// MARK: - Additional Authentication Coverage
func testF206_ForgotPasswordButtonIsAccessible() {
let login = TestFlows.navigateToLoginFromOnboarding(app: app)
login.waitForLoad(timeout: defaultTimeout)
let forgotButton = app.buttons[UITestID.Auth.forgotPasswordButton]
forgotButton.waitForExistenceOrFail(timeout: defaultTimeout)
XCTAssertTrue(forgotButton.isHittable, "Forgot password button should be accessible")
XCTAssertTrue(forgotButton.isHittable, "Forgot password button should be hittable on login screen")
}
func testF207_LoginScreenShowsAllExpectedElements() {
@@ -66,8 +74,12 @@ final class AuthenticationTests: BaseUITestCase {
}
func testF208_RegisterFormShowsAllRequiredFields() {
let register = TestFlows.openRegisterFromLogin(app: app)
register.waitForLoad(timeout: defaultTimeout)
let login = TestFlows.navigateToLoginFromOnboarding(app: app)
login.waitForLoad(timeout: defaultTimeout)
login.tapSignUp()
let register = RegisterScreenObject(app: app)
register.waitForLoad(timeout: navigationTimeout)
XCTAssertTrue(app.textFields[UITestID.Auth.registerUsernameField].exists, "Register username field should exist")
XCTAssertTrue(app.textFields[UITestID.Auth.registerEmailField].exists, "Register email field should exist")
@@ -82,83 +94,11 @@ final class AuthenticationTests: BaseUITestCase {
login.waitForLoad(timeout: defaultTimeout)
login.tapForgotPassword()
// Verify that tapping forgot password transitions away from login
// The forgot password screen should appear (either sheet or navigation)
let forgotPasswordAppeared = app.staticTexts.containing(
NSPredicate(format: "label CONTAINS[c] 'Forgot' OR label CONTAINS[c] 'Reset' OR label CONTAINS[c] 'Password'")
).firstMatch.waitForExistence(timeout: defaultTimeout)
XCTAssertTrue(forgotPasswordAppeared, "Forgot password flow should appear after tapping button")
}
// MARK: - AUTH-005: Invalid token at startup clears session and returns to login
func test08_invalidatedTokenRedirectsToLogin() throws {
// In UI testing mode, the app skips server-side token validation at startup
// (AuthenticationManager.checkAuthenticationStatus reads from DataManager only).
// This test requires the app to detect an invalidated token via an API call,
// which doesn't happen in --ui-testing mode.
throw XCTSkip("Token validation against server is bypassed in UI testing mode")
try XCTSkipIf(!TestAccountAPIClient.isBackendReachable(), "Backend not reachable")
// Create a verified account via API
guard let session = TestAccountManager.createVerifiedAccount() else {
XCTFail("Could not create verified test account")
return
}
// Login via UI
let login = TestFlows.navigateToLoginFromOnboarding(app: app)
login.waitForLoad(timeout: defaultTimeout)
TestFlows.loginWithCredentials(app: app, username: session.username, password: session.password)
// Wait until the main tab bar is visible, confirming successful login.
// Check both the accessibility ID and the tab bar itself, and handle
// the verification gate in case the app shows it despite API verification.
let mainTabs = app.otherElements[UITestID.Root.mainTabs]
let tabBar = app.tabBars.firstMatch
let deadline = Date().addingTimeInterval(longTimeout)
var reachedMain = false
while Date() < deadline {
if mainTabs.exists || tabBar.exists {
reachedMain = true
break
}
// Handle verification gate if it appears
let verificationCode = app.textFields[AccessibilityIdentifiers.Authentication.verificationCodeField]
if verificationCode.exists {
verificationCode.tap()
verificationCode.typeText(TestAccountAPIClient.debugVerificationCode)
let verifyBtn = app.buttons[AccessibilityIdentifiers.Authentication.verifyButton]
if verifyBtn.waitForExistence(timeout: 5) { verifyBtn.tap() }
if mainTabs.waitForExistence(timeout: longTimeout) || tabBar.waitForExistence(timeout: 5) {
reachedMain = true
break
}
}
RunLoop.current.run(until: Date().addingTimeInterval(0.5))
}
XCTAssertTrue(reachedMain, "Expected main tabs after login")
// Invalidate the token via the logout API (simulates a server-side token revocation)
TestAccountManager.invalidateToken(session)
// Force restart the app terminate and relaunch without --reset-state so the
// app restores its persisted session, which should then be rejected by the server.
app.terminate()
app.launchArguments = ["--ui-testing", "--disable-animations", "--complete-onboarding"]
app.launch()
app.otherElements[UITestID.Root.ready].waitForExistenceOrFail(timeout: defaultTimeout)
// The app should detect the invalid token and redirect to the login screen.
// Check for either login screen or onboarding (both indicate session was cleared).
let usernameField = app.textFields[UITestID.Auth.usernameField]
let loginRoot = app.otherElements[UITestID.Root.login]
let sessionCleared = usernameField.waitForExistence(timeout: longTimeout)
|| loginRoot.waitForExistence(timeout: 5)
XCTAssertTrue(
sessionCleared,
"Expected login screen after startup with an invalidated token"
)
// Verify forgot password screen loaded by checking for its email field (accessibility ID, not label)
let emailField = app.textFields[UITestID.PasswordReset.emailField]
let sendCodeButton = app.buttons[UITestID.PasswordReset.sendCodeButton]
let loaded = emailField.waitForExistence(timeout: navigationTimeout)
|| sendCodeButton.waitForExistence(timeout: navigationTimeout)
XCTAssertTrue(loaded, "Forgot password screen should appear with email field or send code button")
}
}