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>
This commit is contained in:
treyt
2026-03-15 17:32:13 -05:00
parent cf2e6d8bcc
commit 5c360a2796
57 changed files with 3781 additions and 928 deletions

View File

@@ -10,22 +10,12 @@ import XCTest
/// 3. Edit/update tests
/// 4. Delete/remove tests (none currently)
/// 5. Navigation/view tests
final class Suite5_TaskTests: BaseUITestCase {
override var includeResetStateLaunchArgument: Bool { false }
final class Suite5_TaskTests: AuthenticatedTestCase {
override var useSeededAccount: Bool { true }
override func setUpWithError() throws {
try super.setUpWithError()
// Ensure user is logged in
UITestHelpers.ensureLoggedIn(app: app)
// CRITICAL: Ensure at least one residence exists
// Tasks are disabled if no residences exist
ensureResidenceExists()
// Now navigate to Tasks tab
navigateToTasksTab()
navigateToTasks()
}
override func tearDownWithError() throws {
@@ -34,82 +24,6 @@ final class Suite5_TaskTests: BaseUITestCase {
// MARK: - Helper Methods
/// Ensures at least one residence exists (required for tasks to work)
private func ensureResidenceExists() {
// Navigate to Residences tab
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
if residencesTab.waitForExistence(timeout: 5) {
residencesTab.tap()
sleep(2)
// Check if we have any residences
// Look for the add button - if we see "Add a property" text or empty state, create one
let emptyStateText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No properties' OR label CONTAINS[c] 'No residences'")).firstMatch
if emptyStateText.exists {
// No residences exist, create a quick one
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton]
if addButton.waitForExistence(timeout: 5) {
addButton.tap()
sleep(2)
// Fill minimal required fields
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
if nameField.waitForExistence(timeout: 5) {
nameField.tap()
nameField.typeText("Test Home for Tasks")
// Scroll to address fields
app.swipeUp()
sleep(1)
// Fill required address fields
let streetField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Street'")).firstMatch
if streetField.exists {
streetField.tap()
streetField.typeText("123 Test St")
}
let cityField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'City'")).firstMatch
if cityField.exists {
cityField.tap()
cityField.typeText("TestCity")
}
let stateField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'State'")).firstMatch
if stateField.exists {
stateField.tap()
stateField.typeText("TS")
}
let postalField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Postal' OR placeholderValue CONTAINS[c] 'Zip'")).firstMatch
if postalField.exists {
postalField.tap()
postalField.typeText("12345")
}
// Save
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
if saveButton.exists {
saveButton.tap()
sleep(3) // Wait for save to complete
}
}
}
}
}
}
private func navigateToTasksTab() {
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
if tasksTab.waitForExistence(timeout: 5) {
if !tasksTab.isSelected {
tasksTab.tap()
sleep(3) // Give it time to load
}
}
}
/// Finds the Add Task button using multiple strategies
/// The button exists in two places:
/// 1. Toolbar (always visible when residences exist)
@@ -157,7 +71,7 @@ final class Suite5_TaskTests: BaseUITestCase {
func test01_cancelTaskCreation() {
// Given: User is on add task form
navigateToTasksTab()
navigateToTasks()
sleep(3)
let addButton = findAddTaskButton()
@@ -194,7 +108,7 @@ final class Suite5_TaskTests: BaseUITestCase {
func test03_viewTasksList() {
// Given: User is on Tasks tab
navigateToTasksTab()
navigateToTasks()
sleep(3)
// Then: Tasks screen should be visible
@@ -205,7 +119,7 @@ final class Suite5_TaskTests: BaseUITestCase {
func test04_addTaskButtonExists() {
// Given: User is on Tasks tab with at least one residence
navigateToTasksTab()
navigateToTasks()
sleep(3)
// Then: Add task button should exist and be enabled
@@ -216,7 +130,7 @@ final class Suite5_TaskTests: BaseUITestCase {
func test05_navigateToAddTask() {
// Given: User is on Tasks tab
navigateToTasksTab()
navigateToTasks()
sleep(3)
// When: User taps add task button
@@ -231,15 +145,15 @@ final class Suite5_TaskTests: BaseUITestCase {
let titleField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Title' OR placeholderValue CONTAINS[c] 'Task'")).firstMatch
XCTAssertTrue(titleField.waitForExistence(timeout: 5), "Task title field should appear in add form")
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
XCTAssertTrue(saveButton.exists, "Save button should exist in add task form")
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save' OR label CONTAINS[c] 'Add'")).firstMatch
XCTAssertTrue(saveButton.exists, "Save/Add button should exist in add task form")
}
// MARK: - 3. Creation Tests
func test06_createBasicTask() {
// Given: User is on Tasks tab
navigateToTasksTab()
navigateToTasks()
sleep(3)
// When: User taps add task button
@@ -272,9 +186,9 @@ final class Suite5_TaskTests: BaseUITestCase {
app.swipeUp()
sleep(1)
// When: User taps save
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
XCTAssertTrue(saveButton.exists, "Save button should exist")
// When: User taps save/add
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save' OR label CONTAINS[c] 'Add'")).firstMatch
XCTAssertTrue(saveButton.exists, "Save/Add button should exist")
saveButton.tap()
// Then: Should return to tasks list
@@ -293,7 +207,7 @@ final class Suite5_TaskTests: BaseUITestCase {
func test07_viewTaskDetails() {
// Given: User is on Tasks tab and at least one task exists
navigateToTasksTab()
navigateToTasks()
sleep(3)
// Look for any task in the list
@@ -322,7 +236,7 @@ final class Suite5_TaskTests: BaseUITestCase {
func test08_navigateToContractors() {
// Given: User is on Tasks tab
navigateToTasksTab()
navigateToTasks()
sleep(1)
// When: User taps Contractors tab
@@ -337,11 +251,11 @@ final class Suite5_TaskTests: BaseUITestCase {
func test09_navigateToDocuments() {
// Given: User is on Tasks tab
navigateToTasksTab()
navigateToTasks()
sleep(1)
// When: User taps Documents tab
let documentsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Documents'")).firstMatch
let documentsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Doc'")).firstMatch
XCTAssertTrue(documentsTab.waitForExistence(timeout: 5), "Documents tab should exist")
documentsTab.tap()
sleep(1)
@@ -352,7 +266,7 @@ final class Suite5_TaskTests: BaseUITestCase {
func test10_navigateBetweenTabs() {
// Given: User is on Tasks tab
navigateToTasksTab()
navigateToTasks()
sleep(1)
// When: User navigates to Residences tab