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:
@@ -13,7 +13,7 @@ final class ContractorIntegrationTests: AuthenticatedTestCase {
|
||||
func testCON002_CreateContractorMinimalFields() {
|
||||
navigateToContractors()
|
||||
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Contractor.addButton]
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Contractor.addButton].firstMatch
|
||||
let emptyState = app.otherElements[AccessibilityIdentifiers.Contractor.emptyStateView]
|
||||
let contractorList = app.otherElements[AccessibilityIdentifiers.Contractor.contractorsList]
|
||||
|
||||
@@ -38,13 +38,37 @@ final class ContractorIntegrationTests: AuthenticatedTestCase {
|
||||
nameField.forceTap()
|
||||
nameField.typeText(uniqueName)
|
||||
|
||||
// Dismiss keyboard before tapping save (toolbar button may not respond with keyboard up)
|
||||
app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1)).tap()
|
||||
sleep(1)
|
||||
|
||||
// Save button is in the toolbar (top of sheet)
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Contractor.saveButton]
|
||||
saveButton.scrollIntoView(in: app.scrollViews.firstMatch)
|
||||
saveButton.waitForExistenceOrFail(timeout: defaultTimeout)
|
||||
saveButton.forceTap()
|
||||
|
||||
// Wait for the sheet to dismiss (save triggers async API call + dismiss)
|
||||
let nameFieldGone = nameField.waitForNonExistence(timeout: longTimeout)
|
||||
if !nameFieldGone {
|
||||
// If still showing the form, try tapping save again
|
||||
if saveButton.exists {
|
||||
saveButton.forceTap()
|
||||
_ = nameField.waitForNonExistence(timeout: longTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
// Pull to refresh to pick up the newly created contractor
|
||||
sleep(2)
|
||||
pullToRefresh()
|
||||
|
||||
// Wait for the contractor list to show the new entry
|
||||
let newContractor = app.staticTexts[uniqueName]
|
||||
if !newContractor.waitForExistence(timeout: defaultTimeout) {
|
||||
// Pull to refresh again in case the first one was too early
|
||||
pullToRefresh()
|
||||
}
|
||||
XCTAssertTrue(
|
||||
newContractor.waitForExistence(timeout: longTimeout),
|
||||
newContractor.waitForExistence(timeout: defaultTimeout),
|
||||
"Newly created contractor should appear in list"
|
||||
)
|
||||
}
|
||||
@@ -57,33 +81,69 @@ final class ContractorIntegrationTests: AuthenticatedTestCase {
|
||||
|
||||
navigateToContractors()
|
||||
|
||||
// Find and tap the seeded contractor
|
||||
// Pull to refresh until the seeded contractor is visible
|
||||
let card = app.staticTexts[contractor.name]
|
||||
pullToRefreshUntilVisible(card)
|
||||
card.waitForExistenceOrFail(timeout: longTimeout)
|
||||
card.forceTap()
|
||||
|
||||
// Tap the ellipsis menu to reveal edit/delete options
|
||||
let menuButton = app.buttons[AccessibilityIdentifiers.Contractor.menuButton]
|
||||
if menuButton.waitForExistence(timeout: defaultTimeout) {
|
||||
menuButton.forceTap()
|
||||
} else {
|
||||
// Fallback: last nav bar button
|
||||
let navBarMenu = app.navigationBars.buttons.element(boundBy: app.navigationBars.buttons.count - 1)
|
||||
if navBarMenu.exists { navBarMenu.forceTap() }
|
||||
}
|
||||
|
||||
// Tap edit
|
||||
let editButton = app.buttons[AccessibilityIdentifiers.Contractor.editButton]
|
||||
editButton.waitForExistenceOrFail(timeout: defaultTimeout)
|
||||
editButton.forceTap()
|
||||
if !editButton.waitForExistence(timeout: defaultTimeout) {
|
||||
// Fallback: look for any Edit button
|
||||
let anyEdit = app.buttons.containing(
|
||||
NSPredicate(format: "label CONTAINS[c] 'Edit'")
|
||||
).firstMatch
|
||||
anyEdit.waitForExistenceOrFail(timeout: 5)
|
||||
anyEdit.forceTap()
|
||||
} else {
|
||||
editButton.forceTap()
|
||||
}
|
||||
|
||||
// Update name
|
||||
// Update name — clear existing text using delete keys
|
||||
let nameField = app.textFields[AccessibilityIdentifiers.Contractor.nameField]
|
||||
nameField.waitForExistenceOrFail(timeout: defaultTimeout)
|
||||
nameField.forceTap()
|
||||
nameField.press(forDuration: 1.0)
|
||||
let selectAll = app.menuItems["Select All"]
|
||||
if selectAll.waitForExistence(timeout: 2) {
|
||||
selectAll.tap()
|
||||
}
|
||||
sleep(1)
|
||||
|
||||
// Move cursor to end and delete all characters
|
||||
let currentValue = (nameField.value as? String) ?? ""
|
||||
let deleteCount = max(currentValue.count, 50) + 5
|
||||
let deleteString = String(repeating: XCUIKeyboardKey.delete.rawValue, count: deleteCount)
|
||||
nameField.typeText(deleteString)
|
||||
|
||||
let updatedName = "Updated Contractor \(Int(Date().timeIntervalSince1970))"
|
||||
nameField.typeText(updatedName)
|
||||
|
||||
// Dismiss keyboard before tapping save
|
||||
app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1)).tap()
|
||||
sleep(1)
|
||||
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Contractor.saveButton]
|
||||
saveButton.scrollIntoView(in: app.scrollViews.firstMatch)
|
||||
saveButton.waitForExistenceOrFail(timeout: defaultTimeout)
|
||||
saveButton.forceTap()
|
||||
|
||||
// After save, the form dismisses back to detail view. Navigate back to list.
|
||||
sleep(3)
|
||||
let backButton = app.navigationBars.buttons.element(boundBy: 0)
|
||||
if backButton.waitForExistence(timeout: 5) {
|
||||
backButton.tap()
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Pull to refresh to pick up the edit
|
||||
pullToRefresh()
|
||||
|
||||
let updatedText = app.staticTexts[updatedName]
|
||||
XCTAssertTrue(
|
||||
updatedText.waitForExistence(timeout: longTimeout),
|
||||
@@ -99,8 +159,9 @@ final class ContractorIntegrationTests: AuthenticatedTestCase {
|
||||
|
||||
navigateToContractors()
|
||||
|
||||
// Find and open the seeded contractor
|
||||
// Pull to refresh until the seeded contractor is visible
|
||||
let card = app.staticTexts[contractor.name]
|
||||
pullToRefreshUntilVisible(card)
|
||||
card.waitForExistenceOrFail(timeout: longTimeout)
|
||||
card.forceTap()
|
||||
|
||||
@@ -155,8 +216,9 @@ final class ContractorIntegrationTests: AuthenticatedTestCase {
|
||||
|
||||
navigateToResidences()
|
||||
|
||||
// Open the seeded residence's detail view
|
||||
// Pull to refresh until the seeded residence is visible
|
||||
let residenceText = app.staticTexts[residence.name]
|
||||
pullToRefreshUntilVisible(residenceText)
|
||||
residenceText.waitForExistenceOrFail(timeout: longTimeout)
|
||||
residenceText.forceTap()
|
||||
|
||||
@@ -181,31 +243,88 @@ final class ContractorIntegrationTests: AuthenticatedTestCase {
|
||||
// MARK: - CON-006: Delete Contractor
|
||||
|
||||
func testCON006_DeleteContractor() {
|
||||
// Seed a contractor via API — don't track since we'll delete through UI
|
||||
// Seed a contractor via API — don't track with cleaner since we'll delete via UI
|
||||
let deleteName = "Delete Contractor \(Int(Date().timeIntervalSince1970))"
|
||||
TestDataSeeder.createContractor(token: session.token, name: deleteName)
|
||||
|
||||
navigateToContractors()
|
||||
|
||||
// Pull to refresh until the seeded contractor is visible
|
||||
let target = app.staticTexts[deleteName]
|
||||
pullToRefreshUntilVisible(target)
|
||||
target.waitForExistenceOrFail(timeout: longTimeout)
|
||||
|
||||
// Open the contractor's detail view
|
||||
target.forceTap()
|
||||
|
||||
// Wait for detail view to load
|
||||
let detailView = app.otherElements[AccessibilityIdentifiers.Contractor.detailView]
|
||||
_ = detailView.waitForExistence(timeout: defaultTimeout)
|
||||
sleep(2)
|
||||
|
||||
// Tap the ellipsis menu button
|
||||
// SwiftUI Menu can be a button, popUpButton, or image
|
||||
let menuButton = app.buttons[AccessibilityIdentifiers.Contractor.menuButton]
|
||||
let menuImage = app.images[AccessibilityIdentifiers.Contractor.menuButton]
|
||||
let menuPopUp = app.popUpButtons.firstMatch
|
||||
|
||||
if menuButton.waitForExistence(timeout: 5) {
|
||||
menuButton.forceTap()
|
||||
} else if menuImage.waitForExistence(timeout: 3) {
|
||||
menuImage.forceTap()
|
||||
} else if menuPopUp.waitForExistence(timeout: 3) {
|
||||
menuPopUp.forceTap()
|
||||
} else {
|
||||
// Debug: dump nav bar buttons to understand what's available
|
||||
let navButtons = app.navigationBars.buttons.allElementsBoundByIndex
|
||||
let navButtonInfo = navButtons.prefix(10).map { "[\($0.identifier)|\($0.label)]" }
|
||||
let allButtons = app.buttons.allElementsBoundByIndex
|
||||
let buttonInfo = allButtons.prefix(15).map { "[\($0.identifier)|\($0.label)]" }
|
||||
XCTFail("Could not find menu button. Nav bar buttons: \(navButtonInfo). All buttons: \(buttonInfo)")
|
||||
return
|
||||
}
|
||||
sleep(1)
|
||||
|
||||
// Find and tap "Delete" in the menu popup
|
||||
let deleteButton = app.buttons[AccessibilityIdentifiers.Contractor.deleteButton]
|
||||
deleteButton.waitForExistenceOrFail(timeout: defaultTimeout)
|
||||
deleteButton.forceTap()
|
||||
|
||||
let confirmButton = app.buttons[AccessibilityIdentifiers.Alert.confirmButton]
|
||||
let alertDelete = app.alerts.buttons.containing(
|
||||
NSPredicate(format: "label CONTAINS[c] 'Delete' OR label CONTAINS[c] 'Confirm'")
|
||||
).firstMatch
|
||||
|
||||
if confirmButton.waitForExistence(timeout: shortTimeout) {
|
||||
confirmButton.tap()
|
||||
} else if alertDelete.waitForExistence(timeout: shortTimeout) {
|
||||
alertDelete.tap()
|
||||
if deleteButton.waitForExistence(timeout: defaultTimeout) {
|
||||
deleteButton.forceTap()
|
||||
} else {
|
||||
let anyDelete = app.buttons.containing(
|
||||
NSPredicate(format: "label CONTAINS[c] 'Delete'")
|
||||
).firstMatch
|
||||
anyDelete.waitForExistenceOrFail(timeout: 5)
|
||||
anyDelete.forceTap()
|
||||
}
|
||||
|
||||
// Confirm the delete in the alert
|
||||
let alert = app.alerts.firstMatch
|
||||
alert.waitForExistenceOrFail(timeout: defaultTimeout)
|
||||
|
||||
let deleteLabel = alert.buttons["Delete"]
|
||||
if deleteLabel.waitForExistence(timeout: 3) {
|
||||
deleteLabel.tap()
|
||||
} else {
|
||||
// Fallback: tap any button containing "Delete"
|
||||
let anyDeleteBtn = alert.buttons.containing(
|
||||
NSPredicate(format: "label CONTAINS[c] 'Delete'")
|
||||
).firstMatch
|
||||
if anyDeleteBtn.exists {
|
||||
anyDeleteBtn.tap()
|
||||
} else {
|
||||
// Last resort: tap the last button (destructive buttons are last)
|
||||
let count = alert.buttons.count
|
||||
alert.buttons.element(boundBy: count > 0 ? count - 1 : 0).tap()
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for the detail view to dismiss and return to list
|
||||
sleep(3)
|
||||
|
||||
// Pull to refresh in case the list didn't auto-update
|
||||
pullToRefresh()
|
||||
|
||||
// Verify the contractor is no longer visible
|
||||
let deletedContractor = app.staticTexts[deleteName]
|
||||
XCTAssertTrue(
|
||||
deletedContractor.waitForNonExistence(timeout: longTimeout),
|
||||
|
||||
Reference in New Issue
Block a user