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:
@@ -10,21 +10,15 @@ import XCTest
|
||||
/// 4. Delete/remove tests (none currently)
|
||||
/// 5. Navigation/view tests
|
||||
/// 6. Performance tests
|
||||
final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
override var includeResetStateLaunchArgument: Bool { false }
|
||||
|
||||
final class Suite4_ComprehensiveResidenceTests: AuthenticatedTestCase {
|
||||
override var useSeededAccount: Bool { true }
|
||||
|
||||
// Test data tracking
|
||||
var createdResidenceNames: [String] = []
|
||||
|
||||
override func setUpWithError() throws {
|
||||
try super.setUpWithError()
|
||||
|
||||
// Ensure user is logged in
|
||||
UITestHelpers.ensureLoggedIn(app: app)
|
||||
|
||||
// Navigate to Residences tab
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
@@ -34,31 +28,26 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func navigateToResidencesTab() {
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
if residencesTab.waitForExistence(timeout: 5) {
|
||||
if !residencesTab.isSelected {
|
||||
residencesTab.tap()
|
||||
sleep(3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func openResidenceForm() -> Bool {
|
||||
let addButton = findAddResidenceButton()
|
||||
guard addButton.exists && addButton.isEnabled else { return false }
|
||||
addButton.tap()
|
||||
sleep(3)
|
||||
|
||||
// Verify form opened
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
return nameField.waitForExistence(timeout: 5)
|
||||
// Verify form opened - prefer accessibility identifier over placeholder
|
||||
let nameFieldById = app.textFields[AccessibilityIdentifiers.Residence.nameField].firstMatch
|
||||
if nameFieldById.waitForExistence(timeout: 5) {
|
||||
return true
|
||||
}
|
||||
// Fallback to placeholder matching
|
||||
let nameFieldByPlaceholder = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
return nameFieldByPlaceholder.waitForExistence(timeout: 3)
|
||||
}
|
||||
|
||||
private func findAddResidenceButton() -> XCUIElement {
|
||||
sleep(2)
|
||||
|
||||
let addButtonById = app.buttons[AccessibilityIdentifiers.Residence.addButton]
|
||||
let addButtonById = app.buttons[AccessibilityIdentifiers.Residence.addButton].firstMatch
|
||||
if addButtonById.exists && addButtonById.isEnabled {
|
||||
return addButtonById
|
||||
}
|
||||
@@ -78,8 +67,17 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
|
||||
private func fillTextField(placeholder: String, text: String) {
|
||||
let field = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] '\(placeholder)'")).firstMatch
|
||||
if field.exists {
|
||||
if field.waitForExistence(timeout: 5) {
|
||||
// Dismiss keyboard first so the field isn't hidden behind it
|
||||
app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1)).tap()
|
||||
sleep(1)
|
||||
// Scroll down to make sure field is visible
|
||||
if !field.isHittable {
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
}
|
||||
field.tap()
|
||||
sleep(2) // Wait for keyboard focus to settle
|
||||
field.typeText(text)
|
||||
}
|
||||
}
|
||||
@@ -121,28 +119,33 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
) -> Bool {
|
||||
guard openResidenceForm() else { return false }
|
||||
|
||||
// Fill name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
// Fill name - prefer accessibility identifier
|
||||
let nameFieldById = app.textFields[AccessibilityIdentifiers.Residence.nameField].firstMatch
|
||||
let nameFieldByPlaceholder = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
let nameField = nameFieldById.exists ? nameFieldById : nameFieldByPlaceholder
|
||||
nameField.tap()
|
||||
// Wait for keyboard to appear before typing
|
||||
let keyboard = app.keyboards.firstMatch
|
||||
_ = keyboard.waitForExistence(timeout: 3)
|
||||
nameField.typeText(name)
|
||||
|
||||
// Select property type
|
||||
selectPropertyType(type: propertyType)
|
||||
|
||||
// Scroll to address section
|
||||
if scrollBeforeAddress {
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
}
|
||||
// Dismiss keyboard before filling address fields
|
||||
app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1)).tap()
|
||||
sleep(1)
|
||||
|
||||
// Fill address fields
|
||||
// Fill address fields - fillTextField handles scrolling into view
|
||||
fillTextField(placeholder: "Street", text: street)
|
||||
fillTextField(placeholder: "City", text: city)
|
||||
fillTextField(placeholder: "State", text: state)
|
||||
fillTextField(placeholder: "Postal", text: postal)
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
// Submit form - button may be labeled "Add" (new) or "Save" (edit)
|
||||
let saveButtonById = app.buttons[AccessibilityIdentifiers.Residence.saveButton].firstMatch
|
||||
let saveButtonByLabel = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save' OR label CONTAINS[c] 'Add'")).firstMatch
|
||||
let saveButton = saveButtonById.exists ? saveButtonById : saveButtonByLabel
|
||||
guard saveButton.exists else { return false }
|
||||
saveButton.tap()
|
||||
|
||||
@@ -178,10 +181,12 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// Save button should be disabled when name is empty
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist")
|
||||
XCTAssertFalse(saveButton.isEnabled, "Save button should be disabled when name is empty")
|
||||
// Submit button should be disabled when name is empty (may be labeled "Add" or "Save")
|
||||
let saveButtonById = app.buttons[AccessibilityIdentifiers.Residence.saveButton].firstMatch
|
||||
let saveButtonByLabel = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save' OR label CONTAINS[c] 'Add'")).firstMatch
|
||||
let saveButton = saveButtonById.exists ? saveButtonById : saveButtonByLabel
|
||||
XCTAssertTrue(saveButton.exists, "Submit button should exist")
|
||||
XCTAssertFalse(saveButton.isEnabled, "Submit button should be disabled when name is empty")
|
||||
}
|
||||
|
||||
func test02_cancelResidenceCreation() {
|
||||
@@ -190,9 +195,14 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
// Fill some data
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
// Fill some data - prefer accessibility identifier
|
||||
let nameFieldById = app.textFields[AccessibilityIdentifiers.Residence.nameField].firstMatch
|
||||
let nameFieldByPlaceholder = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
let nameField = nameFieldById.exists ? nameFieldById : nameFieldByPlaceholder
|
||||
nameField.tap()
|
||||
// Wait for keyboard to appear before typing
|
||||
let keyboard = app.keyboards.firstMatch
|
||||
_ = keyboard.waitForExistence(timeout: 3)
|
||||
nameField.typeText("This will be canceled")
|
||||
|
||||
// Tap cancel
|
||||
@@ -232,7 +242,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
let success = createResidence(name: residenceName, propertyType: type)
|
||||
XCTAssertTrue(success, "Should create \(type) residence")
|
||||
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
@@ -252,7 +262,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
let success = createResidence(name: residenceName)
|
||||
XCTAssertTrue(success, "Should create residence \(i)")
|
||||
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
@@ -339,7 +349,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap residence
|
||||
@@ -354,13 +364,17 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
editButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Edit name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
// Edit name - prefer accessibility identifier
|
||||
let nameFieldById = app.textFields[AccessibilityIdentifiers.Residence.nameField].firstMatch
|
||||
let nameFieldByPlaceholder = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
let nameField = nameFieldById.exists ? nameFieldById : nameFieldByPlaceholder
|
||||
if nameField.exists {
|
||||
let element = app/*@START_MENU_TOKEN@*/.textFields["ResidenceForm.NameField"]/*[[".otherElements",".textFields[\"Original Name 1764809003\"]",".textFields[\"Property Name\"]",".textFields[\"ResidenceForm.NameField\"]"],[[[-1,3],[-1,2],[-1,1],[-1,0,1]],[[-1,3],[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/.firstMatch
|
||||
element.tap()
|
||||
element.tap()
|
||||
app/*@START_MENU_TOKEN@*/.menuItems["Select All"]/*[[".menuItems.containing(.staticText, identifier: \"Select All\")",".collectionViews.menuItems[\"Select All\"]",".menuItems[\"Select All\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.firstMatch.tap()
|
||||
nameField.tap()
|
||||
nameField.tap() // Double-tap to position cursor
|
||||
// Wait for keyboard to appear before interacting
|
||||
let keyboard = app.keyboards.firstMatch
|
||||
_ = keyboard.waitForExistence(timeout: 3)
|
||||
app.menuItems["Select All"].firstMatch.tap()
|
||||
nameField.typeText(newName)
|
||||
|
||||
// Save
|
||||
@@ -373,7 +387,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
createdResidenceNames.append(newName)
|
||||
|
||||
// Verify new name appears
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
let updatedResidence = findResidence(name: newName)
|
||||
XCTAssertTrue(updatedResidence.exists, "Residence should show updated name")
|
||||
@@ -397,7 +411,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap residence
|
||||
@@ -412,12 +426,16 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
editButton.tap()
|
||||
sleep(2)
|
||||
|
||||
// Update name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
// Update name - prefer accessibility identifier
|
||||
let nameFieldById = app.textFields[AccessibilityIdentifiers.Residence.nameField].firstMatch
|
||||
let nameFieldByPlaceholder = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
let nameField = nameFieldById.exists ? nameFieldById : nameFieldByPlaceholder
|
||||
XCTAssertTrue(nameField.exists, "Name field should exist")
|
||||
nameField.tap()
|
||||
nameField.doubleTap()
|
||||
sleep(1)
|
||||
// Wait for keyboard to appear before interacting
|
||||
let keyboard = app.keyboards.firstMatch
|
||||
_ = keyboard.waitForExistence(timeout: 3)
|
||||
if app.buttons["Select All"].exists {
|
||||
app.buttons["Select All"].tap()
|
||||
sleep(1)
|
||||
@@ -518,7 +536,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
createdResidenceNames.append(newName)
|
||||
|
||||
// Verify updated residence appears in list with new name
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
let updatedResidence = findResidence(name: newName)
|
||||
XCTAssertTrue(updatedResidence.exists, "Residence should show updated name in list")
|
||||
@@ -554,7 +572,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
|
||||
// Tap on residence
|
||||
@@ -572,7 +590,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
|
||||
func test14_navigateFromResidencesToOtherTabs() {
|
||||
// From Residences tab
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
|
||||
// Navigate to Tasks
|
||||
let tasksTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
@@ -601,7 +619,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
}
|
||||
|
||||
func test15_refreshResidencesList() {
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
|
||||
// Pull to refresh (if implemented) or use refresh button
|
||||
@@ -628,7 +646,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
|
||||
// Verify residence exists
|
||||
@@ -642,7 +660,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
sleep(3)
|
||||
|
||||
// Navigate back to residences
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
|
||||
// Verify residence still exists
|
||||
@@ -654,7 +672,7 @@ final class Suite4_ComprehensiveResidenceTests: BaseUITestCase {
|
||||
|
||||
func test17_residenceListPerformance() {
|
||||
measure(metrics: [XCTClockMetric(), XCTMemoryMetric()]) {
|
||||
navigateToResidencesTab()
|
||||
navigateToResidences()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user