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:
@@ -2,21 +2,15 @@ import XCTest
|
||||
|
||||
/// Comprehensive contractor testing suite covering all scenarios, edge cases, and variations
|
||||
/// This test suite is designed to be bulletproof and catch regressions early
|
||||
final class Suite7_ContractorTests: BaseUITestCase {
|
||||
override var includeResetStateLaunchArgument: Bool { false }
|
||||
|
||||
final class Suite7_ContractorTests: AuthenticatedTestCase {
|
||||
override var useSeededAccount: Bool { true }
|
||||
|
||||
// Test data tracking
|
||||
var createdContractorNames: [String] = []
|
||||
|
||||
override func setUpWithError() throws {
|
||||
try super.setUpWithError()
|
||||
|
||||
// Ensure user is logged in
|
||||
UITestHelpers.ensureLoggedIn(app: app)
|
||||
|
||||
// Navigate to Contractors tab
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
@@ -26,31 +20,27 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func navigateToContractorsTab() {
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
if contractorsTab.waitForExistence(timeout: 5) {
|
||||
if !contractorsTab.isSelected {
|
||||
contractorsTab.tap()
|
||||
sleep(3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func openContractorForm() -> Bool {
|
||||
let addButton = findAddContractorButton()
|
||||
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
|
||||
// Verify form opened using accessibility identifier
|
||||
let nameField = app.textFields[AccessibilityIdentifiers.Contractor.nameField]
|
||||
return nameField.waitForExistence(timeout: 5)
|
||||
}
|
||||
|
||||
private func findAddContractorButton() -> XCUIElement {
|
||||
sleep(2)
|
||||
|
||||
// Look for add button by various methods
|
||||
// Try accessibility identifier first
|
||||
let addButtonById = app.buttons[AccessibilityIdentifiers.Contractor.addButton]
|
||||
if addButtonById.waitForExistence(timeout: 5) && addButtonById.isEnabled {
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
// Fallback: look for add button by label in nav bar
|
||||
let navBarButtons = app.navigationBars.buttons
|
||||
for i in 0..<navBarButtons.count {
|
||||
let button = navBarButtons.element(boundBy: i)
|
||||
@@ -61,14 +51,22 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: look for any button with plus icon
|
||||
// Last resort: look for any button with plus icon
|
||||
return app.buttons.containing(NSPredicate(format: "label CONTAINS 'plus'")).firstMatch
|
||||
}
|
||||
|
||||
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 field isn't hidden behind it
|
||||
app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1)).tap()
|
||||
sleep(1)
|
||||
if !field.isHittable {
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
}
|
||||
field.tap()
|
||||
sleep(2) // Wait for keyboard to settle
|
||||
field.typeText(text)
|
||||
}
|
||||
}
|
||||
@@ -101,7 +99,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
|
||||
private func createContractor(
|
||||
name: String,
|
||||
phone: String = "555-123-4567",
|
||||
phone: String? = nil,
|
||||
email: String? = nil,
|
||||
company: String? = nil,
|
||||
specialty: String? = nil,
|
||||
@@ -112,10 +110,17 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
// Fill name
|
||||
let nameField = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] 'Name'")).firstMatch
|
||||
nameField.tap()
|
||||
sleep(1) // Wait for keyboard
|
||||
nameField.typeText(name)
|
||||
|
||||
// Fill phone (required field)
|
||||
fillTextField(placeholder: "Phone", text: phone)
|
||||
// Dismiss keyboard before switching to phone (phonePad keyboard type causes focus issues)
|
||||
app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1)).tap()
|
||||
sleep(1)
|
||||
|
||||
// Fill phone (optional)
|
||||
if let phone = phone {
|
||||
fillTextField(placeholder: "Phone", text: phone)
|
||||
}
|
||||
|
||||
// Fill optional fields
|
||||
if let email = email {
|
||||
@@ -137,10 +142,10 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
sleep(1)
|
||||
}
|
||||
|
||||
// Add button (for creating new contractors)
|
||||
let addButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Add'")).firstMatch
|
||||
guard addButton.exists else { return false }
|
||||
addButton.tap()
|
||||
// Submit button (accessibility identifier is the same for Add/Save)
|
||||
let submitButton = app.buttons[AccessibilityIdentifiers.Contractor.saveButton]
|
||||
guard submitButton.exists else { return false }
|
||||
submitButton.tap()
|
||||
|
||||
sleep(4) // Wait for API call
|
||||
|
||||
@@ -216,10 +221,10 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
app.swipeUp()
|
||||
sleep(1)
|
||||
|
||||
// When creating, button should say "Add"
|
||||
let addButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Add'")).firstMatch
|
||||
XCTAssertTrue(addButton.exists, "Add button should exist when creating contractor")
|
||||
XCTAssertFalse(addButton.isEnabled, "Add button should be disabled when name is empty")
|
||||
// Submit button should exist but be disabled when name is empty
|
||||
let submitButton = app.buttons[AccessibilityIdentifiers.Contractor.saveButton]
|
||||
XCTAssertTrue(submitButton.exists, "Submit button should exist when creating contractor")
|
||||
XCTAssertFalse(submitButton.isEnabled, "Submit button should be disabled when name is empty")
|
||||
}
|
||||
|
||||
func test02_cancelContractorCreation() {
|
||||
@@ -267,7 +272,6 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
|
||||
let success = createContractor(
|
||||
name: contractorName,
|
||||
phone: "555-987-6543",
|
||||
email: "jane.smith@example.com",
|
||||
company: "Smith Plumbing Inc",
|
||||
specialty: "Plumbing"
|
||||
@@ -287,7 +291,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
let success = createContractor(name: contractorName, specialty: specialty)
|
||||
XCTAssertTrue(success, "Should create \(specialty) contractor")
|
||||
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
@@ -307,7 +311,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
let success = createContractor(name: contractorName)
|
||||
XCTAssertTrue(success, "Should create contractor \(i)")
|
||||
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
@@ -335,7 +339,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
let success = createContractor(name: contractorName, phone: phone)
|
||||
XCTAssertTrue(success, "Should create contractor with \(format) phone format")
|
||||
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
}
|
||||
|
||||
@@ -363,7 +367,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
let success = createContractor(name: contractorName, email: email)
|
||||
XCTAssertTrue(success, "Should create contractor with email: \(email)")
|
||||
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
@@ -428,7 +432,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap contractor
|
||||
@@ -452,8 +456,8 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
sleep(1)
|
||||
nameField.typeText(newName)
|
||||
|
||||
// Save (when editing, button should say "Save")
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
// Save (uses same accessibility identifier for Add/Save)
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Contractor.saveButton]
|
||||
if saveButton.exists {
|
||||
saveButton.tap()
|
||||
sleep(3)
|
||||
@@ -483,7 +487,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
|
||||
// Find and tap contractor
|
||||
@@ -553,8 +557,8 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// Save (when editing, button should say "Save")
|
||||
let saveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Save'")).firstMatch
|
||||
// Save (uses same accessibility identifier for Add/Save)
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Contractor.saveButton]
|
||||
XCTAssertTrue(saveButton.exists, "Save button should exist when editing contractor")
|
||||
saveButton.tap()
|
||||
sleep(4)
|
||||
@@ -563,7 +567,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
createdContractorNames.append(newName)
|
||||
|
||||
// Verify updated contractor appears in list with new name
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
let updatedContractor = findContractor(name: newName)
|
||||
XCTAssertTrue(updatedContractor.exists, "Contractor should show updated name in list")
|
||||
@@ -593,7 +597,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
|
||||
func test15_navigateFromContractorsToOtherTabs() {
|
||||
// From Contractors tab
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
|
||||
// Navigate to Residences
|
||||
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
|
||||
@@ -622,7 +626,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
}
|
||||
|
||||
func test16_refreshContractorsList() {
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
|
||||
// Pull to refresh (if implemented) or use refresh button
|
||||
@@ -647,7 +651,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
|
||||
// Tap on contractor
|
||||
@@ -675,7 +679,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
return
|
||||
}
|
||||
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
|
||||
// Verify contractor exists
|
||||
@@ -689,7 +693,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
sleep(3)
|
||||
|
||||
// Navigate back to contractors
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
|
||||
// Verify contractor still exists
|
||||
@@ -701,7 +705,7 @@ final class Suite7_ContractorTests: BaseUITestCase {
|
||||
|
||||
func test19_contractorListPerformance() {
|
||||
measure(metrics: [XCTClockMetric(), XCTMemoryMetric()]) {
|
||||
navigateToContractorsTab()
|
||||
navigateToContractors()
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user