Branchwell

PulseCanvas / app · pulsecanvas.ai / mobile / UITests / PulseCanvasOnboardingUITests.swift

1import XCTest
2
3final class PulseCanvasOnboardingUITests: XCTestCase {
4 override func setUp() { continueAfterFailure = false; executionTimeAllowance = 180 }
5
6 @MainActor func testLastPageHasNoRatingOrSharingPrompt() throws {
7 let app = XCUIApplication()
8 app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA", "-PCOnboardingStep", "3"]
9 app.launch()
10 XCTAssertTrue(app.buttons["onboardingContinue"].waitForExistence(timeout: 30))
11 XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 4 of 4"))
12 XCTAssertFalse(app.buttons["onboardingShare"].exists)
13 XCTAssertFalse(app.buttons["onboardingRate"].exists)
14 let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
15 shot.name = "PulseCanvas-onboarding-last-page"
16 shot.lifetime = .keepAlways; add(shot)
17 }
18
19 @MainActor func testTextStaysTopLeftAlignedAcrossSlidesAndRotation() {
20 let app = XCUIApplication()
21 app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA"]
22 app.launch()
23 defer { XCUIDevice.shared.orientation = .portrait }
24 let progress = app.otherElements["onboardingProgress"]
25 XCTAssertTrue(progress.waitForExistence(timeout: 30))
26 for orientation in [UIDeviceOrientation.portrait, .landscapeLeft] {
27 XCUIDevice.shared.orientation = orientation
28 // Wait for the device's layout to settle before recording origins.
29 let landscape = orientation == .landscapeLeft
30 let rotated = NSPredicate { _, _ in
31 (app.frame.width > app.frame.height) == landscape
32 }
33 expectation(for: rotated, evaluatedWith: app)
34 waitForExpectations(timeout: 10)
35 let title = app.staticTexts["onboardingTitle"]
36 let subtitle = app.staticTexts["onboardingSubtitle"]
37 let titleOrigin = title.frame.origin
38 let subtitleOrigin = subtitle.frame.origin
39 let buttonOrigin = app.buttons["onboardingContinue"].frame.origin
40 for step in 1...4 {
41 expectation(for: NSPredicate(format: "label BEGINSWITH %@", "Step \(step) of 4"), evaluatedWith: progress)
42 waitForExpectations(timeout: 5)
43 XCTAssertEqual(title.frame.minX, titleOrigin.x, accuracy: 1)
44 XCTAssertEqual(title.frame.minY, titleOrigin.y, accuracy: 1)
45 XCTAssertEqual(subtitle.frame.minX, subtitleOrigin.x, accuracy: 1)
46 XCTAssertEqual(subtitle.frame.minY, subtitleOrigin.y, accuracy: 1)
47 XCTAssertEqual(title.frame.minX, subtitle.frame.minX, accuracy: 1)
48 XCTAssertEqual(app.buttons["onboardingContinue"].frame.minY, buttonOrigin.y, accuracy: 1)
49 XCTAssertTrue(app.buttons["onboardingContinue"].isHittable)
50 if UIDevice.current.userInterfaceIdiom == .pad && min(app.frame.width, app.frame.height) >= 1000 {
51 let content = app.otherElements["onboardingContent"].frame
52 let centerBetweenControls = (app.buttons["onboardingSkip"].frame.maxY + progress.frame.minY) / 2
53 XCTAssertEqual(content.midY, centerBetweenControls, accuracy: 12, "Center the image and copy between the header and navigation")
54 XCTAssertGreaterThan(title.frame.height, 110, "Large iPads should use the larger title typography")
55 }
56 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
57 attachment.name = "Onboarding-aligned-\(landscape ? "landscape" : "portrait")-\(step)"
58 attachment.lifetime = .keepAlways
59 add(attachment)
60 if step < 4 { title.swipeLeft() }
61 }
62 for step in (1...3).reversed() {
63 title.swipeRight()
64 expectation(for: NSPredicate(format: "label BEGINSWITH %@", "Step \(step) of 4"), evaluatedWith: progress)
65 waitForExpectations(timeout: 5)
66 }
67 }
68 }
69
70 @MainActor func testSwipingOverContinueDoesNotFinishOnboarding() {
71 let app = XCUIApplication()
72 app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA", "-PCOnboardingStep", "3"]
73 app.launch()
74 let next = app.buttons["onboardingContinue"]
75 XCTAssertTrue(next.waitForExistence(timeout: 30))
76 next.coordinate(withNormalizedOffset: CGVector(dx: 0.8, dy: 0.5))
77 .press(forDuration: 0.05, thenDragTo: next.coordinate(withNormalizedOffset: CGVector(dx: 0.2, dy: 0.5)))
78 XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 4 of 4"))
79 next.tap()
80 XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 30))
81 }
82
83 @MainActor func testSwipesNavigateWithoutSkippingPagesOrFinishing() {
84 let app = XCUIApplication()
85 app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA"]
86 app.launch()
87 let progress = app.otherElements["onboardingProgress"]
88 XCTAssertTrue(progress.waitForExistence(timeout: 30))
89 // Use actual content bounds, including on Duo's inner display where
90 // the system status region sits beside the application surface.
91 let page = app.staticTexts["onboardingTitle"]
92 XCTAssertTrue(page.exists)
93 func expectStep(_ step: Int) {
94 let expected = NSPredicate(format: "label BEGINSWITH %@", "Step \(step) of 4")
95 let change = expectation(for: expected, evaluatedWith: progress)
96 wait(for: [change], timeout: 5)
97 XCTAssertEqual(app.scrollViews.count, 0)
98 XCTAssertTrue(app.buttons["onboardingContinue"].isHittable)
99 }
100 expectStep(1)
101 page.swipeRight()
102 expectStep(1)
103 app.swipeUp()
104 expectStep(1)
105 let middle = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.45))
106 middle.press(forDuration: 0.05, thenDragTo: middle.withOffset(CGVector(dx: -16, dy: 0)))
107 expectStep(1)
108 page.swipeLeft()
109 expectStep(2)
110 page.swipeRight()
111 expectStep(1)
112 let flickStart = page.coordinate(withNormalizedOffset: CGVector(dx: 0.6, dy: 0.5))
113 flickStart.press(forDuration: 0.01, thenDragTo: flickStart.withOffset(CGVector(dx: -32, dy: 0)), withVelocity: .fast, thenHoldForDuration: 0)
114 expectStep(2)
115 page.swipeRight()
116 expectStep(1)
117 for step in 2...4 {
118 page.swipeLeft()
119 expectStep(step)
120 }
121 page.swipeLeft()
122 expectStep(4)
123 let attachment = XCTAttachment(screenshot: app.screenshot())
124 attachment.name = "Onboarding-swipe-to-last-page"
125 attachment.lifetime = .keepAlways
126 add(attachment)
127 page.swipeRight()
128 expectStep(3)
129 app.buttons["onboardingContinue"].tap()
130 expectStep(4)
131 app.buttons["onboardingContinue"].tap()
132 XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 30))
133 }
134
135 @MainActor func testImmediateSkipKeepsSettingsResponsiveWithFullSoundtrack() throws {
136 let app = XCUIApplication()
137 // Isolated storage, but use the real 2:54 bundled song rather than the
138 // eight-second fixture so soundtrack startup isn't hidden by the test.
139 app.launchArguments = ["-PCMobileQA", "-PCMobileFullSoundtrackQA", "-PCOnboardingQA"]
140 app.launch()
141 XCTAssertTrue(app.buttons["onboardingSkip"].waitForExistence(timeout: 15))
142 let start = ContinuousClock.now
143 app.buttons["onboardingSkip"].tap()
144 let actions = app.buttons["Project actions"]
145 XCTAssertTrue(actions.waitForExistence(timeout: 3))
146 XCTAssertTrue(actions.isEnabled, "Soundtrack preparation must not disable Settings")
147 let transition = start.duration(to: .now)
148 print("Immediate onboarding skip to enabled editor controls: \(transition)")
149 XCTAssertLessThan(transition, .seconds(4), "Leaving onboarding blocked the interface")
150 actions.tap()
151 XCTAssertTrue(app.buttons["Settings"].waitForExistence(timeout: 3))
152 app.buttons["Settings"].tap()
153 XCTAssertTrue(app.buttons["settingsWelcomePulseCanvas"].waitForExistence(timeout: 3))
154 }
155
156 @MainActor func testNavigationCompletionAndReplay() throws {
157 let app = XCUIApplication()
158 app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA"]
159 app.launch()
160 let next = app.buttons["onboardingContinue"]
161 XCTAssertTrue(next.waitForExistence(timeout: 30))
162 XCTAssertFalse(app.buttons["mobileLibraryButton"].exists, "The editor must stay out of onboarding")
163 for step in 1...4 {
164 XCTAssertTrue(next.isHittable)
165 XCTAssertEqual(app.scrollViews.count, 0, "Onboarding must fit without scrolling")
166 XCTAssertTrue(app.buttons["onboardingSkip"].isHittable)
167 XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step \(step) of 4"))
168 let attachment = XCTAttachment(screenshot: app.screenshot())
169 attachment.name = "Onboarding-\(step)"
170 attachment.lifetime = .keepAlways
171 add(attachment)
172 if step < 4 { next.tap() }
173 }
174 XCTAssertEqual(app.scrollViews.count, 0, "Every onboarding page must fit without scrolling")
175 app.buttons["onboardingBack"].tap()
176 XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 3 of 4"))
177 next.tap()
178 next.tap()
179 XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 90))
180 let actions = app.buttons["Project actions"]
181 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: actions)
182 waitForExpectations(timeout: 90)
183 actions.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
184 app.buttons["Settings"].tap()
185 let welcome = app.buttons["settingsWelcomePulseCanvas"]
186 XCTAssertTrue(welcome.waitForExistence(timeout: 10))
187 welcome.tap()
188 XCTAssertTrue(next.waitForExistence(timeout: 15))
189 XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 1 of 4"))
190 app.buttons["onboardingSkip"].tap()
191 XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 30))
192 }
193
194 @MainActor func testLandscapeAndLargeTextKeepActionsReachable() throws {
195 let app = XCUIApplication()
196 app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA", "-PCOnboardingStep", "3", "-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"]
197 XCUIDevice.shared.orientation = .landscapeLeft
198 defer { XCUIDevice.shared.orientation = .portrait }
199 app.launch()
200 XCTAssertTrue(app.buttons["onboardingContinue"].waitForExistence(timeout: 30))
201 XCTAssertTrue(app.buttons["onboardingContinue"].isHittable)
202 XCTAssertTrue(app.buttons["onboardingSkip"].isHittable)
203 XCTAssertTrue(app.buttons["onboardingBack"].isHittable)
204 XCTAssertEqual(app.scrollViews.count, 0)
205 let attachment = XCTAttachment(screenshot: app.screenshot())
206 attachment.name = "Onboarding-landscape-large-text"
207 attachment.lifetime = .keepAlways
208 add(attachment)
209 app.buttons["onboardingSkip"].tap()
210 XCTAssertTrue(app.buttons["mobileLibraryButton"].waitForExistence(timeout: 90))
211 }
212}