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

@@ -2,22 +2,16 @@ import XCTest
/// Comprehensive documents and warranties testing suite covering all scenarios, edge cases, and variations
/// Tests both document types (permits, receipts, etc.) and warranties with filtering, searching, and CRUD operations
final class Suite8_DocumentWarrantyTests: BaseUITestCase {
override var includeResetStateLaunchArgument: Bool { false }
final class Suite8_DocumentWarrantyTests: AuthenticatedTestCase {
override var useSeededAccount: Bool { true }
// Test data tracking
var createdDocumentTitles: [String] = []
var currentResidenceId: Int32?
override func setUpWithError() throws {
try super.setUpWithError()
// Ensure user is logged in
UITestHelpers.ensureLoggedIn(app: app)
// Navigate to a residence first (documents are residence-specific)
navigateToFirstResidence()
navigateToDocuments()
}
override func tearDownWithError() throws {
@@ -27,32 +21,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
// MARK: - Helper Methods
private func navigateToFirstResidence() {
// Tap Residences tab
let residencesTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch
if residencesTab.waitForExistence(timeout: 5) {
residencesTab.tap()
sleep(3)
}
// Tap first residence card
let firstResidence = app.collectionViews.cells.firstMatch
if firstResidence.waitForExistence(timeout: 5) {
firstResidence.tap()
sleep(2)
}
}
private func navigateToDocumentsTab() {
// Look for Documents tab or navigation link
let documentsButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Documents' OR label CONTAINS[c] 'Warranties'")).firstMatch
if documentsButton.waitForExistence(timeout: 5) {
documentsButton.tap()
sleep(3)
}
}
private func openDocumentForm() -> Bool {
let addButton = findAddButton()
guard addButton.exists && addButton.isEnabled else { return false }
@@ -86,6 +55,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
let field = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS[c] '\(placeholder)'")).firstMatch
if field.exists {
field.tap()
sleep(1) // Wait for keyboard to appear
field.typeText(text)
}
}
@@ -94,6 +64,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
let textEditor = app.textViews.firstMatch
if textEditor.exists {
textEditor.tap()
sleep(1) // Wait for keyboard to appear
textEditor.typeText(text)
}
}
@@ -264,20 +235,19 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
// MARK: Navigation Tests
func test01_NavigateToDocumentsScreen() {
navigateToDocumentsTab()
// Verify we're on documents screen
let navigationTitle = app.navigationBars["Documents & Warranties"]
XCTAssertTrue(navigationTitle.waitForExistence(timeout: 5), "Should navigate to Documents & Warranties screen")
// Verify tabs are visible
navigateToDocuments()
sleep(2) // Wait for documents screen to load
// Verify we're on documents screen by checking for the segmented control tabs
let warrantiesTab = app.buttons["Warranties"]
let documentsTab = app.buttons["Documents"]
XCTAssertTrue(warrantiesTab.exists || documentsTab.exists, "Should see tab switcher")
let warrantiesExists = warrantiesTab.waitForExistence(timeout: 10)
let documentsExists = documentsTab.waitForExistence(timeout: 3)
XCTAssertTrue(warrantiesExists || documentsExists, "Should see tab switcher on Documents screen")
}
func test02_SwitchBetweenWarrantiesAndDocuments() {
navigateToDocumentsTab()
navigateToDocuments()
// Start on warranties tab
switchToWarrantiesTab()
@@ -299,7 +269,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
// MARK: Document Creation Tests
func test03_CreateDocumentWithAllFields() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
XCTAssertTrue(openDocumentForm(), "Should open document form")
@@ -325,7 +295,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test04_CreateDocumentWithMinimalFields() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
XCTAssertTrue(openDocumentForm(), "Should open document form")
@@ -347,7 +317,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test05_CreateDocumentWithEmptyTitle_ShouldFail() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
XCTAssertTrue(openDocumentForm(), "Should open document form")
@@ -374,7 +344,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
// MARK: Warranty Creation Tests
func test06_CreateWarrantyWithAllFields() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
XCTAssertTrue(openDocumentForm(), "Should open warranty form")
@@ -406,7 +376,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test07_CreateWarrantyWithFutureDates() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
XCTAssertTrue(openDocumentForm(), "Should open warranty form")
@@ -432,7 +402,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test08_CreateExpiredWarranty() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
XCTAssertTrue(openDocumentForm(), "Should open warranty form")
@@ -465,7 +435,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
// MARK: Search and Filter Tests
func test09_SearchDocumentsByTitle() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
// Create a test document first
@@ -489,7 +459,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test10_FilterWarrantiesByCategory() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
// Apply category filter
@@ -506,7 +476,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test11_FilterDocumentsByType() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
// Apply type filter
@@ -523,7 +493,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test12_ToggleActiveWarrantiesFilter() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
// Toggle active filter off
@@ -542,7 +512,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
// MARK: Document Detail Tests
func test13_ViewDocumentDetail() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
// Create a document
@@ -573,7 +543,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test14_ViewWarrantyDetailWithDates() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
// Create a warranty
@@ -612,7 +582,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
// MARK: Edit Tests
func test15_EditDocumentTitle() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
// Create document
@@ -661,7 +631,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test16_EditWarrantyDates() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
// Create warranty
@@ -703,7 +673,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
// MARK: Delete Tests
func test17_DeleteDocument() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
// Create document to delete
@@ -744,7 +714,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test18_DeleteWarranty() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
// Create warranty to delete
@@ -786,7 +756,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
// MARK: Edge Cases and Error Handling
func test19_CancelDocumentCreation() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
XCTAssertTrue(openDocumentForm(), "Should open form")
@@ -806,7 +776,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test20_HandleEmptyDocumentsList() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
// Apply very specific filter to get empty list
@@ -825,7 +795,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test21_HandleEmptyWarrantiesList() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
// Search for non-existent warranty
@@ -841,7 +811,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test22_CreateDocumentWithLongTitle() {
navigateToDocumentsTab()
navigateToDocuments()
switchToDocumentsTab()
XCTAssertTrue(openDocumentForm(), "Should open form")
@@ -863,7 +833,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test23_CreateWarrantyWithSpecialCharacters() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
XCTAssertTrue(openDocumentForm(), "Should open form")
@@ -886,7 +856,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test24_RapidTabSwitching() {
navigateToDocumentsTab()
navigateToDocuments()
// Rapidly switch between tabs
for _ in 0..<5 {
@@ -903,7 +873,7 @@ final class Suite8_DocumentWarrantyTests: BaseUITestCase {
}
func test25_MultipleFiltersCombined() {
navigateToDocumentsTab()
navigateToDocuments()
switchToWarrantiesTab()
// Apply multiple filters