// // CameraFlowUITests.swift // PlantGuideUITests // // Tests for camera permission handling and capture flow. // import XCTest final class CameraFlowUITests: BaseUITestCase { // MARK: - Permission States @MainActor func testCameraViewShowsValidState() throws { // Camera is the default tab — no need to tap it launchClean() let camera = CameraScreen(app: app) XCTAssertTrue(camera.hasValidState(timeout: 10), "Camera should show a valid state (capture, permission request, or denied)") } @MainActor func testCameraTabIsDefaultSelected() throws { launchClean() // Camera is the default tab — just verify it's selected TabBarScreen(app: app).assertSelected(UITestID.TabBar.camera) } // MARK: - Capture Button @MainActor func testCaptureButtonExistsWhenAuthorized() throws { launchClean() let camera = CameraScreen(app: app) // On simulator, camera may not be authorized — both states are valid if camera.captureButton.waitForExistence(timeout: 5) { XCTAssertTrue(camera.captureButton.isEnabled, "Capture button should be enabled") } else { // Permission not granted — verify a valid permission state is shown XCTAssertTrue(camera.hasValidState(), "Should show permission or capture UI") } } @MainActor func testCaptureButtonAccessibilityLabel() throws { launchClean() let camera = CameraScreen(app: app) if camera.captureButton.waitForExistence(timeout: 5) { XCTAssertFalse(camera.captureButton.label.isEmpty, "Capture button should have an accessibility label") } // If no capture button (permission denied), test passes — no assertion needed } // MARK: - Error Handling @MainActor func testCameraErrorAlertDismissal() throws { launchClean() // Camera is default tab, so we're already there let errorAlert = app.alerts.firstMatch if errorAlert.waitForExistence(timeout: 5) { let okButton = errorAlert.buttons["OK"] if okButton.exists { okButton.tap() XCTAssertTrue(errorAlert.waitUntilGone(), "Alert should dismiss") } } // If no alert appears, the test passes — no error state to dismiss } }