Re-architect iOS XCUITest suite: per-test isolation + domain organization
Migrate the XCUITest suite off the legacy shared-account model (and the prior Django-style auth assumptions) to a parallel-safe, domain-organized architecture, validated end-to-end against the live Kratos stack. Isolation (parallel-safe by construction): - Core/Fixtures/TestAccount.swift: each test mints its own pre-verified Kratos identity (uit_<domain>_<uuid>@test.honeydue.local), logs in, seeds under its own token, and deletes the identity in teardown (cascading all data + clearing Kratos). No shared testuser; parallel workers no longer race. - AuthenticatedUITestCase rewritten to that model (member surface preserved); adds requiresResidence / seedAccountPreconditions to seed UI-gated data BEFORE login (a fresh account is empty at login). Organization (255 tests preserved, none dropped): - 21 domain suites under Auth/ Onboarding/ Residence/ Task/ Contractor/ Document/ Sharing/ Navigation/ Smoke/ CrossCutting/ E2E/, consistent <Domain>UITests naming. Removes the Suite1..11 / AAA_ / ZZ_ / Tests/Rebuild naming chaos and the overlapping task/residence/auth suites. Runner + test plans: - run_ui_tests.sh: Smoke gate -> Seed -> Parallel(8 workers) -> Sweep. The parallel phase runs the whole target minus phase-managed suites via -skip-testing, so new suites auto-include (no hand-maintained list to drift). Drops the 2-worker cap and Suite6 isolation (isolation made them moot). - HoneyDueUITests.xctestplan skips the 4 phase-managed suites; adds Smoke.xctestplan. Kratos auth fixes folded in (login/verify/reset endpoints removed under Kratos): real Mailpit verification codes replace the obsolete fixed "123456"; teardown deletes Kratos identities; admin-panel login uses the correct seeded password. Build green; isolation, parallelism, and the precondition/sharing migrations validated against the live stack (0 leaked accounts). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,467 @@
|
||||
import XCTest
|
||||
|
||||
/// Comprehensive End-to-End Test Suite
|
||||
/// Closely mirrors TestIntegration_ComprehensiveE2E from honeyDueAPI-go/internal/integration/integration_test.go
|
||||
///
|
||||
/// This test creates a complete scenario:
|
||||
/// 1. Registers a new user and verifies login
|
||||
/// 2. Creates multiple residences
|
||||
/// 3. Creates multiple tasks in different states
|
||||
/// 4. Verifies task categorization in kanban columns
|
||||
/// 5. Tests task state transitions (in-progress, complete, cancel, archive)
|
||||
///
|
||||
/// IMPORTANT: These are integration tests requiring network connectivity.
|
||||
/// Run against a test/dev server, NOT production.
|
||||
///
|
||||
/// Per-test isolation is provided by `AuthenticatedUITestCase`: setUp mints a
|
||||
/// fresh, pre-verified Kratos account, logs in, and exposes `session`/`cleaner`/
|
||||
/// `account`; tearDown deletes the account (cascading all its data). Every test
|
||||
/// here creates its own residences and tasks through the UI (immediately visible),
|
||||
/// so no API-seeded preconditions are needed.
|
||||
final class E2EComprehensiveUITests: AuthenticatedUITestCase {
|
||||
|
||||
// Test run identifier for unique data
|
||||
private let testRunId = Int(Date().timeIntervalSince1970)
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
/// Creates a residence with the given name
|
||||
/// Returns true if successful
|
||||
@discardableResult
|
||||
private func createResidence(name: String, streetAddress: String = "123 Test St", city: String = "Austin", state: String = "TX", postalCode: String = "78701") -> Bool {
|
||||
navigateToTab("Residences")
|
||||
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton].firstMatch
|
||||
guard addButton.waitForExistence(timeout: defaultTimeout) else {
|
||||
XCTFail("Add residence button not found")
|
||||
return false
|
||||
}
|
||||
addButton.tap()
|
||||
|
||||
// Fill name
|
||||
let nameField = app.textFields[AccessibilityIdentifiers.Residence.nameField].firstMatch
|
||||
guard nameField.waitForExistence(timeout: 5) else {
|
||||
XCTFail("Name field not found")
|
||||
return false
|
||||
}
|
||||
nameField.focusAndType(name, app: app)
|
||||
|
||||
// Fill address
|
||||
let streetField = app.textFields[AccessibilityIdentifiers.Residence.streetAddressField].firstMatch
|
||||
if streetField.exists { streetField.focusAndType(streetAddress, app: app) }
|
||||
let cityField = app.textFields[AccessibilityIdentifiers.Residence.cityField].firstMatch
|
||||
if cityField.exists { cityField.focusAndType(city, app: app) }
|
||||
let stateField = app.textFields[AccessibilityIdentifiers.Residence.stateProvinceField].firstMatch
|
||||
if stateField.exists { stateField.focusAndType(state, app: app) }
|
||||
let postalField = app.textFields[AccessibilityIdentifiers.Residence.postalCodeField].firstMatch
|
||||
if postalField.exists { postalField.focusAndType(postalCode, app: app) }
|
||||
|
||||
app.swipeUp()
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Residence.saveButton].firstMatch
|
||||
guard saveButton.waitForExistence(timeout: defaultTimeout) else {
|
||||
XCTFail("Save button not found")
|
||||
return false
|
||||
}
|
||||
saveButton.tap()
|
||||
|
||||
// Verify created
|
||||
let residenceCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(name)'")).firstMatch
|
||||
return residenceCard.waitForExistence(timeout: 10)
|
||||
}
|
||||
|
||||
/// Creates a task with the given title
|
||||
/// Returns true if successful
|
||||
@discardableResult
|
||||
private func createTask(title: String, description: String? = nil) -> Bool {
|
||||
// Ensure at least one residence exists (tasks require a residence context)
|
||||
navigateToTab("Residences")
|
||||
_ = app.cells.firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
let emptyState = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No properties' OR label CONTAINS[c] 'Add your first'")).firstMatch
|
||||
if emptyState.exists || app.cells.count == 0 {
|
||||
createResidence(name: "Auto Residence \(testRunId)")
|
||||
}
|
||||
|
||||
navigateToTab("Tasks")
|
||||
|
||||
let addButton = findAddTaskButton()
|
||||
guard addButton.waitForExistence(timeout: 10) && addButton.isEnabled else {
|
||||
XCTFail("Add task button not found or disabled")
|
||||
return false
|
||||
}
|
||||
addButton.tap()
|
||||
|
||||
// Fill title
|
||||
let titleField = app.textFields[AccessibilityIdentifiers.Task.titleField].firstMatch
|
||||
guard titleField.waitForExistence(timeout: 5) else {
|
||||
XCTFail("Title field not found")
|
||||
return false
|
||||
}
|
||||
titleField.focusAndType(title, app: app)
|
||||
|
||||
// Fill description if provided
|
||||
if let desc = description {
|
||||
let descField = app.textViews[AccessibilityIdentifiers.Task.descriptionField].firstMatch
|
||||
if descField.exists {
|
||||
descField.focusAndType(desc, app: app)
|
||||
}
|
||||
}
|
||||
|
||||
app.swipeUp()
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Task.saveButton].firstMatch
|
||||
guard saveButton.waitForExistence(timeout: defaultTimeout) else {
|
||||
XCTFail("Save button not found")
|
||||
return false
|
||||
}
|
||||
saveButton.tap()
|
||||
|
||||
// Verify created
|
||||
let taskCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(title)'")).firstMatch
|
||||
return taskCard.waitForExistence(timeout: 10)
|
||||
}
|
||||
|
||||
|
||||
private func findAddTaskButton() -> XCUIElement {
|
||||
// Strategy 1: Accessibility identifier
|
||||
let addButtonById = app.buttons[AccessibilityIdentifiers.Task.addButton].firstMatch
|
||||
if addButtonById.exists && addButtonById.isEnabled {
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
// Strategy 2: Navigation bar plus button
|
||||
let navBarButtons = app.navigationBars.buttons
|
||||
for i in 0..<navBarButtons.count {
|
||||
let button = navBarButtons.element(boundBy: i)
|
||||
if (button.label == "plus" || button.label.contains("Add")) && button.isEnabled {
|
||||
return button
|
||||
}
|
||||
}
|
||||
|
||||
// Strategy 3: Empty state button
|
||||
let emptyStateButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Add Task'")).firstMatch
|
||||
if emptyStateButton.exists && emptyStateButton.isEnabled {
|
||||
return emptyStateButton
|
||||
}
|
||||
|
||||
return addButtonById
|
||||
}
|
||||
|
||||
// MARK: - Test 1: Create Multiple Residences
|
||||
// Phase 2 of TestIntegration_ComprehensiveE2E
|
||||
|
||||
func test01_createMultipleResidences() {
|
||||
let residenceNames = [
|
||||
"E2E Main House \(testRunId)",
|
||||
"E2E Beach House \(testRunId)",
|
||||
"E2E Mountain Cabin \(testRunId)"
|
||||
]
|
||||
|
||||
for (index, name) in residenceNames.enumerated() {
|
||||
let streetAddress = "\(100 * (index + 1)) Test St"
|
||||
let success = createResidence(name: name, streetAddress: streetAddress)
|
||||
XCTAssertTrue(success, "Should create residence: \(name)")
|
||||
}
|
||||
|
||||
// Verify all residences exist
|
||||
navigateToTab("Residences")
|
||||
|
||||
for name in residenceNames {
|
||||
let residenceCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(name)'")).firstMatch
|
||||
XCTAssertTrue(residenceCard.waitForExistence(timeout: 5), "Residence '\(name)' should exist in list")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test 2: Create Tasks with Various States
|
||||
// Phase 3 of TestIntegration_ComprehensiveE2E
|
||||
|
||||
func test02_createTasksWithVariousStates() {
|
||||
// Ensure at least one residence exists
|
||||
navigateToTab("Residences")
|
||||
_ = app.cells.firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
|
||||
let emptyState = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No properties'")).firstMatch
|
||||
if emptyState.exists {
|
||||
createResidence(name: "Task Test Residence \(testRunId)")
|
||||
}
|
||||
|
||||
// Create tasks with different purposes
|
||||
let tasks = [
|
||||
("E2E Active Task \(testRunId)", "Task that remains active"),
|
||||
("E2E Progress Task \(testRunId)", "Task to mark in-progress"),
|
||||
("E2E Complete Task \(testRunId)", "Task to complete"),
|
||||
("E2E Cancel Task \(testRunId)", "Task to cancel")
|
||||
]
|
||||
|
||||
for (title, description) in tasks {
|
||||
let success = createTask(title: title, description: description)
|
||||
XCTAssertTrue(success, "Should create task: \(title)")
|
||||
}
|
||||
|
||||
// Verify all tasks exist
|
||||
navigateToTab("Tasks")
|
||||
|
||||
for (title, _) in tasks {
|
||||
let taskCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(title)'")).firstMatch
|
||||
XCTAssertTrue(taskCard.waitForExistence(timeout: 5), "Task '\(title)' should exist")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test 3: Task State Transitions
|
||||
// Mirrors task operations from TestIntegration_TaskFlow
|
||||
|
||||
func test03_taskStateTransitions() {
|
||||
navigateToTab("Tasks")
|
||||
|
||||
// Find a task to transition (create one if needed)
|
||||
let testTaskTitle = "E2E State Test \(testRunId)"
|
||||
|
||||
var taskExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(testTaskTitle)'")).firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
if !taskExists {
|
||||
// Check if any residence exists first
|
||||
navigateToTab("Residences")
|
||||
_ = app.cells.firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
|
||||
let emptyResidences = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No properties'")).firstMatch
|
||||
if emptyResidences.exists {
|
||||
createResidence(name: "State Test Residence \(testRunId)")
|
||||
}
|
||||
|
||||
createTask(title: testTaskTitle, description: "Testing state transitions")
|
||||
navigateToTab("Tasks")
|
||||
}
|
||||
|
||||
// Find and tap the task
|
||||
let taskCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(testTaskTitle)'")).firstMatch
|
||||
if taskCard.waitForExistence(timeout: defaultTimeout) {
|
||||
taskCard.tap()
|
||||
|
||||
// Wait for task detail to load
|
||||
let detailView = app.navigationBars.firstMatch
|
||||
_ = detailView.waitForExistence(timeout: defaultTimeout)
|
||||
|
||||
// Try to mark in progress
|
||||
let inProgressButton = app.buttons[AccessibilityIdentifiers.Task.markInProgressButton].firstMatch
|
||||
if inProgressButton.exists && inProgressButton.isEnabled {
|
||||
inProgressButton.tap()
|
||||
_ = inProgressButton.waitForNonExistence(timeout: defaultTimeout)
|
||||
}
|
||||
|
||||
// Try to complete
|
||||
let completeButton = app.buttons[AccessibilityIdentifiers.Task.completeButton].firstMatch
|
||||
if completeButton.exists && completeButton.isEnabled {
|
||||
completeButton.tap()
|
||||
|
||||
// Handle completion form if shown
|
||||
let submitButton = app.buttons[AccessibilityIdentifiers.Task.submitButton].firstMatch
|
||||
if submitButton.waitForExistence(timeout: defaultTimeout) {
|
||||
submitButton.tap()
|
||||
_ = submitButton.waitForNonExistence(timeout: defaultTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
// Navigate back
|
||||
let backButton = app.navigationBars.buttons.element(boundBy: 0)
|
||||
if backButton.exists && backButton.isHittable {
|
||||
backButton.tap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test 4: Task Cancel Operation
|
||||
|
||||
func test04_taskCancelOperation() {
|
||||
navigateToTab("Tasks")
|
||||
|
||||
let testTaskTitle = "E2E Cancel Test \(testRunId)"
|
||||
|
||||
// Create task if doesn't exist
|
||||
if !app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(testTaskTitle)'")).firstMatch.waitForExistence(timeout: defaultTimeout) {
|
||||
navigateToTab("Residences")
|
||||
_ = app.cells.firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
|
||||
let emptyResidences = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No properties'")).firstMatch
|
||||
if emptyResidences.exists {
|
||||
createResidence(name: "Cancel Test Residence \(testRunId)")
|
||||
}
|
||||
|
||||
createTask(title: testTaskTitle, description: "Task to be cancelled")
|
||||
navigateToTab("Tasks")
|
||||
}
|
||||
|
||||
// Find and tap task
|
||||
let taskCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(testTaskTitle)'")).firstMatch
|
||||
if taskCard.waitForExistence(timeout: defaultTimeout) {
|
||||
taskCard.tap()
|
||||
_ = app.navigationBars.firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
|
||||
// Look for cancel button
|
||||
let cancelButton = app.buttons[AccessibilityIdentifiers.Task.detailCancelButton].firstMatch
|
||||
if cancelButton.exists && cancelButton.isEnabled {
|
||||
cancelButton.tap()
|
||||
|
||||
// Confirm cancellation if alert shown
|
||||
let confirmButton = app.alerts.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Cancel' OR label CONTAINS[c] 'Confirm' OR label CONTAINS[c] 'Yes'")).firstMatch
|
||||
if confirmButton.waitForExistence(timeout: defaultTimeout) {
|
||||
confirmButton.tap()
|
||||
_ = confirmButton.waitForNonExistence(timeout: defaultTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
// Navigate back
|
||||
let backButton = app.navigationBars.buttons.element(boundBy: 0)
|
||||
if backButton.exists && backButton.isHittable {
|
||||
backButton.tap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test 5: Task Archive Operation
|
||||
|
||||
func test05_taskArchiveOperation() {
|
||||
navigateToTab("Tasks")
|
||||
|
||||
let testTaskTitle = "E2E Archive Test \(testRunId)"
|
||||
|
||||
// Create task if doesn't exist
|
||||
if !app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(testTaskTitle)'")).firstMatch.waitForExistence(timeout: defaultTimeout) {
|
||||
navigateToTab("Residences")
|
||||
_ = app.cells.firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
|
||||
let emptyResidences = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'No properties'")).firstMatch
|
||||
if emptyResidences.exists {
|
||||
createResidence(name: "Archive Test Residence \(testRunId)")
|
||||
}
|
||||
|
||||
createTask(title: testTaskTitle, description: "Task to be archived")
|
||||
navigateToTab("Tasks")
|
||||
}
|
||||
|
||||
// Find and tap task
|
||||
let taskCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(testTaskTitle)'")).firstMatch
|
||||
if taskCard.waitForExistence(timeout: defaultTimeout) {
|
||||
taskCard.tap()
|
||||
_ = app.navigationBars.firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
|
||||
// Look for archive button
|
||||
let archiveButton = app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Archive'")).firstMatch
|
||||
if archiveButton.exists && archiveButton.isEnabled {
|
||||
archiveButton.tap()
|
||||
|
||||
// Confirm archive if alert shown
|
||||
let confirmButton = app.alerts.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Archive' OR label CONTAINS[c] 'Confirm' OR label CONTAINS[c] 'Yes'")).firstMatch
|
||||
if confirmButton.waitForExistence(timeout: defaultTimeout) {
|
||||
confirmButton.tap()
|
||||
_ = confirmButton.waitForNonExistence(timeout: defaultTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
// Navigate back
|
||||
let backButton = app.navigationBars.buttons.element(boundBy: 0)
|
||||
if backButton.exists && backButton.isHittable {
|
||||
backButton.tap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test 6: Verify Kanban Column Structure
|
||||
// Phase 6 of TestIntegration_ComprehensiveE2E
|
||||
|
||||
func test06_verifyKanbanStructure() {
|
||||
navigateToTab("Tasks")
|
||||
|
||||
// Expected kanban column names (may vary by implementation)
|
||||
let expectedColumns = [
|
||||
"Overdue",
|
||||
"In Progress",
|
||||
"Due Soon",
|
||||
"Upcoming",
|
||||
"Completed",
|
||||
"Cancelled"
|
||||
]
|
||||
|
||||
var foundColumns: [String] = []
|
||||
|
||||
for column in expectedColumns {
|
||||
let columnHeader = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] '\(column)'")).firstMatch
|
||||
if columnHeader.exists {
|
||||
foundColumns.append(column)
|
||||
}
|
||||
}
|
||||
|
||||
// Should have at least some kanban columns OR be in list view
|
||||
let hasKanbanView = foundColumns.count >= 2
|
||||
let hasListView = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks' OR label CONTAINS[c] 'All Tasks'")).firstMatch.exists
|
||||
|
||||
XCTAssertTrue(hasKanbanView || hasListView, "Should display tasks in kanban or list view. Found columns: \(foundColumns)")
|
||||
}
|
||||
|
||||
// MARK: - Test 7: Residence Details Show Tasks
|
||||
// Verifies that residence detail screen shows associated tasks
|
||||
|
||||
// test07 removed — app bug: pull-to-refresh doesn't load API-created residences
|
||||
|
||||
|
||||
// MARK: - Test 8: Contractor CRUD (Mirrors backend contractor tests)
|
||||
|
||||
func test08_contractorCRUD() {
|
||||
navigateToTab("Contractors")
|
||||
|
||||
let contractorName = "E2E Test Contractor \(testRunId)"
|
||||
|
||||
// Check if Contractors tab exists
|
||||
let contractorsTab = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Contractors'")).firstMatch
|
||||
guard contractorsTab.exists else {
|
||||
// Contractors may not be a main tab - skip this test
|
||||
return
|
||||
}
|
||||
|
||||
// Try to add contractor
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Contractor.addButton].firstMatch
|
||||
guard addButton.waitForExistence(timeout: 5) else {
|
||||
// May need residence first
|
||||
return
|
||||
}
|
||||
|
||||
addButton.tap()
|
||||
|
||||
// Fill contractor form
|
||||
let nameField = app.textFields[AccessibilityIdentifiers.Contractor.nameField].firstMatch
|
||||
if nameField.exists {
|
||||
nameField.focusAndType(contractorName, app: app)
|
||||
|
||||
let companyField = app.textFields[AccessibilityIdentifiers.Contractor.companyField].firstMatch
|
||||
if companyField.exists {
|
||||
companyField.focusAndType("Test Company Inc", app: app)
|
||||
}
|
||||
|
||||
let phoneField = app.textFields[AccessibilityIdentifiers.Contractor.phoneField].firstMatch
|
||||
if phoneField.exists {
|
||||
phoneField.focusAndType("555-123-4567", app: app)
|
||||
}
|
||||
|
||||
app.swipeUp()
|
||||
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Contractor.saveButton].firstMatch
|
||||
if saveButton.exists {
|
||||
saveButton.tap()
|
||||
|
||||
// Verify contractor was created
|
||||
let contractorCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(contractorName)'")).firstMatch
|
||||
XCTAssertTrue(contractorCard.waitForExistence(timeout: 10), "Contractor '\(contractorName)' should be created")
|
||||
}
|
||||
} else {
|
||||
// Cancel if form didn't load properly
|
||||
let cancelButton = app.buttons[AccessibilityIdentifiers.Contractor.formCancelButton].firstMatch
|
||||
if cancelButton.exists {
|
||||
cancelButton.tap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test 9: Full Flow Summary
|
||||
|
||||
// test09_fullFlowSummary removed — redundant summary test with no unique coverage
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
import XCTest
|
||||
|
||||
/// Comprehensive End-to-End Integration Tests
|
||||
/// Mirrors the backend integration tests in honeyDueAPI-go/internal/integration/integration_test.go
|
||||
///
|
||||
/// This test suite covers:
|
||||
/// 1. Full authentication flow (register, login, logout)
|
||||
/// 2. Residence CRUD operations
|
||||
/// 3. Task lifecycle (create, update, mark-in-progress, complete, archive, cancel)
|
||||
/// 4. Residence sharing between users
|
||||
/// 5. Cross-user access control
|
||||
///
|
||||
/// IMPORTANT: These tests create real data and require network connectivity.
|
||||
/// Run with a test server or dev environment (not production).
|
||||
///
|
||||
/// Per-test isolation is provided by `AuthenticatedUITestCase`: setUp mints a
|
||||
/// fresh, pre-verified Kratos account, logs in, and exposes `session`/`cleaner`/
|
||||
/// `account`; tearDown deletes the account (cascading all its data). Tests that
|
||||
/// gate on a residence existing set `requiresResidence` so one is seeded BEFORE
|
||||
/// login (a fresh account is otherwise empty until a manual refresh).
|
||||
final class E2EIntegrationUITests: AuthenticatedUITestCase {
|
||||
|
||||
/// test03 creates a task through the UI, which requires at least one
|
||||
/// residence to already exist (the Add Task button is disabled otherwise).
|
||||
/// Seed a residence before login so the app loads it on its post-login fetch.
|
||||
override var requiresResidence: Bool { true }
|
||||
|
||||
// Unique ID for test data names
|
||||
private let testRunId = Int(Date().timeIntervalSince1970)
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
/// Dismiss strong password suggestion if shown
|
||||
private func dismissStrongPasswordSuggestion() {
|
||||
let chooseOwnPassword = app.buttons["Choose My Own Password"]
|
||||
if chooseOwnPassword.waitForExistence(timeout: 1) {
|
||||
chooseOwnPassword.tap()
|
||||
return
|
||||
}
|
||||
let notNow = app.buttons["Not Now"]
|
||||
if notNow.exists && notNow.isHittable {
|
||||
notNow.tap()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test 1: Complete Authentication Flow
|
||||
// Mirrors TestIntegration_AuthenticationFlow
|
||||
|
||||
func test01_authenticationFlow() {
|
||||
// This test verifies the full auth lifecycle via API
|
||||
// (UI registration is tested by Suite1_RegistrationTests)
|
||||
let timestamp = Int(Date().timeIntervalSince1970)
|
||||
let testUser = "e2e_auth_\(testRunId)"
|
||||
let testEmail = "e2e_auth_\(testRunId)@test.com"
|
||||
let testPassword = "TestPass123!"
|
||||
|
||||
// Phase 1: Create user via API
|
||||
guard let session = TestAccountAPIClient.createVerifiedAccount(
|
||||
username: testUser, email: testEmail, password: testPassword
|
||||
) else {
|
||||
XCTFail("Could not create test user via API")
|
||||
return
|
||||
}
|
||||
|
||||
// Phase 2: Logout current user and login as new user via UI
|
||||
UITestHelpers.ensureLoggedOut(app: app)
|
||||
let welcomeText = app.textFields[AccessibilityIdentifiers.Authentication.usernameField]
|
||||
XCTAssertTrue(welcomeText.waitForExistence(timeout: 10), "Should be on login screen")
|
||||
UITestHelpers.login(app: app, username: testEmail, password: testPassword)
|
||||
|
||||
// Phase 3: Verify logged in
|
||||
let tabBar = app.tabBars.firstMatch
|
||||
XCTAssertTrue(tabBar.waitForExistence(timeout: 15), "Should be logged in after login")
|
||||
|
||||
// Phase 4: Logout
|
||||
UITestHelpers.logout(app: app)
|
||||
XCTAssertTrue(welcomeText.waitForExistence(timeout: 10), "Should be on login screen after logout")
|
||||
|
||||
// Phase 5: Login again to verify re-login works
|
||||
UITestHelpers.login(app: app, username: testEmail, password: testPassword)
|
||||
XCTAssertTrue(tabBar.waitForExistence(timeout: 10), "Should be logged in after re-login")
|
||||
|
||||
// Phase 6: Final logout
|
||||
UITestHelpers.logout(app: app)
|
||||
XCTAssertTrue(welcomeText.waitForExistence(timeout: 10), "Should be logged out")
|
||||
}
|
||||
|
||||
// MARK: - Test 2: Residence CRUD Flow
|
||||
// Mirrors TestIntegration_ResidenceFlow
|
||||
|
||||
func test02_residenceCRUDFlow() {
|
||||
// Ensure logged in as test user
|
||||
// Already logged in via setUp — verify tab bar exists
|
||||
XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: defaultTimeout), "Should be logged in")
|
||||
navigateToTab("Residences")
|
||||
|
||||
let residenceName = "E2E Test Home \(testRunId)"
|
||||
|
||||
// Phase 1: Create residence
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton].firstMatch
|
||||
XCTAssertTrue(addButton.waitForExistence(timeout: defaultTimeout), "Add residence button should exist")
|
||||
addButton.tap()
|
||||
|
||||
// Fill form
|
||||
let nameField = app.textFields[AccessibilityIdentifiers.Residence.nameField]
|
||||
XCTAssertTrue(nameField.waitForExistence(timeout: 5), "Name field should exist")
|
||||
nameField.focusAndType(residenceName, app: app)
|
||||
|
||||
// Use return key to move to next field or dismiss, then scroll
|
||||
dismissKeyboard()
|
||||
|
||||
// Scroll to show more fields
|
||||
app.swipeUp()
|
||||
|
||||
// Fill street field
|
||||
let streetField = app.textFields[AccessibilityIdentifiers.Residence.streetAddressField]
|
||||
if streetField.waitForExistence(timeout: 3) && streetField.isHittable {
|
||||
streetField.focusAndType("123 E2E Test St", app: app)
|
||||
dismissKeyboard()
|
||||
}
|
||||
|
||||
// Fill city field
|
||||
let cityField = app.textFields[AccessibilityIdentifiers.Residence.cityField]
|
||||
if cityField.waitForExistence(timeout: 3) && cityField.isHittable {
|
||||
cityField.focusAndType("Austin", app: app)
|
||||
dismissKeyboard()
|
||||
}
|
||||
|
||||
// Fill state field
|
||||
let stateField = app.textFields[AccessibilityIdentifiers.Residence.stateProvinceField]
|
||||
if stateField.waitForExistence(timeout: 3) && stateField.isHittable {
|
||||
stateField.focusAndType("TX", app: app)
|
||||
dismissKeyboard()
|
||||
}
|
||||
|
||||
// Fill postal code field
|
||||
let postalField = app.textFields[AccessibilityIdentifiers.Residence.postalCodeField]
|
||||
if postalField.waitForExistence(timeout: 3) && postalField.isHittable {
|
||||
postalField.focusAndType("78701", app: app)
|
||||
}
|
||||
|
||||
// Dismiss keyboard and scroll to save button
|
||||
dismissKeyboard()
|
||||
_ = app.keyboards.firstMatch.waitForNonExistence(timeout: defaultTimeout)
|
||||
app.swipeUp()
|
||||
|
||||
// Save the residence
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Residence.saveButton]
|
||||
if saveButton.waitForExistence(timeout: 5) && saveButton.isHittable {
|
||||
saveButton.tap()
|
||||
} else {
|
||||
// Try finding by label as fallback
|
||||
let saveByLabel = app.buttons[AccessibilityIdentifiers.Residence.saveButton].firstMatch
|
||||
XCTAssertTrue(saveByLabel.waitForExistence(timeout: 5), "Save button should exist")
|
||||
saveByLabel.tap()
|
||||
}
|
||||
|
||||
// Phase 2: Verify residence was created
|
||||
navigateToTab("Residences")
|
||||
let residenceCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(residenceName)'")).firstMatch
|
||||
XCTAssertTrue(residenceCard.waitForExistence(timeout: 10), "Residence '\(residenceName)' should appear in list")
|
||||
}
|
||||
|
||||
// MARK: - Test 3: Task Lifecycle Flow
|
||||
// Mirrors TestIntegration_TaskFlow
|
||||
|
||||
func test03_taskLifecycleFlow() {
|
||||
// Ensure logged in
|
||||
// Already logged in via setUp — verify tab bar exists
|
||||
XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: defaultTimeout), "Should be logged in")
|
||||
|
||||
// Residence precondition is seeded before login (requiresResidence), so
|
||||
// the Add Task button is enabled. Refresh the residences list to be sure
|
||||
// the seeded residence is loaded.
|
||||
navigateToResidences()
|
||||
pullToRefresh()
|
||||
|
||||
// Navigate to Tasks
|
||||
navigateToTab("Tasks")
|
||||
|
||||
let taskTitle = "E2E Task Lifecycle \(testRunId)"
|
||||
|
||||
// Phase 1: Create task - use firstMatch to avoid multiple element issue
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Task.addButton].firstMatch
|
||||
guard addButton.waitForExistence(timeout: 5) else {
|
||||
XCTFail("Add task button should exist")
|
||||
return
|
||||
}
|
||||
|
||||
// Check if button is enabled
|
||||
guard addButton.isEnabled else {
|
||||
XCTFail("Add task button should be enabled (requires at least one residence)")
|
||||
return
|
||||
}
|
||||
|
||||
addButton.tap()
|
||||
|
||||
// Fill task form
|
||||
let titleField = app.textFields[AccessibilityIdentifiers.Task.titleField].firstMatch
|
||||
XCTAssertTrue(titleField.waitForExistence(timeout: 5), "Task title field should exist")
|
||||
titleField.focusAndType(taskTitle, app: app)
|
||||
|
||||
dismissKeyboard()
|
||||
_ = app.keyboards.firstMatch.waitForNonExistence(timeout: defaultTimeout)
|
||||
app.swipeUp()
|
||||
|
||||
// Save the task
|
||||
let saveTaskButton = app.buttons[AccessibilityIdentifiers.Task.saveButton].firstMatch
|
||||
if saveTaskButton.waitForExistence(timeout: 5) && saveTaskButton.isHittable {
|
||||
saveTaskButton.tap()
|
||||
} else {
|
||||
let saveByLabel = app.buttons[AccessibilityIdentifiers.Task.saveButton].firstMatch
|
||||
XCTAssertTrue(saveByLabel.exists, "Save/Create button should exist")
|
||||
saveByLabel.tap()
|
||||
}
|
||||
|
||||
// Phase 2: Verify task was created
|
||||
navigateToTab("Tasks")
|
||||
let taskCard = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '\(taskTitle)'")).firstMatch
|
||||
XCTAssertTrue(taskCard.waitForExistence(timeout: 10), "Task '\(taskTitle)' should appear in task list")
|
||||
}
|
||||
|
||||
// MARK: - Test 4: Kanban Column Distribution
|
||||
// Mirrors TestIntegration_TasksByResidenceKanban
|
||||
|
||||
func test04_kanbanColumnDistribution() {
|
||||
// Already logged in via setUp — verify tab bar exists
|
||||
XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: defaultTimeout), "Should be logged in")
|
||||
navigateToTab("Tasks")
|
||||
|
||||
// Verify tasks screen is showing
|
||||
let tasksTitle = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch
|
||||
let kanbanExists = app.staticTexts.containing(NSPredicate(format: "label CONTAINS[c] 'Overdue' OR label CONTAINS[c] 'Upcoming' OR label CONTAINS[c] 'In Progress'")).firstMatch.exists
|
||||
|
||||
XCTAssertTrue(kanbanExists || tasksTitle.exists, "Tasks screen should be visible")
|
||||
}
|
||||
|
||||
// MARK: - Test 5: Cross-User Access Control
|
||||
// Mirrors TestIntegration_CrossUserAccessDenied
|
||||
|
||||
func test05_crossUserAccessControl() {
|
||||
// Already logged in via setUp — verify tab bar exists
|
||||
XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: defaultTimeout), "Should be logged in")
|
||||
|
||||
// Verify user can access their residences tab
|
||||
navigateToTab("Residences")
|
||||
|
||||
let residencesVisible = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Residences'")).firstMatch.isSelected
|
||||
XCTAssertTrue(residencesVisible, "User should be able to access Residences tab")
|
||||
|
||||
// Verify user can access their tasks tab
|
||||
navigateToTab("Tasks")
|
||||
|
||||
let tasksAccessible = app.tabBars.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Tasks'")).firstMatch.isSelected
|
||||
XCTAssertTrue(tasksAccessible, "User should be able to access Tasks tab")
|
||||
}
|
||||
|
||||
// MARK: - Test 6: Lookup Data Endpoints
|
||||
// Mirrors TestIntegration_LookupEndpoints
|
||||
|
||||
func test06_lookupDataAvailable() {
|
||||
// Already logged in via setUp — verify tab bar exists
|
||||
XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: defaultTimeout), "Should be logged in")
|
||||
|
||||
// Navigate to add residence to check residence types are loaded
|
||||
navigateToTab("Residences")
|
||||
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton].firstMatch
|
||||
addButton.waitForExistenceOrFail(timeout: navigationTimeout, message: "Add residence button should exist")
|
||||
addButton.tap()
|
||||
|
||||
// Check property type picker exists (indicates lookups loaded)
|
||||
let propertyTypePicker = app.buttons[AccessibilityIdentifiers.Residence.propertyTypePicker].firstMatch
|
||||
XCTAssertTrue(propertyTypePicker.waitForExistence(timeout: navigationTimeout), "Property type picker should exist (lookups loaded)")
|
||||
|
||||
// Cancel form
|
||||
let cancelButton = app.buttons[AccessibilityIdentifiers.Residence.formCancelButton].firstMatch
|
||||
if cancelButton.exists { cancelButton.tap() }
|
||||
}
|
||||
|
||||
// MARK: - Test 7: Residence Sharing Flow
|
||||
// Mirrors TestIntegration_ResidenceSharingFlow
|
||||
|
||||
func test07_residenceSharingUIElements() {
|
||||
// Already logged in via setUp — verify tab bar exists
|
||||
XCTAssertTrue(app.tabBars.firstMatch.waitForExistence(timeout: defaultTimeout), "Should be logged in")
|
||||
navigateToTab("Residences")
|
||||
|
||||
// Find any residence to check sharing UI
|
||||
let residenceCard = app.cells.firstMatch
|
||||
if residenceCard.waitForExistence(timeout: defaultTimeout) {
|
||||
residenceCard.tap()
|
||||
|
||||
// Look for share button in residence details
|
||||
let shareButton = app.buttons[AccessibilityIdentifiers.Residence.shareButton]
|
||||
let manageUsersButton = app.buttons[AccessibilityIdentifiers.Residence.manageUsersButton]
|
||||
|
||||
// Note: Share functionality may not be visible depending on user permissions
|
||||
// This test just verifies we can navigate to residence details
|
||||
|
||||
// Navigate back
|
||||
let backButton = app.navigationBars.buttons.element(boundBy: 0)
|
||||
if backButton.exists && backButton.isHittable {
|
||||
backButton.tap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helper: Create Minimal Residence
|
||||
|
||||
private func createMinimalResidence(name: String) {
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Residence.addButton].firstMatch
|
||||
guard addButton.waitForExistence(timeout: 5) else { return }
|
||||
|
||||
addButton.tap()
|
||||
|
||||
// Fill name field
|
||||
let nameField = app.textFields[AccessibilityIdentifiers.Residence.nameField]
|
||||
if nameField.waitForExistence(timeout: defaultTimeout) {
|
||||
nameField.focusAndType(name, app: app)
|
||||
dismissKeyboard()
|
||||
}
|
||||
|
||||
// Scroll to show address fields
|
||||
app.swipeUp()
|
||||
|
||||
// Fill street field
|
||||
let streetField = app.textFields[AccessibilityIdentifiers.Residence.streetAddressField]
|
||||
if streetField.waitForExistence(timeout: 3) && streetField.isHittable {
|
||||
streetField.focusAndType("123 Test St", app: app)
|
||||
dismissKeyboard()
|
||||
}
|
||||
|
||||
// Fill city field
|
||||
let cityField = app.textFields[AccessibilityIdentifiers.Residence.cityField]
|
||||
if cityField.waitForExistence(timeout: 3) && cityField.isHittable {
|
||||
cityField.focusAndType("Austin", app: app)
|
||||
dismissKeyboard()
|
||||
}
|
||||
|
||||
// Fill state field
|
||||
let stateField = app.textFields[AccessibilityIdentifiers.Residence.stateProvinceField]
|
||||
if stateField.waitForExistence(timeout: 3) && stateField.isHittable {
|
||||
stateField.focusAndType("TX", app: app)
|
||||
dismissKeyboard()
|
||||
}
|
||||
|
||||
// Fill postal code field
|
||||
let postalField = app.textFields[AccessibilityIdentifiers.Residence.postalCodeField]
|
||||
if postalField.waitForExistence(timeout: 3) && postalField.isHittable {
|
||||
postalField.focusAndType("78701", app: app)
|
||||
}
|
||||
|
||||
dismissKeyboard()
|
||||
_ = app.keyboards.firstMatch.waitForNonExistence(timeout: defaultTimeout)
|
||||
app.swipeUp()
|
||||
|
||||
// Save
|
||||
let saveButton = app.buttons[AccessibilityIdentifiers.Residence.saveButton].firstMatch
|
||||
if saveButton.waitForExistence(timeout: 5) && saveButton.isHittable {
|
||||
saveButton.tap()
|
||||
}
|
||||
// Wait for save to complete and return to list
|
||||
_ = app.cells.firstMatch.waitForExistence(timeout: defaultTimeout)
|
||||
}
|
||||
|
||||
// MARK: - Helper: Find Add Task Button
|
||||
|
||||
private func findAddTaskButton() -> XCUIElement {
|
||||
let addButton = app.buttons[AccessibilityIdentifiers.Task.addButton].firstMatch
|
||||
if addButton.exists {
|
||||
return addButton
|
||||
}
|
||||
return app.buttons.containing(NSPredicate(format: "label CONTAINS[c] 'Add Task' OR label CONTAINS[c] 'New Task'")).firstMatch
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user