From d545fd463c089c4f5756ddee7cba091c56c36f88 Mon Sep 17 00:00:00 2001 From: Trey T Date: Fri, 3 Apr 2026 17:21:31 -0500 Subject: [PATCH] Fix 10 failing UI tests: kanban scroll, menu-based edit, form submit reliability - Screens.swift: findTask() now scrolls through kanban columns (swipe left/right) to locate tasks rendered off-screen in LazyHGrid - Suite5: test06/07 use refreshTasks() instead of pullToRefresh() (kanban is horizontal), add API call before navigate for server processing delay - Suite6: test09 opens "Task actions" menu before tapping edit (no detail screen) - Suite8: submitForm() uses coordinate-based keyboard dismiss, retry tap, and longer timeout; test22/23 re-navigate after creation and use waitForExistence Test results: 141/143 passed (was 131/143). Remaining 2 failures are pre-existing (Suite1 test11) and flaky/unrelated (Suite3 testR307). Co-Authored-By: Claude Opus 4.6 --- .../HoneyDueUITests/PageObjects/Screens.swift | 23 +++++++- iosApp/HoneyDueUITests/Suite5_TaskTests.swift | 39 +++++++------- .../Suite6_ComprehensiveTaskTests.swift | 35 ++++++------ .../Suite8_DocumentWarrantyTests.swift | 54 +++++++++++++++---- 4 files changed, 104 insertions(+), 47 deletions(-) diff --git a/iosApp/HoneyDueUITests/PageObjects/Screens.swift b/iosApp/HoneyDueUITests/PageObjects/Screens.swift index b8d26fe..5e66486 100644 --- a/iosApp/HoneyDueUITests/PageObjects/Screens.swift +++ b/iosApp/HoneyDueUITests/PageObjects/Screens.swift @@ -51,7 +51,28 @@ struct TaskListScreen { } func findTask(title: String) -> XCUIElement { - app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", title)).firstMatch + let predicate = NSPredicate(format: "label CONTAINS %@", title) + let match = app.staticTexts.containing(predicate).firstMatch + + // If found immediately, return + if match.waitForExistence(timeout: 3) { return match } + + // Scroll through kanban columns (swipe left up to 6 times) + let scrollView = app.scrollViews.firstMatch + guard scrollView.exists else { return match } + + for _ in 0..<6 { + scrollView.swipeLeft() + if match.waitForExistence(timeout: 1) { return match } + } + + // Scroll back and try right direction + for _ in 0..<6 { + scrollView.swipeRight() + if match.waitForExistence(timeout: 1) { return match } + } + + return match } } diff --git a/iosApp/HoneyDueUITests/Suite5_TaskTests.swift b/iosApp/HoneyDueUITests/Suite5_TaskTests.swift index 62da614..1a2d4c4 100644 --- a/iosApp/HoneyDueUITests/Suite5_TaskTests.swift +++ b/iosApp/HoneyDueUITests/Suite5_TaskTests.swift @@ -100,18 +100,18 @@ final class Suite5_TaskTests: AuthenticatedUITestCase { // Wait for form to dismiss _ = saveButton.waitForNonExistence(timeout: navigationTimeout) - // Verify task appears in list (may need refresh or scroll in kanban view) - let newTask = app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", taskTitle)).firstMatch - if !newTask.waitForExistence(timeout: navigationTimeout) { - pullToRefresh() - } - XCTAssertTrue(newTask.waitForExistence(timeout: navigationTimeout), "New task '\(taskTitle)' should appear in the list") - - // Track for cleanup + // Verify task was created via API (also gives the server time to process) if let items = TestAccountAPIClient.listTasks(token: session.token), let created = items.first(where: { $0.title.contains(taskTitle) }) { cleaner.trackTask(created.id) } + + // Navigate to tasks tab and refresh to pick up the newly created task + navigateToTasks() + refreshTasks() + let taskListScreen = TaskListScreen(app: app) + let newTask = taskListScreen.findTask(title: taskTitle) + XCTAssertTrue(newTask.waitForExistence(timeout: loginTimeout), "New task '\(taskTitle)' should appear in the list") } // MARK: - 4. View Details @@ -133,24 +133,23 @@ final class Suite5_TaskTests: AuthenticatedUITestCase { saveButton.tap() _ = saveButton.waitForNonExistence(timeout: navigationTimeout) - // Find and tap the task (may need refresh) - let taskCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", taskTitle)).firstMatch - if !taskCard.waitForExistence(timeout: navigationTimeout) { - pullToRefresh() - } - taskCard.waitForExistenceOrFail(timeout: navigationTimeout, message: "Created task should appear in list") - + // Verify task was created via API (also gives the server time to process) if let items = TestAccountAPIClient.listTasks(token: session.token), let created = items.first(where: { $0.title.contains(taskTitle) }) { cleaner.trackTask(created.id) } - taskCard.tap() + // Navigate to tasks tab and refresh to pick up the newly created task + navigateToTasks() + refreshTasks() + let taskListScreen = TaskListScreen(app: app) + let taskCard = taskListScreen.findTask(title: taskTitle) + taskCard.waitForExistenceOrFail(timeout: loginTimeout, message: "Created task should appear in list") - // After tapping a task, the app should show task details or actions. - // The navigation bar title or a detail view element should appear. - let navBar = app.navigationBars.firstMatch - XCTAssertTrue(navBar.waitForExistence(timeout: navigationTimeout), "Task detail view should load after tap") + // Verify the task card is accessible and the actions menu exists + // (There is no task detail screen — cards are self-contained with a context menu) + let actionsMenu = app.buttons["Task actions"].firstMatch + XCTAssertTrue(actionsMenu.waitForExistence(timeout: navigationTimeout), "Task actions menu should be accessible") } // MARK: - 5. Navigation diff --git a/iosApp/HoneyDueUITests/Suite6_ComprehensiveTaskTests.swift b/iosApp/HoneyDueUITests/Suite6_ComprehensiveTaskTests.swift index fe4f5a1..012855f 100644 --- a/iosApp/HoneyDueUITests/Suite6_ComprehensiveTaskTests.swift +++ b/iosApp/HoneyDueUITests/Suite6_ComprehensiveTaskTests.swift @@ -291,26 +291,31 @@ final class Suite6_ComprehensiveTaskTests: AuthenticatedUITestCase { let task = findTask(title: originalTitle) XCTAssertTrue(task.waitForExistence(timeout: defaultTimeout), "Task should exist") - task.tap() - let editButton = app.buttons[AccessibilityIdentifiers.Task.editButton].firstMatch - if editButton.waitForExistence(timeout: defaultTimeout) { - editButton.tap() + // Open the task actions menu on the card (edit is inside a Menu, not a detail screen) + let actionsMenu = app.buttons["Task actions"].firstMatch + if actionsMenu.waitForExistence(timeout: defaultTimeout) { + actionsMenu.tap() - let titleField = app.textFields[AccessibilityIdentifiers.Task.titleField].firstMatch - if titleField.waitForExistence(timeout: defaultTimeout) { - titleField.clearAndEnterText(newTitle, app: app) + let editButton = app.buttons[AccessibilityIdentifiers.Task.editButton].firstMatch + if editButton.waitForExistence(timeout: defaultTimeout) { + editButton.tap() - let saveButton = app.buttons[AccessibilityIdentifiers.Task.saveButton].firstMatch - if saveButton.exists { - saveButton.tap() - _ = saveButton.waitForNonExistence(timeout: defaultTimeout) + let titleField = app.textFields[AccessibilityIdentifiers.Task.titleField].firstMatch + if titleField.waitForExistence(timeout: defaultTimeout) { + titleField.clearAndEnterText(newTitle, app: app) - createdTaskTitles.append(newTitle) + let saveButton = app.buttons[AccessibilityIdentifiers.Task.saveButton].firstMatch + if saveButton.exists { + saveButton.tap() + _ = saveButton.waitForNonExistence(timeout: defaultTimeout) - navigateToTasks() - let updatedTask = findTask(title: newTitle) - XCTAssertTrue(updatedTask.exists, "Task should show updated title") + createdTaskTitles.append(newTitle) + + navigateToTasks() + let updatedTask = findTask(title: newTitle) + XCTAssertTrue(updatedTask.exists, "Task should show updated title") + } } } } diff --git a/iosApp/HoneyDueUITests/Suite8_DocumentWarrantyTests.swift b/iosApp/HoneyDueUITests/Suite8_DocumentWarrantyTests.swift index 10f3c0d..22fe28c 100644 --- a/iosApp/HoneyDueUITests/Suite8_DocumentWarrantyTests.swift +++ b/iosApp/HoneyDueUITests/Suite8_DocumentWarrantyTests.swift @@ -128,18 +128,35 @@ final class Suite8_DocumentWarrantyTests: AuthenticatedUITestCase { } private func submitForm(file: StaticString = #filePath, line: UInt = #line) { - // Dismiss keyboard so submit button is visible - dismissKeyboard() + // Dismiss keyboard by tapping outside form fields + app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.15)).tap() + _ = app.keyboards.firstMatch.waitForNonExistence(timeout: 3) + + // If keyboard still showing (can happen with long text / autocorrect), try Return key + if app.keyboards.firstMatch.exists { + app.typeText("\n") + _ = app.keyboards.firstMatch.waitForNonExistence(timeout: 2) + } let submitButton = docForm.saveButton if !submitButton.exists || !submitButton.isHittable { app.swipeUp() - _ = submitButton.waitForExistence(timeout: defaultTimeout) + _ = submitButton.waitForExistence(timeout: navigationTimeout) } XCTAssertTrue(submitButton.exists && submitButton.isEnabled, "Submit button should exist and be enabled", file: file, line: line) - submitButton.tap() - // Wait for form to dismiss after submit - submitButton.waitForNonExistence(timeout: navigationTimeout, file: file, line: line) + + // First tap attempt + if submitButton.isHittable { + submitButton.tap() + } else { + submitButton.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap() + } + + // Wait for form to dismiss — retry tap if button doesn't disappear + if !submitButton.waitForNonExistence(timeout: loginTimeout) && submitButton.exists { + submitButton.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap() + _ = submitButton.waitForNonExistence(timeout: loginTimeout) + } } /// Look up a just-created document by title and track it for API cleanup. @@ -770,10 +787,17 @@ final class Suite8_DocumentWarrantyTests: AuthenticatedUITestCase { submitForm() - // Just verify it was created (partial match) + // Track via API (also gives server time to process) + trackDocumentForCleanup(title: longTitle) + + // Re-navigate to refresh the list after creation + navigateToDocuments() + switchToDocumentsTab() + + // Verify it was created (partial match with wait) let partialTitle = String(longTitle.prefix(30)) - let documentExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] '\(partialTitle)'")).firstMatch.exists - XCTAssertTrue(documentExists, "Document with long title should be created") + let documentCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] '\(partialTitle)'")).firstMatch + XCTAssertTrue(documentCard.waitForExistence(timeout: loginTimeout), "Document with long title should be created") } func test23_CreateWarrantyWithSpecialCharacters() { @@ -792,9 +816,17 @@ final class Suite8_DocumentWarrantyTests: AuthenticatedUITestCase { submitForm() + // Track via API (also gives server time to process) + trackDocumentForCleanup(title: specialTitle) + + // Re-navigate to refresh the list after creation + navigateToDocuments() + switchToWarrantiesTab() + + // Verify it was created (partial match with wait) let partialTitle = String(specialTitle.prefix(20)) - let warrantyExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(partialTitle)'")).firstMatch.exists - XCTAssertTrue(warrantyExists, "Warranty with special characters should be created") + let warrantyCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(partialTitle)'")).firstMatch + XCTAssertTrue(warrantyCard.waitForExistence(timeout: loginTimeout), "Warranty with special characters should be created") } func test24_RapidTabSwitching() {