Files
honeyDueKMP/iosApp/HoneyDueUITests/Tests/Rebuild/Suite2_AuthenticationRebuildTests.swift
treyt 5c360a2796 Rearchitect UI test suite for complete, non-flaky coverage against live API
- Migrate Suite4-10, SmokeTests, NavigationCriticalPathTests to AuthenticatedTestCase
  with seeded admin account and real backend login
- Add 34 accessibility identifiers across 11 app views (task completion, profile,
  notifications, theme, join residence, manage users, forms)
- Create FeatureCoverageTests (14 tests) covering previously untested features:
  profile edit, theme selection, notification prefs, task completion, manage users,
  join residence, task templates
- Create MultiUserSharingTests (18 API tests) and MultiUserSharingUITests (8 XCUI
  tests) for full cross-user residence sharing lifecycle
- Add cleanup infrastructure: SuiteZZ_CleanupTests auto-wipes test data after runs,
  cleanup_test_data.sh script for manual reset via admin API
- Add share code API methods to TestAccountAPIClient (generateShareCode, joinWithCode,
  getShareCode, listResidenceUsers, removeUser)
- Fix app bugs found by tests:
  - ResidencesListView join callback now uses forceRefresh:true
  - APILayer invalidates task cache when residence count changes
  - AllTasksView auto-reloads tasks when residence list changes
- Fix test quality: keyboard focus waits, Save/Add button label matching,
  Documents tab label (Docs), remove API verification from UI tests
- DataLayerTests and PasswordResetTests now verify through UI, not API calls

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

147 lines
5.9 KiB
Swift

import XCTest
/// Rebuild plan for legacy Suite2 failures:
/// - test02_loginWithValidCredentials
/// - test06_logout
final class Suite2_AuthenticationRebuildTests: BaseUITestCase {
override var includeResetStateLaunchArgument: Bool { false }
private let validUser = RebuildTestUserFactory.seeded
private enum AuthLandingState {
case main
case verification
}
override func setUpWithError() throws {
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: longTimeout) || 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: longTimeout)
case .verification:
RebuildSessionAssertions.assertOnVerification(app, timeout: longTimeout)
}
}
func testR204_mainAppHasExpectedPrimaryTabsAfterLogin() {
let landing = loginAndWaitForAuthenticatedLanding(user: validUser)
switch landing {
case .main:
RebuildSessionAssertions.assertOnMainApp(app, timeout: longTimeout)
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: longTimeout)
}
func testR206_postLogoutMainAppIsNoLongerAccessible() {
let landing = loginAndWaitForAuthenticatedLanding(user: validUser)
switch landing {
case .main:
logoutFromMainApp()
case .verification:
logoutFromVerificationIfNeeded()
}
RebuildSessionAssertions.assertOnLogin(app, timeout: longTimeout)
XCTAssertFalse(app.otherElements[UITestID.Root.mainTabs].exists, "Main app root should not be visible after logout")
}
}