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

@@ -4,9 +4,10 @@ import XCTest
///
/// Test Plan IDs: TASK-010, TASK-012, plus create/edit flows.
/// Data is seeded via API and cleaned up in tearDown.
final class TaskIntegrationTests: AuthenticatedTestCase {
override var useSeededAccount: Bool { true }
final class TaskIntegrationTests: AuthenticatedUITestCase {
override var needsAPISession: Bool { true }
override var testCredentials: (username: String, password: String) { ("admin", "test1234") }
override var apiCredentials: (username: String, password: String) { ("admin", "test1234") }
// MARK: - Create Task
@@ -39,6 +40,7 @@ final class TaskIntegrationTests: AuthenticatedTestCase {
titleField.waitForExistenceOrFail(timeout: defaultTimeout)
let uniqueTitle = "IntTest Task \(Int(Date().timeIntervalSince1970))"
titleField.forceTap()
_ = app.keyboards.firstMatch.waitForExistence(timeout: 3)
titleField.typeText(uniqueTitle)
let saveButton = app.buttons[AccessibilityIdentifiers.Task.saveButton]
@@ -48,7 +50,7 @@ final class TaskIntegrationTests: AuthenticatedTestCase {
let newTask = app.staticTexts[uniqueTitle]
XCTAssertTrue(
newTask.waitForExistence(timeout: longTimeout),
newTask.waitForExistence(timeout: loginTimeout),
"Newly created task should appear"
)
}
@@ -101,7 +103,7 @@ final class TaskIntegrationTests: AuthenticatedTestCase {
// Pull to refresh until the cancelled task is visible
let taskText = app.staticTexts[task.title]
pullToRefreshUntilVisible(taskText)
guard taskText.waitForExistence(timeout: longTimeout) else {
guard taskText.waitForExistence(timeout: loginTimeout) else {
throw XCTSkip("Cancelled task '\(task.title)' not visible — may require a Cancelled filter to be active")
}
taskText.forceTap()
@@ -126,74 +128,6 @@ final class TaskIntegrationTests: AuthenticatedTestCase {
)
}
// MARK: - TASK-004: Create Task from Template
func test16_createTaskFromTemplate() throws {
// Seed a residence so template-created tasks have a valid target
cleaner.seedResidence(name: "Template Test Residence \(Int(Date().timeIntervalSince1970))")
navigateToTasks()
// Tap the add task button (or empty-state equivalent)
let addButton = app.buttons[AccessibilityIdentifiers.Task.addButton].firstMatch
let emptyAddButton = app.buttons.containing(
NSPredicate(format: "label CONTAINS[c] 'Add' OR label CONTAINS[c] 'Create'")
).firstMatch
let addVisible = addButton.waitForExistence(timeout: defaultTimeout) || emptyAddButton.waitForExistence(timeout: 3)
XCTAssertTrue(addVisible, "An add/create task button should be visible on the tasks screen")
if addButton.exists && addButton.isHittable {
addButton.forceTap()
} else {
emptyAddButton.forceTap()
}
// Look for a Templates or Browse Templates option within the add-task flow.
// NOTE: The exact accessibility identifier for the template browser is not yet defined
// in AccessibilityIdentifiers.swift. The identifiers below use the pattern established
// in the codebase (e.g., "TaskForm.TemplatesButton") and will need to be wired up in
// the SwiftUI view when the template browser feature is implemented.
let templateButton = app.buttons.containing(
NSPredicate(format: "label CONTAINS[c] 'Template' OR label CONTAINS[c] 'Browse'")
).firstMatch
guard templateButton.waitForExistence(timeout: defaultTimeout) else {
throw XCTSkip("Template browser not yet reachable from the add-task flow — skipping")
}
templateButton.forceTap()
// Select the first available template
let firstTemplate = app.cells.firstMatch
guard firstTemplate.waitForExistence(timeout: defaultTimeout) else {
throw XCTSkip("No templates available in template browser — skipping")
}
firstTemplate.forceTap()
// After selecting a template the form should be pre-filled the title field should
// contain something (i.e., not be empty)
let titleField = app.textFields[AccessibilityIdentifiers.Task.titleField]
titleField.waitForExistenceOrFail(timeout: defaultTimeout)
let preFilledTitle = titleField.value as? String ?? ""
XCTAssertFalse(
preFilledTitle.isEmpty,
"Title field should be pre-filled by the selected template"
)
// Save the templated task
let saveButton = app.buttons[AccessibilityIdentifiers.Task.saveButton]
let scrollContainer = app.scrollViews.firstMatch.exists ? app.scrollViews.firstMatch : app.collectionViews.firstMatch
saveButton.scrollIntoView(in: scrollContainer)
saveButton.forceTap()
// The task should now appear in the list
let savedTask = app.staticTexts[preFilledTitle]
XCTAssertTrue(
savedTask.waitForExistence(timeout: longTimeout),
"Task created from template ('\(preFilledTitle)') should appear in the task list"
)
}
// MARK: - TASK-012: Delete Task
func testTASK012_DeleteTaskUpdatesViews() {
@@ -219,6 +153,7 @@ final class TaskIntegrationTests: AuthenticatedTestCase {
titleField.waitForExistenceOrFail(timeout: defaultTimeout)
let uniqueTitle = "Delete Task \(Int(Date().timeIntervalSince1970))"
titleField.forceTap()
_ = app.keyboards.firstMatch.waitForExistence(timeout: 3)
titleField.typeText(uniqueTitle)
let saveButton = app.buttons[AccessibilityIdentifiers.Task.saveButton]
@@ -230,7 +165,7 @@ final class TaskIntegrationTests: AuthenticatedTestCase {
// Wait for the task to appear in the Kanban board
let taskText = app.staticTexts[uniqueTitle]
taskText.waitForExistenceOrFail(timeout: longTimeout)
taskText.waitForExistenceOrFail(timeout: loginTimeout)
// Tap the "Actions" menu on the task card to reveal cancel option
let actionsMenu = app.buttons.containing(
@@ -260,16 +195,19 @@ final class TaskIntegrationTests: AuthenticatedTestCase {
).firstMatch
let alertConfirmButton = app.buttons[AccessibilityIdentifiers.Alert.confirmButton]
if alertConfirmButton.waitForExistence(timeout: shortTimeout) {
if alertConfirmButton.waitForExistence(timeout: defaultTimeout) {
alertConfirmButton.tap()
} else if confirmDelete.waitForExistence(timeout: shortTimeout) {
} else if confirmDelete.waitForExistence(timeout: defaultTimeout) {
confirmDelete.tap()
}
// Refresh the task list (kanban uses toolbar button, not pull-to-refresh)
refreshTasks()
// Verify the task is removed or moved to a different column
let deletedTask = app.staticTexts[uniqueTitle]
XCTAssertTrue(
deletedTask.waitForNonExistence(timeout: longTimeout),
deletedTask.waitForNonExistence(timeout: loginTimeout),
"Cancelled task should no longer appear in active views"
)
}