import XCTest final class PulseCanvasOnboardingUITests: XCTestCase { override func setUp() { continueAfterFailure = false; executionTimeAllowance = 180 } @MainActor func testLastPageHasNoRatingOrSharingPrompt() throws { let app = XCUIApplication() app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA", "-PCOnboardingStep", "3"] app.launch() XCTAssertTrue(app.buttons["onboardingContinue"].waitForExistence(timeout: 30)) XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 4 of 4")) XCTAssertFalse(app.buttons["onboardingShare"].exists) XCTAssertFalse(app.buttons["onboardingRate"].exists) let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) shot.name = "PulseCanvas-onboarding-last-page" shot.lifetime = .keepAlways; add(shot) } @MainActor func testTextStaysTopLeftAlignedAcrossSlidesAndRotation() { let app = XCUIApplication() app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA"] app.launch() defer { XCUIDevice.shared.orientation = .portrait } let progress = app.otherElements["onboardingProgress"] XCTAssertTrue(progress.waitForExistence(timeout: 30)) for orientation in [UIDeviceOrientation.portrait, .landscapeLeft] { XCUIDevice.shared.orientation = orientation // Wait for the device's layout to settle before recording origins. let landscape = orientation == .landscapeLeft let rotated = NSPredicate { _, _ in (app.frame.width > app.frame.height) == landscape } expectation(for: rotated, evaluatedWith: app) waitForExpectations(timeout: 10) let title = app.staticTexts["onboardingTitle"] let subtitle = app.staticTexts["onboardingSubtitle"] let titleOrigin = title.frame.origin let subtitleOrigin = subtitle.frame.origin let buttonOrigin = app.buttons["onboardingContinue"].frame.origin for step in 1...4 { expectation(for: NSPredicate(format: "label BEGINSWITH %@", "Step \(step) of 4"), evaluatedWith: progress) waitForExpectations(timeout: 5) XCTAssertEqual(title.frame.minX, titleOrigin.x, accuracy: 1) XCTAssertEqual(title.frame.minY, titleOrigin.y, accuracy: 1) XCTAssertEqual(subtitle.frame.minX, subtitleOrigin.x, accuracy: 1) XCTAssertEqual(subtitle.frame.minY, subtitleOrigin.y, accuracy: 1) XCTAssertEqual(title.frame.minX, subtitle.frame.minX, accuracy: 1) XCTAssertEqual(app.buttons["onboardingContinue"].frame.minY, buttonOrigin.y, accuracy: 1) XCTAssertTrue(app.buttons["onboardingContinue"].isHittable) if UIDevice.current.userInterfaceIdiom == .pad && min(app.frame.width, app.frame.height) >= 1000 { let content = app.otherElements["onboardingContent"].frame let centerBetweenControls = (app.buttons["onboardingSkip"].frame.maxY + progress.frame.minY) / 2 XCTAssertEqual(content.midY, centerBetweenControls, accuracy: 12, "Center the image and copy between the header and navigation") XCTAssertGreaterThan(title.frame.height, 110, "Large iPads should use the larger title typography") } let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) attachment.name = "Onboarding-aligned-\(landscape ? "landscape" : "portrait")-\(step)" attachment.lifetime = .keepAlways add(attachment) if step < 4 { title.swipeLeft() } } for step in (1...3).reversed() { title.swipeRight() expectation(for: NSPredicate(format: "label BEGINSWITH %@", "Step \(step) of 4"), evaluatedWith: progress) waitForExpectations(timeout: 5) } } } @MainActor func testSwipingOverContinueDoesNotFinishOnboarding() { let app = XCUIApplication() app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA", "-PCOnboardingStep", "3"] app.launch() let next = app.buttons["onboardingContinue"] XCTAssertTrue(next.waitForExistence(timeout: 30)) next.coordinate(withNormalizedOffset: CGVector(dx: 0.8, dy: 0.5)) .press(forDuration: 0.05, thenDragTo: next.coordinate(withNormalizedOffset: CGVector(dx: 0.2, dy: 0.5))) XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 4 of 4")) next.tap() XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 30)) } @MainActor func testSwipesNavigateWithoutSkippingPagesOrFinishing() { let app = XCUIApplication() app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA"] app.launch() let progress = app.otherElements["onboardingProgress"] XCTAssertTrue(progress.waitForExistence(timeout: 30)) // Use actual content bounds, including on Duo's inner display where // the system status region sits beside the application surface. let page = app.staticTexts["onboardingTitle"] XCTAssertTrue(page.exists) func expectStep(_ step: Int) { let expected = NSPredicate(format: "label BEGINSWITH %@", "Step \(step) of 4") let change = expectation(for: expected, evaluatedWith: progress) wait(for: [change], timeout: 5) XCTAssertEqual(app.scrollViews.count, 0) XCTAssertTrue(app.buttons["onboardingContinue"].isHittable) } expectStep(1) page.swipeRight() expectStep(1) app.swipeUp() expectStep(1) let middle = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.45)) middle.press(forDuration: 0.05, thenDragTo: middle.withOffset(CGVector(dx: -16, dy: 0))) expectStep(1) page.swipeLeft() expectStep(2) page.swipeRight() expectStep(1) let flickStart = page.coordinate(withNormalizedOffset: CGVector(dx: 0.6, dy: 0.5)) flickStart.press(forDuration: 0.01, thenDragTo: flickStart.withOffset(CGVector(dx: -32, dy: 0)), withVelocity: .fast, thenHoldForDuration: 0) expectStep(2) page.swipeRight() expectStep(1) for step in 2...4 { page.swipeLeft() expectStep(step) } page.swipeLeft() expectStep(4) let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = "Onboarding-swipe-to-last-page" attachment.lifetime = .keepAlways add(attachment) page.swipeRight() expectStep(3) app.buttons["onboardingContinue"].tap() expectStep(4) app.buttons["onboardingContinue"].tap() XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 30)) } @MainActor func testImmediateSkipKeepsSettingsResponsiveWithFullSoundtrack() throws { let app = XCUIApplication() // Isolated storage, but use the real 2:54 bundled song rather than the // eight-second fixture so soundtrack startup isn't hidden by the test. app.launchArguments = ["-PCMobileQA", "-PCMobileFullSoundtrackQA", "-PCOnboardingQA"] app.launch() XCTAssertTrue(app.buttons["onboardingSkip"].waitForExistence(timeout: 15)) let start = ContinuousClock.now app.buttons["onboardingSkip"].tap() let actions = app.buttons["Project actions"] XCTAssertTrue(actions.waitForExistence(timeout: 3)) XCTAssertTrue(actions.isEnabled, "Soundtrack preparation must not disable Settings") let transition = start.duration(to: .now) print("Immediate onboarding skip to enabled editor controls: \(transition)") XCTAssertLessThan(transition, .seconds(4), "Leaving onboarding blocked the interface") actions.tap() XCTAssertTrue(app.buttons["Settings"].waitForExistence(timeout: 3)) app.buttons["Settings"].tap() XCTAssertTrue(app.buttons["settingsWelcomePulseCanvas"].waitForExistence(timeout: 3)) } @MainActor func testNavigationCompletionAndReplay() throws { let app = XCUIApplication() app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA"] app.launch() let next = app.buttons["onboardingContinue"] XCTAssertTrue(next.waitForExistence(timeout: 30)) XCTAssertFalse(app.buttons["mobileLibraryButton"].exists, "The editor must stay out of onboarding") for step in 1...4 { XCTAssertTrue(next.isHittable) XCTAssertEqual(app.scrollViews.count, 0, "Onboarding must fit without scrolling") XCTAssertTrue(app.buttons["onboardingSkip"].isHittable) XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step \(step) of 4")) let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = "Onboarding-\(step)" attachment.lifetime = .keepAlways add(attachment) if step < 4 { next.tap() } } XCTAssertEqual(app.scrollViews.count, 0, "Every onboarding page must fit without scrolling") app.buttons["onboardingBack"].tap() XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 3 of 4")) next.tap() next.tap() XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 90)) let actions = app.buttons["Project actions"] expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: actions) waitForExpectations(timeout: 90) actions.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap() app.buttons["Settings"].tap() let welcome = app.buttons["settingsWelcomePulseCanvas"] XCTAssertTrue(welcome.waitForExistence(timeout: 10)) welcome.tap() XCTAssertTrue(next.waitForExistence(timeout: 15)) XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 1 of 4")) app.buttons["onboardingSkip"].tap() XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 30)) } @MainActor func testLandscapeAndLargeTextKeepActionsReachable() throws { let app = XCUIApplication() app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA", "-PCOnboardingStep", "3", "-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"] XCUIDevice.shared.orientation = .landscapeLeft defer { XCUIDevice.shared.orientation = .portrait } app.launch() XCTAssertTrue(app.buttons["onboardingContinue"].waitForExistence(timeout: 30)) XCTAssertTrue(app.buttons["onboardingContinue"].isHittable) XCTAssertTrue(app.buttons["onboardingSkip"].isHittable) XCTAssertTrue(app.buttons["onboardingBack"].isHittable) XCTAssertEqual(app.scrollViews.count, 0) let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = "Onboarding-landscape-large-text" attachment.lifetime = .keepAlways add(attachment) app.buttons["onboardingSkip"].tap() XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 90)) } }