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>
150 lines
6.0 KiB
Swift
150 lines
6.0 KiB
Swift
import XCTest
|
|
|
|
/// Rebuild plan for legacy Suite2 failures:
|
|
/// - test02_loginWithValidCredentials
|
|
/// - test06_logout
|
|
final class Suite2_AuthenticationRebuildTests: BaseUITestCase {
|
|
override var includeResetStateLaunchArgument: Bool { false }
|
|
override var relaunchBetweenTests: Bool { true }
|
|
private let validUser = RebuildTestUserFactory.seeded
|
|
|
|
private enum AuthLandingState {
|
|
case main
|
|
case verification
|
|
}
|
|
|
|
override func setUpWithError() throws {
|
|
// Force a clean app launch so no stale field text persists between tests
|
|
app.terminate()
|
|
try super.setUpWithError()
|
|
UITestHelpers.ensureLoggedOut(app: app)
|
|
}
|
|
|
|
private func loginFromLoginScreen(user: RebuildTestUser = RebuildTestUserFactory.seeded) {
|
|
UITestHelpers.ensureOnLoginScreen(app: app)
|
|
let login = LoginScreenObject(app: app)
|
|
login.waitForLoad(timeout: defaultTimeout)
|
|
login.enterUsername(user.username)
|
|
login.enterPassword(user.password)
|
|
|
|
let loginButton = app.buttons[AccessibilityIdentifiers.Authentication.loginButton]
|
|
loginButton.waitForExistenceOrFail(timeout: defaultTimeout)
|
|
loginButton.forceTap()
|
|
}
|
|
|
|
@discardableResult
|
|
private func loginAndWaitForAuthenticatedLanding(user: RebuildTestUser = RebuildTestUserFactory.seeded) -> AuthLandingState {
|
|
loginFromLoginScreen(user: user)
|
|
|
|
let mainRoot = app.otherElements[UITestID.Root.mainTabs]
|
|
if mainRoot.waitForExistence(timeout: loginTimeout) || app.tabBars.firstMatch.waitForExistence(timeout: 2) {
|
|
return .main
|
|
}
|
|
|
|
let verification = VerificationScreen(app: app)
|
|
if verification.codeField.waitForExistence(timeout: defaultTimeout) || verification.verifyButton.waitForExistence(timeout: 2) {
|
|
return .verification
|
|
}
|
|
|
|
XCTFail("Expected authenticated landing on main tabs or verification screen")
|
|
return .verification
|
|
}
|
|
|
|
private func logoutFromVerificationIfNeeded() {
|
|
let verification = VerificationScreen(app: app)
|
|
verification.waitForLoad(timeout: defaultTimeout)
|
|
verification.tapLogoutIfAvailable()
|
|
|
|
let toolbarLogout = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Logout' OR label CONTAINS[c] 'Log Out'")).firstMatch
|
|
if toolbarLogout.waitForExistence(timeout: 3) {
|
|
toolbarLogout.forceTap()
|
|
}
|
|
}
|
|
|
|
private func logoutFromMainApp() {
|
|
UITestHelpers.logout(app: app)
|
|
}
|
|
|
|
func testR201_loginScreenLoadsFromOnboardingEntry() {
|
|
UITestHelpers.ensureOnLoginScreen(app: app)
|
|
let login = LoginScreenObject(app: app)
|
|
login.waitForLoad(timeout: defaultTimeout)
|
|
}
|
|
|
|
func testR202_validCredentialsSubmitFromLogin() {
|
|
UITestHelpers.ensureOnLoginScreen(app: app)
|
|
let login = LoginScreenObject(app: app)
|
|
login.waitForLoad(timeout: defaultTimeout)
|
|
|
|
login.enterUsername(validUser.username)
|
|
login.enterPassword(validUser.password)
|
|
|
|
let loginButton = app.buttons[AccessibilityIdentifiers.Authentication.loginButton]
|
|
XCTAssertTrue(loginButton.waitForExistence(timeout: defaultTimeout), "Login button must exist before submit")
|
|
XCTAssertTrue(loginButton.isHittable, "Login button must be tappable")
|
|
}
|
|
|
|
func testR203_validLoginTransitionsToMainAppRoot() {
|
|
let landing = loginAndWaitForAuthenticatedLanding(user: validUser)
|
|
switch landing {
|
|
case .main:
|
|
RebuildSessionAssertions.assertOnMainApp(app, timeout: loginTimeout)
|
|
case .verification:
|
|
RebuildSessionAssertions.assertOnVerification(app, timeout: loginTimeout)
|
|
}
|
|
}
|
|
|
|
func testR204_mainAppHasExpectedPrimaryTabsAfterLogin() {
|
|
let landing = loginAndWaitForAuthenticatedLanding(user: validUser)
|
|
|
|
switch landing {
|
|
case .main:
|
|
RebuildSessionAssertions.assertOnMainApp(app, timeout: loginTimeout)
|
|
|
|
let tabBar = app.tabBars.firstMatch
|
|
if tabBar.waitForExistence(timeout: 5) {
|
|
let residences = tabBar.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
|
let tasks = tabBar.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
|
let contractors = tabBar.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
|
let docs = tabBar.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Doc'")).firstMatch
|
|
XCTAssertTrue(residences.exists, "Residences tab should exist")
|
|
XCTAssertTrue(tasks.exists, "Tasks tab should exist")
|
|
XCTAssertTrue(contractors.exists, "Contractors tab should exist")
|
|
XCTAssertTrue(docs.exists, "Documents tab should exist")
|
|
} else {
|
|
XCTAssertTrue(app.otherElements[UITestID.Root.mainTabs].exists, "Main tabs root should exist")
|
|
}
|
|
case .verification:
|
|
let verify = VerificationScreen(app: app)
|
|
verify.waitForLoad(timeout: defaultTimeout)
|
|
XCTAssertTrue(verify.codeField.exists, "Verification code field should exist for unverified accounts")
|
|
}
|
|
}
|
|
|
|
func testR205_logoutFromMainAppReturnsToLoginRoot() {
|
|
let landing = loginAndWaitForAuthenticatedLanding(user: validUser)
|
|
|
|
switch landing {
|
|
case .main:
|
|
logoutFromMainApp()
|
|
case .verification:
|
|
logoutFromVerificationIfNeeded()
|
|
}
|
|
RebuildSessionAssertions.assertOnLogin(app, timeout: loginTimeout)
|
|
}
|
|
|
|
func testR206_postLogoutMainAppIsNoLongerAccessible() {
|
|
let landing = loginAndWaitForAuthenticatedLanding(user: validUser)
|
|
|
|
switch landing {
|
|
case .main:
|
|
logoutFromMainApp()
|
|
case .verification:
|
|
logoutFromVerificationIfNeeded()
|
|
}
|
|
RebuildSessionAssertions.assertOnLogin(app, timeout: loginTimeout)
|
|
|
|
XCTAssertFalse(app.otherElements[UITestID.Root.mainTabs].exists, "Main app root should not be visible after logout")
|
|
}
|
|
}
|