Fix UI test failures: registration dismiss cascade, onboarding reset, test stability

- Fix registration flow dismiss cascade: chain fullScreenCover → sheet onDismiss
  so auth state is set only after all UIKit presentations are removed, preventing
  RootView from swapping LoginView→MainTabView behind a stale sheet
- Fix onboarding reset: set hasCompletedOnboarding directly instead of calling
  completeOnboarding() which has an auth guard that fails after DataManager.clear()
- Stabilize Suite1 registration tests, Suite6 task tests, Suite7 contractor tests
- Add clean-slate-per-suite via AuthenticatedUITestCase reset state
- Improve test account seeding and screen object reliability

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey T
2026-04-02 16:11:47 -05:00
parent 00e9ed0a96
commit 5bb27034aa
16 changed files with 277 additions and 232 deletions

View File

@@ -14,10 +14,21 @@ final class Suite7_ContractorTests: AuthenticatedUITestCase {
// Test data tracking
var createdContractorNames: [String] = []
private static var hasCleanedStaleData = false
override func setUpWithError() throws {
try super.setUpWithError()
// One-time cleanup of stale contractors from previous test runs
if !Self.hasCleanedStaleData {
Self.hasCleanedStaleData = true
if let stale = TestAccountAPIClient.listContractors(token: session.token) {
for contractor in stale {
_ = TestAccountAPIClient.deleteContractor(token: session.token, id: contractor.id)
}
}
}
// Dismiss any open form from previous test
let cancelButton = app.buttons[AccessibilityIdentifiers.Contractor.formCancelButton].firstMatch
if cancelButton.exists { cancelButton.tap() }
@@ -133,6 +144,9 @@ final class Suite7_ContractorTests: AuthenticatedUITestCase {
let created = items.first(where: { $0.name.contains(name) }) {
cleaner.trackContractor(created.id)
}
// Navigate to contractors tab to trigger list refresh and reset scroll position
navigateToContractors()
}
private func findContractor(name: String, scrollIfNeeded: Bool = true) -> XCUIElement {
@@ -248,9 +262,10 @@ final class Suite7_ContractorTests: AuthenticatedUITestCase {
}
for (index, specialty) in specialties.enumerated() {
navigateToContractors()
let contractorName = "\(specialty) Expert \(timestamp)_\(index)"
let contractor = findContractor(name: contractorName)
XCTAssertTrue(contractor.exists, "\(specialty) contractor should exist in list")
XCTAssertTrue(contractor.waitForExistence(timeout: 10), "\(specialty) contractor should exist in list")
}
}
@@ -290,9 +305,10 @@ final class Suite7_ContractorTests: AuthenticatedUITestCase {
}
for (index, (_, format)) in phoneFormats.enumerated() {
navigateToContractors()
let contractorName = "\(format) Phone \(timestamp)_\(index)"
let contractor = findContractor(name: contractorName)
XCTAssertTrue(contractor.exists, "Contractor with \(format) phone should exist")
XCTAssertTrue(contractor.waitForExistence(timeout: 10), "Contractor with \(format) phone should exist")
}
}