Branchwell

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

1import XCTest
2
3final class PulseCanvasMobileUITests: XCTestCase {
4 @MainActor func testSelectAtmosphericVisualizers() {
5 let app = XCUIApplication()
6 app.launchArguments = ["-PCMobileQA", "-PCMobileFullSoundtrackQA"]
7 app.launch()
8 let library = app.buttons["mobileLibraryButton"]
9 XCTAssertTrue(library.waitForExistence(timeout: 30))
10 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
11 waitForExpectations(timeout: 90)
12
13 let names = ["Backlit Rift", "Undersurface", "Mercury Ribbon", "Ember Front", "Anvil Flyover", "Pigment Strata"]
14 let search = app.textFields["modalVisualizerSearch"]
15 let selection = app.staticTexts["mobileVisualizerName"]
16 for (offset, name) in names.enumerated() {
17 library.tap()
18 XCTAssertTrue(search.waitForExistence(timeout: 10))
19 search.tap()
20 search.typeText(name + "\n")
21 let row = app.buttons["libraryVisualizer-\(456 + offset)"]
22 XCTAssertTrue(row.waitForExistence(timeout: 10), name)
23 row.coordinate(withNormalizedOffset: CGVector(dx: 0.25, dy: 0.5)).tap()
24 expectation(for: NSPredicate(format: "label == %@", name), evaluatedWith: selection)
25 waitForExpectations(timeout: 15)
26 let evidence = XCTAttachment(screenshot: app.screenshot())
27 evidence.name = name
28 evidence.lifetime = .keepAlways
29 add(evidence)
30 }
31 }
32
33 override func setUp() { continueAfterFailure = false }
34 @MainActor func testStudioDoubleTapFavoritesInEditorAndPresentation() {
35 verifyDoubleTapFavorites(radioMode: false)
36 }
37
38 @MainActor func testRadioDoubleTapFavoritesAndPresentationControls() {
39 verifyDoubleTapFavorites(radioMode: true)
40 }
41
42 @MainActor private func verifyDoubleTapFavorites(radioMode: Bool) {
43 XCUIDevice.shared.orientation = .portrait
44 defer { XCUIDevice.shared.orientation = .portrait }
45 let app = XCUIApplication()
46 app.launchArguments = radioMode
47 ? ["-PCMobileQA", "-PCMobileRadioQA", "-PCMobileStationsQA"]
48 : ["-PCMobileQA", "-PCMobileFullSoundtrackQA"]
49 app.launch()
50 let library = app.buttons["mobileLibraryButton"]
51 XCTAssertTrue(library.waitForExistence(timeout: 30))
52 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
53 waitForExpectations(timeout: 90)
54 if radioMode { app.buttons["Radio"].tap() }
55 let play = app.buttons[radioMode ? "radioPlaybackButton" : "mobilePlaybackButton"]
56 let position = radioMode ? app.sliders["radioSongPosition"] : app.sliders["Soundtrack position"]
57 if radioMode {
58 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play)
59 waitForExpectations(timeout: 30)
60 play.tap()
61 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: position)
62 waitForExpectations(timeout: 30)
63 play.tap()
64 }
65 let preview = app.otherElements[radioMode ? "mobileRadioPreview" : "mobileVisualizerPreview"]
66 let heart = app.buttons[radioMode ? "Favorite radio visualizer" : "Favorite visualizer"]
67 func value(_ element: XCUIElement) -> String { String(describing: element.value ?? "") }
68 func expectValue(_ element: XCUIElement, _ expected: String) {
69 expectation(for: NSPredicate(format: "value == %@", expected), evaluatedWith: element)
70 waitForExpectations(timeout: 5)
71 }
72 func capture(_ name: String) {
73 let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
74 shot.name = name; shot.lifetime = .keepAlways; add(shot)
75 }
76 XCTAssertTrue(preview.waitForExistence(timeout: 10))
77 if value(heart) == "Favorited" { heart.tap() }
78 let originalName = value(preview), originalPosition = value(position)
79 let originalSong = radioMode ? app.staticTexts["radioCurrentSongTitle"].label : ""
80 preview.doubleTap()
81 expectValue(heart, "Favorited")
82 preview.doubleTap()
83 expectValue(heart, "Favorited")
84 XCTAssertEqual(value(preview), originalName)
85 XCTAssertEqual(value(position), originalPosition)
86 XCTAssertEqual(play.label, "Play")
87 capture("\(radioMode ? "Radio" : "Studio")-editor-double-tap")
88
89 app.buttons["mobilePresentationButton"].tap()
90 let full = app.otherElements["mobilePresentationPreview"]
91 XCTAssertTrue(full.waitForExistence(timeout: 10))
92 let fullHeart = app.buttons["presentationVisualizerFavorite"]
93 expectValue(fullHeart, "Favorited")
94 XCTAssertEqual(app.staticTexts["presentationVisualizerTitle"].label, originalName)
95 fullHeart.tap()
96 expectValue(fullHeart, "Not favorited")
97 full.doubleTap()
98 expectValue(fullHeart, "Favorited")
99 XCTAssertTrue(app.buttons["Close"].isHittable, "Double-tap must not toggle presentation controls")
100 full.doubleTap()
101 expectValue(fullHeart, "Favorited")
102 capture("\(radioMode ? "Radio" : "Studio")-full-screen-double-tap")
103 if radioMode {
104 XCTAssertEqual(app.staticTexts["presentationSongTitle"].label, originalSong)
105 let songHeart = app.buttons["presentationSongFavorite"]
106 songHeart.tap(); expectValue(songHeart, "Favorited")
107 songHeart.tap(); expectValue(songHeart, "Not favorited")
108 let next = app.buttons["presentationNextSong"]
109 XCTAssertTrue(next.isHittable)
110 next.tap()
111 expectation(for: NSPredicate(format: "label != %@", originalSong), evaluatedWith: app.staticTexts["presentationSongTitle"])
112 waitForExpectations(timeout: 15)
113 XCTAssertEqual(app.buttons["presentationPlayback"].label, "Play", "Next must preserve pause state")
114 app.buttons["presentationStationPicker"].tap()
115 app.buttons["Next station"].tap()
116 expectation(for: NSPredicate(format: "value == %@", "Electronic"), evaluatedWith: app.buttons["presentationStationPicker"])
117 waitForExpectations(timeout: 20)
118 let fullPlay = app.buttons["presentationPlayback"]
119 XCTAssertEqual(fullPlay.label, "Pause")
120 fullPlay.tap()
121 XCTAssertEqual(app.staticTexts["presentationSongTitle"].label, "Radio test soundtrack 2")
122 app.buttons["presentationStationPicker"].tap()
123 app.buttons["All music"].tap()
124 expectation(for: NSPredicate(format: "value == %@", "All music"), evaluatedWith: app.buttons["presentationStationPicker"])
125 waitForExpectations(timeout: 20)
126 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: fullPlay)
127 waitForExpectations(timeout: 20)
128 fullPlay.tap()
129 }
130 full.tap()
131 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: app.buttons["Close"])
132 waitForExpectations(timeout: 5)
133 full.doubleTap()
134 XCTAssertFalse(app.buttons["Close"].exists, "Double-tap while controls are hidden must keep them hidden")
135 full.tap()
136 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 5))
137 for orientation in [UIDeviceOrientation.portrait, .landscapeLeft] {
138 XCUIDevice.shared.orientation = orientation
139 expectation(for: NSPredicate { _, _ in
140 let window = app.windows.firstMatch.frame
141 let landscape = window.width > window.height
142 return landscape == (orientation == .landscapeLeft)
143 && window.minX >= 0 && window.minY >= 0 && window.contains(fullHeart.frame)
144 }, evaluatedWith: app)
145 waitForExpectations(timeout: 10)
146 for control in [fullHeart, app.buttons["Close"], app.buttons["presentationPlayback"], app.buttons["Randomize"]] {
147 XCTAssertTrue(control.isHittable)
148 XCTAssertTrue(app.windows.firstMatch.frame.contains(control.frame), control.debugDescription)
149 }
150 if radioMode {
151 for control in [app.buttons["presentationSongFavorite"], app.buttons["presentationStationPicker"], app.buttons["presentationNextSong"]] {
152 XCTAssertTrue(control.isHittable, control.debugDescription)
153 XCTAssertTrue(app.windows.firstMatch.frame.contains(control.frame), control.debugDescription)
154 }
155 }
156 capture("\(radioMode ? "Radio" : "Studio")-presentation-controls-\(orientation.rawValue)")
157 }
158 app.buttons["Close"].tap()
159 if !radioMode { XCTAssertEqual(value(position), originalPosition) }
160 // Exercise the gesture while music is playing, without seeking or stopping it.
161 play.tap()
162 preview.doubleTap()
163 XCTAssertEqual(play.label, "Pause")
164 XCTAssertEqual(value(heart), "Favorited")
165 play.tap()
166 }
167
168 @MainActor func testStudioPreviewSwipesKeepMusicAndCurrentScene() {
169 verifyPreviewSwipes(radioMode: false)
170 }
171
172 @MainActor func testRadioPreviewSwipesKeepCurrentSong() {
173 verifyPreviewSwipes(radioMode: true)
174 }
175
176 @MainActor private func verifyPreviewSwipes(radioMode: Bool) {
177 let app = XCUIApplication()
178 app.launchArguments = radioMode
179 ? ["-PCMobileQA", "-PCMobileRadioQA"]
180 : ["-PCMobileQA", "-PCMobileFullSoundtrackQA"]
181 app.launch()
182 let library = app.buttons["mobileLibraryButton"]
183 XCTAssertTrue(library.waitForExistence(timeout: 30))
184 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
185 waitForExpectations(timeout: 90)
186 if radioMode {
187 app.buttons["Radio"].tap()
188 app.buttons["Randomize visualizer group"].tap()
189 app.buttons["Randomize Drive & flight"].tap()
190 } else {
191 library.tap()
192 app.buttons["Randomize visualizer group"].tap()
193 app.buttons["Randomize Drive & flight"].tap()
194 app.buttons["Done"].tap()
195 }
196 let play = app.buttons[radioMode ? "radioPlaybackButton" : "mobilePlaybackButton"]
197 let position = radioMode ? app.sliders["radioSongPosition"] : app.sliders["Soundtrack position"]
198 if radioMode {
199 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play)
200 waitForExpectations(timeout: 30)
201 play.tap()
202 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: position)
203 waitForExpectations(timeout: 30)
204 play.tap()
205 }
206 XCTAssertEqual(play.label, "Play")
207 position.adjust(toNormalizedSliderPosition: 0)
208 let preview = app.otherElements[radioMode ? "mobileRadioPreview" : "mobileVisualizerPreview"]
209 XCTAssertTrue(preview.waitForExistence(timeout: 10))
210 let mode = radioMode ? "Radio" : "Studio"
211 func visualizer(_ element: XCUIElement) -> String { String(describing: element.value ?? "") }
212 func capture(_ name: String) {
213 let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
214 shot.name = name; shot.lifetime = .keepAlways; add(shot)
215 }
216 func expectChange(_ element: XCUIElement, from previous: String) {
217 expectation(for: NSPredicate { _, _ in
218 !visualizer(element).isEmpty && visualizer(element) != previous
219 }, evaluatedWith: element)
220 waitForExpectations(timeout: 5)
221 }
222 let originalPosition = String(describing: position.value)
223 let originalSong = radioMode ? app.staticTexts["radioCurrentSongTitle"].label : ""
224 let sceneChoice = app.otherElements["currentStudioClip"].buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Choose visualizer for scene")).firstMatch
225 let originalScene = radioMode ? "" : sceneChoice.label
226 let unchanged = visualizer(preview)
227 preview.swipeUp()
228 XCTAssertEqual(visualizer(preview), unchanged)
229 preview.swipeDown()
230 XCTAssertEqual(visualizer(preview), unchanged)
231 let middle = preview.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
232 middle.press(forDuration: 0.05, thenDragTo: middle.withOffset(CGVector(dx: -16, dy: 0)))
233 XCTAssertEqual(visualizer(preview), unchanged)
234 capture("\(mode)-editor-before-swipe")
235 preview.swipeLeft()
236 expectChange(preview, from: unchanged)
237 capture("\(mode)-editor-after-swipe")
238 let afterLeft = visualizer(preview)
239 preview.swipeRight()
240 expectChange(preview, from: afterLeft)
241 XCTAssertEqual(String(describing: position.value), originalPosition, "Swipes must not seek the soundtrack")
242 XCTAssertEqual(play.label, "Play", "Swipes must preserve pause state")
243 if radioMode { XCTAssertEqual(app.staticTexts["radioCurrentSongTitle"].label, originalSong) }
244 else { XCTAssertEqual(sceneChoice.label, originalScene, "Swipes replace the look in the current scene") }
245
246 // The Library uses the selected group as its filter. The new name must
247 // be present there, rather than coming from the unrestricted catalog.
248 let chosen = visualizer(preview)
249 library.tap()
250 let group = app.buttons.matching(identifier: "Randomize visualizer group").firstMatch
251 XCTAssertTrue(String(describing: group.value).contains("Drive & flight"))
252 let search = app.textFields["modalVisualizerSearch"]
253 search.tap(); search.typeText(chosen + "\n")
254 let match = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "libraryVisualizer-")).firstMatch
255 XCTAssertTrue(match.waitForExistence(timeout: 5), "Swipes must stay within the selected group")
256 app.buttons["Done"].tap()
257
258 app.buttons["mobilePresentationButton"].tap()
259 let full = app.otherElements["mobilePresentationPreview"]
260 XCTAssertTrue(full.waitForExistence(timeout: 10))
261 let fullBefore = visualizer(full)
262 capture("\(mode)-full-screen-before-swipe")
263 full.swipeLeft()
264 expectChange(full, from: fullBefore)
265 XCTAssertTrue(app.buttons["Close"].isHittable, "A swipe must not also hide the controls")
266 let fullAfter = visualizer(full)
267 full.swipeRight()
268 expectChange(full, from: fullAfter)
269 capture("\(mode)-full-screen-after-swipe")
270 full.tap()
271 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: app.buttons["Close"])
272 waitForExpectations(timeout: 5)
273 full.tap()
274 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 5))
275 app.buttons["Close"].tap()
276 XCTAssertEqual(String(describing: position.value), originalPosition)
277
278 position.adjust(toNormalizedSliderPosition: 0)
279 play.tap()
280 XCTAssertEqual(play.label, "Pause")
281 let playingBefore = visualizer(preview)
282 preview.swipeLeft()
283 expectChange(preview, from: playingBefore)
284 XCTAssertEqual(play.label, "Pause", "A swipe must keep the music playing")
285 if radioMode { XCTAssertEqual(app.staticTexts["radioCurrentSongTitle"].label, originalSong) }
286 play.tap()
287 }
288
289 @MainActor func testPreviewDiceRandomizesStyleWithoutChangingVisualizer() {
290 let app = XCUIApplication()
291 app.launchArguments = ["-PCMobileQA"]
292 XCUIDevice.shared.orientation = .portrait
293 defer { XCUIDevice.shared.orientation = .portrait }
294 app.launch()
295 let library = app.buttons["mobileLibraryButton"]
296 XCTAssertTrue(library.waitForExistence(timeout: 30))
297 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
298 waitForExpectations(timeout: 90)
299 for orientation in [UIDeviceOrientation.portrait, .landscapeLeft] {
300 XCUIDevice.shared.orientation = orientation
301 let dice = app.buttons["mobileRandomizeStyleButton"]
302 let shuffle = app.buttons["Random visualizer"]
303 let style = app.buttons["Visual style"]
304 expectation(for: NSPredicate { _, _ in
305 let controls = [dice, shuffle, style, app.buttons["Present visualizer"]]
306 return controls.allSatisfy { $0.isHittable && $0.frame.width >= 44 && $0.frame.height >= 44 && app.windows.firstMatch.frame.contains($0.frame) }
307 && abs(dice.frame.midY - shuffle.frame.midY) < 2
308 }, evaluatedWith: app)
309 waitForExpectations(timeout: 15)
310 for button in [dice, shuffle, style, app.buttons["Present visualizer"]] {
311 XCTAssertTrue(button.isHittable)
312 XCTAssertGreaterThanOrEqual(button.frame.width, 44)
313 XCTAssertGreaterThanOrEqual(button.frame.height, 44)
314 XCTAssertTrue(app.windows.firstMatch.frame.contains(button.frame))
315 }
316 XCTAssertEqual(dice.frame.midY, shuffle.frame.midY, accuracy: 2)
317 XCTAssertGreaterThan(dice.frame.midX, shuffle.frame.midX)
318 XCTAssertLessThan(dice.frame.midX, style.frame.midX)
319 let presentation = app.buttons["mobilePresentationButton"]
320 let more = app.buttons["Project actions"]
321 XCTAssertEqual(presentation.frame.midY, library.frame.midY, accuracy: 2)
322 XCTAssertGreaterThan(presentation.frame.midX, library.frame.midX)
323 XCTAssertLessThan(presentation.frame.midX, more.frame.midX)
324 for (top, bottom) in [(library, shuffle), (presentation, dice), (more, style)] {
325 XCTAssertEqual(top.frame.midX, bottom.frame.midX, accuracy: 1)
326 XCTAssertEqual(top.frame.width, bottom.frame.width, accuracy: 1)
327 XCTAssertEqual(top.frame.height, bottom.frame.height, accuracy: 1)
328 }
329 let timeline = app.scrollViews["mobileStudioTimeline"]
330 XCTAssertTrue(timeline.exists)
331 XCTAssertTrue(app.windows.firstMatch.frame.contains(timeline.frame), "The timeline must remain inside the screen after aligning the controls")
332 presentation.tap()
333 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10))
334 let close = app.buttons["Close"]
335 XCTAssertGreaterThanOrEqual(close.frame.height, 44)
336 XCTAssertLessThanOrEqual(app.windows.firstMatch.frame.maxY - close.frame.maxY, 16)
337 let presentationShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
338 presentationShot.name = orientation == .portrait ? "Compact-presentation-portrait" : "Compact-presentation-landscape"
339 presentationShot.lifetime = .keepAlways
340 add(presentationShot)
341 app.buttons["Close"].tap()
342 let name = app.staticTexts["mobileVisualizerName"].label
343 style.tap()
344 XCTAssertTrue(app.buttons["Reset"].waitForExistence(timeout: 10))
345 app.buttons["Reset"].tap()
346 let before = ["Chaos", "Motion speed", "Zoom speed"].map { String(describing: app.sliders[$0].value) }
347 app.buttons["mobileSheetDone"].tap()
348 dice.tap()
349 XCTAssertEqual(app.staticTexts["mobileVisualizerName"].label, name)
350 style.tap()
351 XCTAssertTrue(app.buttons["Reset"].waitForExistence(timeout: 10))
352 let after = ["Chaos", "Motion speed", "Zoom speed"].map { String(describing: app.sliders[$0].value) }
353 XCTAssertNotEqual(after, before, "Dice changes the current look while keeping the selected visualizer")
354 app.buttons["mobileSheetDone"].tap()
355 let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
356 shot.name = orientation == .portrait ? "Preview-dice-portrait" : "Preview-dice-landscape"
357 shot.lifetime = .keepAlways
358 add(shot)
359 app.buttons["Radio"].tap()
360 XCTAssertEqual(presentation.label, "Present radio")
361 presentation.tap()
362 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10))
363 app.buttons["Close"].tap()
364 app.buttons["Studio"].tap()
365 }
366 }
367
368 /// Settings has no rating, feedback, support or more-apps rows.
369 @MainActor func testSettingsHasNoRatingFeedbackOrSupportRows() {
370 let app = XCUIApplication()
371 app.launchArguments = ["-PCMobileQA"]
372 app.launch()
373 let actions = app.buttons["Project actions"]
374 XCTAssertTrue(actions.waitForExistence(timeout: 60))
375 actions.tap()
376 app.buttons["Settings"].tap()
377 XCTAssertTrue(app.buttons["settingsWelcomePulseCanvas"].waitForExistence(timeout: 10))
378 attachSettings(app, name: "Settings top")
379 for _ in 0..<12 { app.swipeUp(velocity: .slow) }
380 for identifier in ["settingsRatePulseCanvas", "settingsFeedbackPulseCanvas", "settingsTechnicalSupport"] {
381 XCTAssertFalse(app.buttons[identifier].exists, identifier)
382 }
383 for label in ["Rate on the App Store", "Send Feedback", "Get support", "More Free Apps from Project ATOM"] {
384 XCTAssertFalse(app.buttons[label].exists, label)
385 }
386 attachSettings(app, name: "Settings bottom")
387 }
388
389 @MainActor private func attachSettings(_ app: XCUIApplication, name: String) {
390 let shot = XCTAttachment(screenshot: app.screenshot())
391 shot.name = name
392 shot.lifetime = .keepAlways
393 add(shot)
394 }
395
396 @MainActor func testLibraryOnlyBrowsingAndSettingsAlwaysRestartOnboarding() {
397 verifyLibraryAndOnboardingReplay(landscape: true)
398 }
399
400 @MainActor func testPortraitLibraryAndOnboardingReplay() {
401 verifyLibraryAndOnboardingReplay(landscape: false)
402 }
403
404 @MainActor private func verifyLibraryAndOnboardingReplay(landscape: Bool) {
405 let app = XCUIApplication()
406 XCUIDevice.shared.orientation = landscape ? .landscapeLeft : .portrait
407 defer { XCUIDevice.shared.orientation = .portrait }
408 app.launchArguments = ["-PCMobileQA", "-PCOnboardingQA", "-PCOnboardingStep", "3"]
409 app.launch()
410 XCTAssertTrue(app.buttons["onboardingContinue"].waitForExistence(timeout: 30))
411 XCTAssertTrue(app.otherElements["onboardingProgress"].label.contains("Step 4 of 4"))
412 app.buttons["onboardingContinue"].tap()
413 let library = app.buttons["mobileLibraryButton"]
414 XCTAssertTrue(library.waitForExistence(timeout: 30))
415 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
416 waitForExpectations(timeout: 90)
417 XCTAssertFalse(app.descendants(matching: .any)["sidebarVisualizerList"].exists)
418 XCTAssertFalse(app.textFields["sidebarVisualizerSearch"].exists)
419 for chooseResult in [false, true] {
420 library.tap()
421 let search = app.textFields["modalVisualizerSearch"]
422 XCTAssertTrue(search.waitForExistence(timeout: 10))
423 search.tap(); search.typeText("LED Corridor")
424 if chooseResult {
425 app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "libraryVisualizer-")).firstMatch.tap()
426 } else {
427 app.buttons["mobileSheetDone"].tap()
428 }
429 XCTAssertTrue(search.waitForNonExistence(timeout: 10))
430 XCTAssertTrue(app.keyboards.firstMatch.waitForNonExistence(timeout: 10), "Closing Library must dismiss the keyboard and its accessory bar")
431 XCTAssertTrue(library.isHittable)
432 }
433 XCTAssertEqual(app.staticTexts["mobileVisualizerName"].label, "LED Corridor")
434 let preview = app.otherElements["mobileVisualizerPreview"]
435 XCTAssertTrue(preview.exists)
436 XCTAssertLessThan(preview.frame.minX - app.windows.firstMatch.frame.minX, 32)
437 XCTAssertLessThan(app.windows.firstMatch.frame.maxX - preview.frame.maxX, 32)
438 let editorShot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
439 editorShot.name = "Editor-without-sidebar-or-keyboard-bar"
440 editorShot.lifetime = .keepAlways
441 add(editorShot)
442 for _ in 0..<2 {
443 app.buttons["Project actions"].tap()
444 app.buttons["Settings"].tap()
445 let welcome = app.buttons["settingsWelcomePulseCanvas"]
446 XCTAssertTrue(welcome.waitForExistence(timeout: 10))
447 welcome.tap()
448 let progress = app.otherElements["onboardingProgress"]
449 XCTAssertTrue(progress.waitForExistence(timeout: 10))
450 XCTAssertTrue(progress.label.contains("Step 1 of 4"))
451 app.buttons["onboardingContinue"].tap()
452 XCTAssertTrue(progress.label.contains("Step 2 of 4"))
453 app.buttons["onboardingSkip"].tap()
454 XCTAssertTrue(library.waitForExistence(timeout: 30))
455 }
456 }
457
458 @MainActor private func nameSaveDestination(in app: XCUIApplication, prefix: String) {
459 let filename = app.textFields["DOCPicker.filenameTextField"]
460 XCTAssertTrue(filename.waitForExistence(timeout: 10))
461 let value = filename.value as? String ?? ""
462 filename.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
463 filename.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: value.count + 10) + prefix + UUID().uuidString)
464 }
465 @MainActor func testPersonalFolderRadioStaysOutOfStudio() throws {
466 let app = XCUIApplication()
467 XCUIDevice.shared.orientation = .portrait
468 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA", "-PCMobileFolderQA"]
469 app.launch()
470 let library = app.buttons["mobileLibraryButton"]
471 XCTAssertTrue(library.waitForExistence(timeout: 30))
472 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
473 waitForExpectations(timeout: 90)
474 app.buttons["Radio"].tap()
475 let title = app.staticTexts["radioCurrentSongTitle"]
476 expectation(for: NSPredicate(format: "label == %@", "Personal song"), evaluatedWith: title)
477 waitForExpectations(timeout: 60)
478 XCTAssertEqual(app.buttons["radioPlaybackButton"].label, "Pause")
479 XCTAssertFalse(app.buttons["Favorite song"].exists)
480 XCTAssertFalse(app.buttons["Favorite songs"].exists)
481 XCTAssertTrue(app.buttons["Favorite radio visualizer"].exists)
482 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
483 XCTAssertFalse(app.buttons["Export MP4"].isEnabled)
484 app.buttons["Choose music"].tap()
485 let songs = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "studioMusicSong-"))
486 expectation(for: NSPredicate { _, _ in songs.count == 2 }, evaluatedWith: app)
487 waitForExpectations(timeout: 30)
488 XCTAssertFalse(app.buttons["Use Personal song in Studio"].exists)
489 app.buttons["cancelStudioMusic"].tap()
490 app.buttons["Next song"].tap()
491 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: app.buttons["radioPlaybackButton"])
492 waitForExpectations(timeout: 30)
493 XCTAssertEqual(title.label, "Personal song", "A one-song album loops")
494 app.buttons["radioStationPicker"].tap()
495 XCTAssertTrue(app.buttons["Choose music folder…"].exists)
496 app.buttons["All music"].tap()
497 XCTAssertTrue(app.buttons["Favorite song"].waitForExistence(timeout: 30))
498 XCTAssertTrue(title.label.hasPrefix("Radio test soundtrack"))
499 }
500
501 @MainActor func testChooseLibrarySongAsStudioSoundtrack() throws {
502 let app = XCUIApplication()
503 XCUIDevice.shared.orientation = .portrait
504 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
505 app.launch()
506 let library = app.buttons["mobileLibraryButton"]
507 XCTAssertTrue(library.waitForExistence(timeout: 30))
508 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
509 waitForExpectations(timeout: 90)
510 app.buttons["Radio"].tap()
511 let radioPlay = app.buttons["radioPlaybackButton"]
512 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: radioPlay)
513 waitForExpectations(timeout: 30)
514 radioPlay.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
515 XCTAssertTrue(app.buttons["Favorite song"].waitForExistence(timeout: 30))
516 let title = app.staticTexts["radioCurrentSongTitle"].label
517 app.buttons["Favorite song"].tap()
518 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(); app.buttons["Choose music"].tap()
519 let songs = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "studioMusicSong-"))
520 expectation(for: NSPredicate { _, _ in songs.count == 2 }, evaluatedWith: app)
521 waitForExpectations(timeout: 30)
522 app.buttons["cancelStudioMusic"].tap()
523 XCTAssertEqual(radioPlay.label, "Pause", "Canceling the picker must not stop Radio")
524 XCTAssertEqual(app.staticTexts["radioCurrentSongTitle"].label, title)
525 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(); app.buttons["Choose music"].tap()
526 expectation(for: NSPredicate { _, _ in songs.count == 2 }, evaluatedWith: app)
527 waitForExpectations(timeout: 30)
528 app.buttons["Favorites"].tap()
529 XCTAssertEqual(songs.count, 1)
530 let search = app.textFields["studioMusicSearch"]
531 search.tap(); search.typeText("no such song\n")
532 XCTAssertTrue(app.staticTexts["No matching favorite songs"].waitForExistence(timeout: 5))
533 app.buttons["clearStudioMusicSearch"].tap()
534 expectation(for: NSPredicate { _, _ in songs.count == 1 }, evaluatedWith: app)
535 waitForExpectations(timeout: 5)
536 XCTAssertFalse(app.buttons["clearStudioMusicSearch"].exists)
537 app.buttons["Use \(title) in Studio"].coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5)).tap()
538 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: app.buttons["cancelStudioMusic"])
539 waitForExpectations(timeout: 90)
540 XCTAssertTrue(app.buttons["Studio"].isSelected)
541 XCTAssertTrue(app.staticTexts[title].exists, "Studio must show the song title rather than a cache hash")
542 XCTAssertTrue(app.buttons["Play scene 1"].exists, "Loading a library song creates the Studio timeline")
543 app.buttons["mobilePlaybackButton"].tap()
544 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: app.buttons["mobilePlaybackButton"])
545 waitForExpectations(timeout: 15)
546 app.buttons["mobilePlaybackButton"].tap()
547 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(); app.buttons["Export MP4"].tap()
548 XCTAssertTrue(app.buttons["Render video"].waitForExistence(timeout: 10))
549 app.buttons["720p"].tap(); app.buttons["Render video"].tap()
550 XCTAssertTrue(app.buttons["Save video"].waitForExistence(timeout: 180), "Library songs must export with the normal Studio renderer")
551 }
552 @MainActor func testExpandedWorkspaceAndTabSwitching() throws {
553 let app = XCUIApplication()
554 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
555 app.launch()
556 let library = app.buttons["mobileLibraryButton"]
557 XCTAssertTrue(library.waitForExistence(timeout: 30))
558 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
559 waitForExpectations(timeout: 90)
560 let window = app.windows.firstMatch
561 print("EXPANDED window: \(window.frame)")
562 print("EXPANDED header: \(app.otherElements["mobileWorkspaceHeader"].frame)")
563 if window.frame.width >= 520 && window.frame.width > window.frame.height
564 || window.frame.width >= 350 && window.frame.height >= 600 {
565 let card = app.otherElements["currentStudioClip"]
566 XCTAssertTrue(card.waitForExistence(timeout: 10))
567 XCTAssertGreaterThan(card.frame.maxY, window.frame.maxY - 25, "Cards should sit at the bottom of the display")
568 XCTAssertLessThanOrEqual(card.frame.maxY, window.frame.maxY + 1)
569 XCTAssertTrue(app.buttons["Apply to all"].isHittable)
570 XCTAssertTrue(app.buttons["Randomize timeline"].isHittable)
571 }
572 let sidebar = app.descendants(matching: .any)["sidebarVisualizerList"]
573 XCTAssertFalse(sidebar.exists, "Visualizer browsing belongs in Library on every mobile display")
574 library.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
575 let modal = app.descendants(matching: .any)["modalVisualizerList"]
576 XCTAssertTrue(modal.waitForExistence(timeout: 10))
577 XCTAssertGreaterThan(modal.frame.maxY, window.frame.maxY - 5, "Library picker should use its full height")
578 print("PC_EXPANDED_CAPTURE library")
579 Thread.sleep(forTimeInterval: 5)
580 app.buttons["Done"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
581 for round in 0..<3 {
582 let start = Date()
583 app.buttons["Radio"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
584 let play = app.buttons["radioPlaybackButton"]
585 XCTAssertTrue(play.waitForExistence(timeout: 10))
586 print("TAB_SWITCH Radio \(round): \(Date().timeIntervalSince(start)) seconds")
587 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play)
588 waitForExpectations(timeout: 30)
589 if round == 0 {
590 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
591 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.sliders["radioSongPosition"])
592 waitForExpectations(timeout: 45)
593 }
594 let back = Date()
595 app.buttons["Studio"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
596 XCTAssertTrue(app.buttons["mobilePlaybackButton"].waitForExistence(timeout: 10))
597 print("TAB_SWITCH Studio \(round): \(Date().timeIntervalSince(back)) seconds")
598 }
599 print("PC_EXPANDED_CAPTURE studio")
600 Thread.sleep(forTimeInterval: 6)
601 }
602
603 /// Real library and export UI for the Duo marketing artwork (no QA fixture data).
604 @MainActor func testCaptureDuoMarketingDetails() throws {
605 let app = XCUIApplication()
606 app.launch()
607 let library = app.buttons["mobileLibraryButton"]
608 XCTAssertTrue(library.waitForExistence(timeout: 30))
609 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
610 waitForExpectations(timeout: 90)
611 app.buttons["Studio"].tap()
612 library.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
613 XCTAssertTrue(app.textFields["modalVisualizerSearch"].waitForExistence(timeout: 10))
614 print("PC_MARKETING_CAPTURE library")
615 Thread.sleep(forTimeInterval: 8)
616 app.buttons["Done"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
617 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
618 app.buttons["Export MP4"].tap()
619 XCTAssertTrue(app.buttons["4K"].waitForExistence(timeout: 15))
620 app.buttons["4K"].tap()
621 app.buttons["60 fps"].tap()
622 print("PC_MARKETING_CAPTURE export")
623 Thread.sleep(forTimeInterval: 8)
624 app.buttons["Done"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
625 }
626 /// Current production layout with the real soundtrack and live Radio catalog.
627 /// The host captures the active display at each marker; no QA fixture UI.
628 @MainActor func testCaptureCurrentMarketingLayout() throws {
629 if let pose = ProcessInfo.processInfo.environment["PC_MARKETING_ORIENTATION"] {
630 XCUIDevice.shared.orientation = pose == "landscape" ? .landscapeLeft : .portrait
631 }
632 let app = XCUIApplication()
633 app.launchArguments = ["-PCUITesting"] // Skip onboarding, retaining the real soundtrack and live Radio.
634 app.launch()
635 func tap(_ element: XCUIElement) {
636 element.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
637 }
638 func capture(_ name: String) {
639 print("PC_CURRENT_CAPTURE \(name) window=\(app.windows.firstMatch.frame)")
640 Thread.sleep(forTimeInterval: 7)
641 }
642 let library = app.buttons["mobileLibraryButton"]
643 XCTAssertTrue(library.waitForExistence(timeout: 30))
644 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
645 waitForExpectations(timeout: 90)
646 tap(app.buttons["Studio"]); tap(library)
647 let search = app.textFields["modalVisualizerSearch"]
648 XCTAssertTrue(search.waitForExistence(timeout: 10))
649 let groups = app.buttons.matching(identifier: "Randomize visualizer group")
650 tap(groups.element(boundBy: max(0, groups.count - 1))); app.buttons["Randomize all"].tap()
651 search.tap(); search.typeText("LED Corridor\n")
652 let choices = app.buttons.containing(.staticText, identifier: "LED Corridor")
653 XCTAssertTrue(choices.firstMatch.waitForExistence(timeout: 10))
654 let choice = choices.element(boundBy: max(0, choices.count - 1))
655 choice.coordinate(withNormalizedOffset: CGVector(dx: 0.25, dy: 0.5)).tap()
656 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: search); waitForExpectations(timeout: 15)
657 tap(app.buttons["Visual style"])
658 XCTAssertTrue(app.buttons["mobilePalettePicker"].waitForExistence(timeout: 10))
659 tap(app.buttons["mobilePalettePicker"]); app.buttons["Blue Hour"].tap()
660 app.sliders["Chaos"].adjust(toNormalizedSliderPosition: 0.8)
661 tap(app.buttons["Done"])
662 tap(app.buttons["Play scene 1"])
663 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: app.buttons["mobilePlaybackButton"])
664 waitForExpectations(timeout: 15)
665 Thread.sleep(forTimeInterval: 2); capture("studio")
666 tap(app.buttons["Present visualizer"])
667 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10))
668 Thread.sleep(forTimeInterval: 5); capture("fullscreen")
669 app.windows.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
670 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10)); tap(app.buttons["Close"])
671 tap(app.buttons["mobilePlaybackButton"])
672 tap(app.buttons["Visual style"])
673 XCTAssertTrue(app.navigationBars["Visual style"].waitForExistence(timeout: 10)); capture("style")
674 tap(app.buttons["Done"]); tap(app.buttons["Radio"])
675 let play = app.buttons["radioPlaybackButton"]
676 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play); waitForExpectations(timeout: 60)
677 tap(play)
678 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.sliders["radioSongPosition"]); waitForExpectations(timeout: 90)
679 Thread.sleep(forTimeInterval: 2); capture("radio"); tap(play)
680 tap(app.buttons["Studio"]); tap(library)
681 XCTAssertTrue(search.waitForExistence(timeout: 10)); capture("library"); tap(app.buttons["Done"])
682 tap(app.buttons["Project actions"]); app.buttons["Export MP4"].tap()
683 XCTAssertTrue(app.buttons["4K"].waitForExistence(timeout: 15))
684 app.buttons["4K"].tap(); app.buttons["60 fps"].tap(); capture("export")
685 tap(app.buttons["Done"])
686 }
687
688 /// Opt-in native marketing captures with a different featured visualizer per slide.
689 @MainActor func testCaptureVariedMarketingLayout() throws {
690 let env = ProcessInfo.processInfo.environment
691 guard env["PC_MARKETING_VARIETY"] == "1" else { throw XCTSkip("Marketing capture is opt-in") }
692 XCUIDevice.shared.orientation = env["PC_MARKETING_ORIENTATION"] == "landscape" ? .landscapeLeft : .portrait
693 let app = XCUIApplication()
694 app.launchArguments = ["-PCMobileQA", "-PCMobileFullSoundtrackQA"]
695 app.launch()
696 func tap(_ e: XCUIElement) { e.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap() }
697 let library = app.buttons["mobileLibraryButton"]
698 XCTAssertTrue(library.waitForExistence(timeout: 30))
699 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
700 waitForExpectations(timeout: 90)
701 let search = app.textFields["modalVisualizerSearch"]
702 func choose(_ name: String) {
703 tap(library)
704 XCTAssertTrue(search.waitForExistence(timeout: 10))
705 let groups = app.buttons.matching(identifier: "Randomize visualizer group")
706 tap(groups.element(boundBy: max(0, groups.count - 1))); app.buttons["Randomize all"].tap()
707 search.tap(); search.typeText(name + "\n")
708 let choice = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "libraryVisualizer-")).containing(.staticText, identifier: name).firstMatch
709 XCTAssertTrue(choice.waitForExistence(timeout: 10))
710 choice.coordinate(withNormalizedOffset: CGVector(dx: 0.25, dy: 0.5)).tap()
711 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: search); waitForExpectations(timeout: 15)
712 }
713 func capture(_ name: String, _ effect: String) {
714 Thread.sleep(forTimeInterval: 1)
715 print("PC_VARIETY_CAPTURE \(name) effect=\(effect) window=\(app.windows.firstMatch.frame)")
716 if let dir = env["PC_MARKETING_ACK_DIRECTORY"] {
717 let root = URL(fileURLWithPath: dir, isDirectory: true)
718 XCTAssertNoThrow(try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true))
719 XCTAssertNoThrow(try name.write(to: root.appendingPathComponent("stage.txt"), atomically: true, encoding: .utf8))
720 let ack = root.appendingPathComponent(name + ".ack").path
721 let deadline = Date().addingTimeInterval(90)
722 while !FileManager.default.fileExists(atPath: ack), Date() < deadline { Thread.sleep(forTimeInterval: 0.2) }
723 XCTAssertTrue(FileManager.default.fileExists(atPath: ack), "Native capture missing: " + name)
724 } else { Thread.sleep(forTimeInterval: 6) }
725 }
726 if env["PC_MARKETING_DUO_CLOSED"] == "1" {
727 if env["PC_MARKETING_CLOSED_HERO"] == "1" {
728 choose("Oil Marble")
729 tap(app.buttons["Present visualizer"])
730 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10))
731 Thread.sleep(forTimeInterval: 5)
732 capture("closed-hero", "Oil Marble")
733 return
734 }
735 choose("Ink Bloom"); capture("closed-studio", "Ink Bloom")
736 tap(library)
737 XCTAssertTrue(search.waitForExistence(timeout: 10))
738 capture("closed-library", "Ink Bloom")
739 return
740 }
741 func style(_ palette: String) {
742 tap(app.buttons["Visual style"])
743 XCTAssertTrue(app.buttons["Reset"].waitForExistence(timeout: 10))
744 tap(app.buttons["Reset"])
745 tap(app.buttons["mobilePalettePicker"]); app.buttons[palette].tap()
746 tap(app.buttons["Done"])
747 }
748 tap(app.buttons["Studio"])
749 choose("Plasma Bore"); style("Ultraviolet")
750 let leadOnly = env["PC_MARKETING_LEAD_ONLY"] == "1"
751 if !leadOnly { tap(app.buttons["Play scene 1"]); Thread.sleep(forTimeInterval: 2) }
752 capture("studio", "Plasma Bore")
753 if !leadOnly { tap(app.buttons["mobilePlaybackButton"]) }
754 choose("Mercury Fold"); style("Ultraviolet")
755 if !leadOnly { tap(app.buttons["Play scene 1"]) }
756 tap(app.buttons["Present visualizer"])
757 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10))
758 Thread.sleep(forTimeInterval: 5); capture("fullscreen", "Mercury Fold")
759 if leadOnly {
760 if env["PC_MARKETING_REFRESH_RADIO"] == "1" {
761 tap(app.buttons["Close"]); tap(app.buttons["Radio"])
762 let play = app.buttons["radioPlaybackButton"]
763 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play); waitForExpectations(timeout: 90)
764 tap(play)
765 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.sliders["radioSongPosition"]); waitForExpectations(timeout: 90)
766 if app.staticTexts["Mercury Fold"].isHittable { tap(app.buttons["Random radio visualizer"]) }
767 capture("radio", "Live Radio selection distinct from opening")
768 }
769 return
770 }
771 app.windows.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
772 tap(app.buttons["Close"]); tap(app.buttons["mobilePlaybackButton"])
773 choose("Aurora Fold"); tap(app.buttons["Visual style"])
774 XCTAssertTrue(app.navigationBars["Visual style"].waitForExistence(timeout: 10)); capture("style", "Aurora Fold")
775 tap(app.buttons["Done"]); tap(app.buttons["Radio"])
776 let play = app.buttons["radioPlaybackButton"]
777 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play); waitForExpectations(timeout: 90)
778 tap(play)
779 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.sliders["radioSongPosition"]); waitForExpectations(timeout: 90)
780 capture("radio", "Live Radio selection"); tap(play)
781 tap(app.buttons["Studio"]); choose("Orbit Loom"); tap(library)
782 XCTAssertTrue(search.waitForExistence(timeout: 10)); capture("library", "Orbit Loom"); tap(app.buttons["Done"])
783 choose("Lotus Resonance")
784 tap(app.buttons["Project actions"]); app.buttons["Export MP4"].tap()
785 XCTAssertTrue(app.buttons["4K"].waitForExistence(timeout: 15)); app.buttons["4K"].tap(); app.buttons["60 fps"].tap()
786 capture("export", "Lotus Resonance"); tap(app.buttons["Done"])
787 let availability = env["PC_MARKETING_AVAILABILITY_EFFECT"] ?? "Ink Bloom"
788 choose(availability); capture("availability", availability)
789 }
790
791 @MainActor func testCaptureDuoStoreScreenshots() throws {
792 let app = XCUIApplication()
793 app.launch()
794 let library = app.buttons["mobileLibraryButton"]
795 XCTAssertTrue(library.waitForExistence(timeout: 30))
796 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
797 waitForExpectations(timeout: 90)
798 app.buttons["Studio"].tap()
799 library.tap()
800 let search = app.textFields["modalVisualizerSearch"]
801 XCTAssertTrue(search.waitForExistence(timeout: 10))
802 let groupChoices = app.buttons.matching(identifier: "Randomize visualizer group")
803 groupChoices.element(boundBy: max(0, groupChoices.count - 1)).tap()
804 app.buttons["Randomize all"].tap()
805 search.tap(); search.typeText("Octagon Vault\n")
806 let choices = app.buttons.containing(.staticText, identifier: "Octagon Vault")
807 let foundChoice = choices.firstMatch.waitForExistence(timeout: 10)
808 if !foundChoice { print("LIBRARY SEARCH VALUE: \(String(describing: search.value))\n" + app.debugDescription) }
809 XCTAssertTrue(foundChoice)
810 // The front sheet follows matching cards/sidebar rows in the hierarchy.
811 let choose = choices.element(boundBy: max(0, choices.count - 1))
812 XCTAssertTrue(choose.isHittable)
813 choose.coordinate(withNormalizedOffset: CGVector(dx: 0.25, dy: 0.5)).tap()
814 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: search)
815 waitForExpectations(timeout: 15)
816 let play = app.buttons["mobilePlaybackButton"]
817 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
818 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: play)
819 waitForExpectations(timeout: 15)
820 Thread.sleep(forTimeInterval: 3)
821 print("PC_STORE_CAPTURE studio")
822 Thread.sleep(forTimeInterval: 8)
823 app.buttons["Present visualizer"].tap()
824 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10))
825 Thread.sleep(forTimeInterval: 5)
826 print("PC_STORE_CAPTURE fullscreen")
827 Thread.sleep(forTimeInterval: 8)
828 app.windows.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
829 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10)); app.buttons["Close"].tap()
830 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
831 app.buttons["Visual style"].tap()
832 XCTAssertTrue(app.navigationBars["Visual style"].waitForExistence(timeout: 10))
833 print("PC_STORE_CAPTURE style")
834 Thread.sleep(forTimeInterval: 8)
835 app.buttons["Done"].tap()
836 app.buttons["Radio"].tap()
837 let radioPlay = app.buttons["radioPlaybackButton"]
838 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: radioPlay)
839 waitForExpectations(timeout: 60)
840 radioPlay.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
841 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.sliders["radioSongPosition"])
842 waitForExpectations(timeout: 90)
843 Thread.sleep(forTimeInterval: 3)
844 print("PC_STORE_CAPTURE radio")
845 Thread.sleep(forTimeInterval: 8)
846 radioPlay.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
847 }
848 /// Run on Duo's inner and outer displays; capture real UI while checking
849 /// the transport survives a geometry change without resetting the session.
850 @MainActor func testAdaptiveWindowStudioAndRadio() throws {
851 let app = XCUIApplication()
852 XCUIDevice.shared.orientation = .portrait
853 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
854 app.launch()
855 let library = app.buttons["mobileLibraryButton"]
856 XCTAssertTrue(library.waitForExistence(timeout: 30))
857 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
858 waitForExpectations(timeout: 90)
859 // Duo can report the inactive display's orientation on the application
860 // element; the live window is the correct bounds for layout assertions.
861 let window = app.windows.firstMatch
862 print("Duo geometry: app=\(app.frame), window=\(window.frame), library=\(library.frame)")
863 for button in [app.buttons["Studio"], app.buttons["Radio"], library, app.buttons["Project actions"]] {
864 XCTAssertTrue(button.isHittable)
865 XCTAssertTrue(window.frame.insetBy(dx: -1, dy: -1).contains(button.frame))
866 }
867 if window.frame.width >= 850 && window.frame.width > window.frame.height {
868 XCTAssertTrue(app.otherElements["mobileStudioLandscape"].exists)
869 XCTAssertFalse(app.scrollViews.allElementsBoundByIndex.contains { $0.frame.height > 200 && $0.frame.width > 350 },
870 "Wide Studio must not have a vertical scroll container")
871 let clip = app.otherElements["currentStudioClip"]
872 XCTAssertTrue(clip.waitForExistence(timeout: 10))
873 XCTAssertTrue(window.frame.insetBy(dx: -1, dy: -1).contains(clip.frame), "Full scene card must fit vertically")
874 XCTAssertTrue(app.buttons["Apply to all"].isHittable)
875 }
876 library.tap()
877 let search = app.textFields["modalVisualizerSearch"]
878 XCTAssertTrue(search.waitForExistence(timeout: 10))
879 search.tap(); search.typeText("Octagon Vault\n")
880 let choices = app.buttons.containing(.staticText, identifier: "Octagon Vault")
881 let foundChoice = choices.firstMatch.waitForExistence(timeout: 10)
882 if !foundChoice { print("LIBRARY SEARCH VALUE: \(String(describing: search.value))\n" + app.debugDescription) }
883 XCTAssertTrue(foundChoice)
884 // The front sheet follows matching cards/sidebar rows in the hierarchy.
885 let choose = choices.element(boundBy: max(0, choices.count - 1))
886 XCTAssertTrue(choose.isHittable)
887 choose.coordinate(withNormalizedOffset: CGVector(dx: 0.25, dy: 0.5)).tap()
888 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: search)
889 waitForExpectations(timeout: 15)
890 XCTAssertEqual(app.staticTexts["mobileVisualizerName"].label, "Octagon Vault")
891 let studioPlay = app.buttons["mobilePlaybackButton"]
892 studioPlay.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
893 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: studioPlay)
894 waitForExpectations(timeout: 15)
895 Thread.sleep(forTimeInterval: 2)
896 XCTAssertFalse(app.staticTexts["mobileRenderError"].exists)
897 let studio = XCTAttachment(screenshot: app.screenshot())
898 studio.name = "Duo Studio"; studio.lifetime = .keepAlways; add(studio)
899 app.buttons["Visual style"].tap()
900 XCTAssertTrue(app.navigationBars["Visual style"].waitForExistence(timeout: 10))
901 let style = XCTAttachment(screenshot: app.screenshot())
902 style.name = "Duo Visual style"; style.lifetime = .keepAlways; add(style)
903 app.buttons["Done"].tap()
904 app.buttons["Radio"].tap()
905 let play = app.buttons["radioPlaybackButton"]
906 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play)
907 waitForExpectations(timeout: 30)
908 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
909 let scrubber = app.sliders["radioSongPosition"]
910 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: scrubber)
911 waitForExpectations(timeout: 30)
912 XCTAssertEqual(play.label, "Pause")
913 if window.frame.width >= 650 {
914 XCTAssertTrue(app.otherElements["mobileRadioLandscape"].exists)
915 XCTAssertEqual(app.scrollViews.count, 0)
916 for control in [play, scrubber, app.buttons["Next song"], app.buttons["Present radio"], app.buttons["radioStationPicker"]] {
917 XCTAssertTrue(control.isHittable)
918 XCTAssertTrue(window.frame.insetBy(dx: -1, dy: -1).contains(control.frame))
919 }
920 XCTAssertGreaterThan(app.otherElements["mobileRadioPreview"].frame.height, 180)
921 XCTAssertGreaterThanOrEqual(app.otherElements["mobileRadioPreview"].frame.maxX, window.frame.maxX - 20,
922 "Radio preview must extend below the side status region to the trailing margin")
923 }
924 Thread.sleep(forTimeInterval: 2)
925 let radio = XCTAttachment(screenshot: app.screenshot())
926 radio.name = "Duo Radio"; radio.lifetime = .keepAlways; add(radio)
927 XCUIDevice.shared.orientation = .landscapeLeft
928 // Some Duo runtime poses keep the active display orientation fixed
929 // even when XCTest rotates the inactive display. Assert live geometry.
930 print("Duo window after orientation request: \(window.frame)")
931 XCTAssertTrue(app.buttons["Radio"].waitForExistence(timeout: 10))
932 XCTAssertEqual(play.label, "Pause", "Resizing must retain playback")
933 let rotated = XCTAttachment(screenshot: app.screenshot())
934 rotated.name = "Duo Radio landscape"; rotated.lifetime = .keepAlways; add(rotated)
935 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
936 app.buttons["Studio"].tap()
937 if window.frame.width >= 650 && window.frame.width > window.frame.height {
938 XCTAssertTrue(app.otherElements["mobileStudioLandscape"].exists)
939 XCTAssertFalse(app.scrollViews.allElementsBoundByIndex.contains { $0.frame.height > 200 && $0.frame.width > 350 })
940 for control in [app.buttons["mobilePlaybackButton"], app.buttons["Present visualizer"], app.buttons["Apply to all"], app.otherElements["currentStudioClip"]] {
941 XCTAssertTrue(control.isHittable)
942 XCTAssertTrue(window.frame.insetBy(dx: -1, dy: -1).contains(control.frame), control.debugDescription)
943 }
944 }
945 }
946 @MainActor func testIPadLandscapeRadioFitsWithoutScrolling() throws {
947 let app = XCUIApplication()
948 defer { XCUIDevice.shared.orientation = .portrait }
949 func checkGroupedActions() {
950 let favorites = app.buttons["Favorite songs"].frame
951 let station = app.buttons["radioStationPicker"].frame
952 let next = app.buttons["Next song"].frame
953 XCTAssertEqual(station.minX - favorites.maxX, 8, accuracy: 1)
954 XCTAssertEqual(next.minX - station.maxX, 8, accuracy: 1)
955 XCTAssertEqual(favorites.midY, station.midY, accuracy: 1)
956 XCTAssertEqual(station.midY, next.midY, accuracy: 1)
957 }
958 XCUIDevice.shared.orientation = .landscapeLeft
959 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
960 app.launch()
961 let library = app.buttons["mobileLibraryButton"]
962 XCTAssertTrue(library.waitForExistence(timeout: 30))
963 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
964 waitForExpectations(timeout: 90)
965 for tab in [app.buttons["Studio"], app.buttons["Radio"]] {
966 XCTAssertTrue(tab.isHittable)
967 XCTAssertLessThan(tab.frame.midX, app.frame.midX, "iPad workspace tabs stay left-aligned")
968 XCTAssertGreaterThanOrEqual(tab.frame.minY, app.frame.minY + 60, "Tabs must sit below the window-control strip")
969 }
970 app.buttons["Radio"].tap()
971 let landscape = app.otherElements["mobileRadioLandscape"]
972 XCTAssertTrue(landscape.waitForExistence(timeout: 15))
973 XCTAssertEqual(app.scrollViews.count, 0, "Landscape Radio must fit without a scroll container")
974 let play = app.buttons["radioPlaybackButton"]
975 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play)
976 waitForExpectations(timeout: 30)
977 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
978 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.sliders["radioSongPosition"])
979 waitForExpectations(timeout: 30)
980 // Keep the short QA song stable while querying every control; a slow
981 // first simulator boot can otherwise advance during these assertions.
982 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
983 XCTAssertEqual(play.label, "Play")
984 if !app.buttons["Favorite radio visualizer"].exists { print("RADIO_CONTROL_DEBUG \(app.debugDescription)") }
985 let controls = [app.buttons["Randomize visualizer group"], app.buttons["Random radio visualizer"],
986 app.buttons["Present radio"], app.buttons["Favorite radio visualizer"],
987 app.buttons["Favorite song"], app.buttons["Favorite songs"], app.buttons["Next song"],
988 app.buttons["radioStationPicker"], play, app.sliders["radioSongPosition"], app.sliders["Radio volume"]]
989 for control in controls {
990 XCTAssertTrue(control.isHittable, "\(control.identifier) must be reachable without scrolling")
991 XCTAssertTrue(app.frame.insetBy(dx: -1, dy: -1).contains(control.frame), "\(control.identifier) must stay on screen")
992 }
993 XCTAssertGreaterThan(app.otherElements["mobileRadioPreview"].frame.height, 200)
994 checkGroupedActions()
995 app.buttons["Randomize visualizer group"].tap()
996 app.buttons["Randomize favorites"].tap()
997 let message = app.staticTexts["No saved favorite visualizers yet. Playing random visualizers from the full library."]
998 XCTAssertTrue(message.waitForExistence(timeout: 10))
999 XCTAssertTrue(message.isHittable)
1000 XCTAssertEqual(app.scrollViews.count, 0, "Fallback messaging must also fit")
1001 let screenshot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1002 screenshot.name = "Landscape Radio — all controls visible"; screenshot.lifetime = .keepAlways; add(screenshot)
1003 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1004 XCUIDevice.shared.orientation = .portrait
1005 XCTAssertTrue(landscape.waitForExistence(timeout: 10))
1006 XCTAssertEqual(app.scrollViews.count, 0, "A large portrait window also gives Radio a bounded preview")
1007 XCTAssertTrue(app.buttons["Studio"].isHittable)
1008 XCTAssertTrue(app.buttons["Radio"].isHittable)
1009 XCTAssertLessThan(app.buttons["Studio"].frame.minX, app.frame.minX + 40)
1010 XCTAssertGreaterThanOrEqual(app.buttons["Studio"].frame.minY, app.frame.minY + 60, "Portrait tabs must also sit below window controls")
1011 checkGroupedActions()
1012 let portrait = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
1013 portrait.name = "Portrait Radio — grouped actions"; portrait.lifetime = .keepAlways; add(portrait)
1014 XCUIDevice.shared.orientation = .landscapeRight
1015 XCTAssertTrue(landscape.waitForExistence(timeout: 10))
1016 XCTAssertEqual(app.scrollViews.count, 0)
1017 XCTAssertEqual(play.label, "Pause", "Rotation must not interrupt playback")
1018 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1019 }
1020 @MainActor func testBackgroundAudioAndRadioPresentation() throws {
1021 let app = XCUIApplication()
1022 XCUIDevice.shared.orientation = .portrait
1023 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
1024 app.launch()
1025 let library = app.buttons["mobileLibraryButton"]
1026 XCTAssertTrue(library.waitForExistence(timeout: 30))
1027 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
1028 waitForExpectations(timeout: 90)
1029 let studioPlay = app.buttons["mobilePlaybackButton"]
1030 studioPlay.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1031 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: studioPlay)
1032 waitForExpectations(timeout: 15)
1033 XCUIDevice.shared.press(.home)
1034 Thread.sleep(forTimeInterval: 3)
1035 app.activate()
1036 XCTAssertEqual(studioPlay.label, "Pause", "Studio audio must keep playing in the background")
1037 studioPlay.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1038 app.buttons["Radio"].tap()
1039 let picker = app.buttons["Randomize visualizer group"]
1040 XCTAssertTrue(picker.waitForExistence(timeout: 15))
1041 XCTAssertGreaterThanOrEqual(picker.frame.height, 51.9)
1042 picker.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5)).tap()
1043 app.buttons["Randomize all"].tap()
1044 let play = app.buttons["radioPlaybackButton"]
1045 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play)
1046 waitForExpectations(timeout: 30)
1047 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1048 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.sliders["radioSongPosition"])
1049 waitForExpectations(timeout: 30)
1050 let before = app.staticTexts["radioElapsedTime"].label
1051 let firstTitle = app.staticTexts["radioCurrentSongTitle"].label
1052 XCUIDevice.shared.press(.home)
1053 Thread.sleep(forTimeInterval: 3)
1054 app.activate()
1055 XCTAssertEqual(play.label, "Pause", "Radio audio must keep playing in the background")
1056 XCTAssertNotEqual(app.staticTexts["radioElapsedTime"].label, before, "The Radio clock must advance in the background")
1057 app.buttons["Present radio"].tap()
1058 XCTAssertTrue(app.buttons["presentationNextSong"].waitForExistence(timeout: 10))
1059 // Pause before inspecting controls so the genuine four-second idle
1060 // timer cannot hide them during slow simulator accessibility queries.
1061 app.buttons["presentationPlayback"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1062 XCTAssertFalse(app.buttons["Fit project aspect ratio"].exists)
1063 XCTAssertFalse(app.switches["Fit project aspect ratio"].exists)
1064 app.buttons["presentationPlayback"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1065 app.buttons["presentationNextSong"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1066 app.buttons["Close"].tap()
1067 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.sliders["radioSongPosition"])
1068 waitForExpectations(timeout: 30)
1069 XCTAssertNotEqual(app.staticTexts["radioCurrentSongTitle"].label, firstTitle)
1070 XCTAssertEqual(play.label, "Pause")
1071 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1072 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1073 XCTAssertTrue(app.buttons["Export MP4"].isEnabled, "A loaded Radio song must be exportable")
1074 app.buttons["Export MP4"].tap()
1075 XCTAssertTrue(app.buttons["Render video"].waitForExistence(timeout: 10))
1076 app.buttons["720p"].tap()
1077 app.buttons["Render video"].coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5)).tap()
1078 XCTAssertTrue(app.buttons["Save video"].waitForExistence(timeout: 180), "The actual current Radio song must render")
1079 app.buttons["Done"].tap()
1080 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(); app.buttons["Export MP4"].tap()
1081 XCTAssertTrue(app.buttons["Render video"].waitForExistence(timeout: 10))
1082 XCTAssertFalse(app.buttons["Save video"].exists, "A new export visit must not offer a stale previous movie")
1083 app.buttons["Done"].tap()
1084 }
1085 /// Additional editor controls not exercised by the playback/export tests.
1086 @MainActor func testStyleTimelineAndProjectMenus() throws {
1087 let app = XCUIApplication()
1088 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
1089 app.launch()
1090 let library = app.buttons["mobileLibraryButton"]
1091 XCTAssertTrue(library.waitForExistence(timeout: 30))
1092 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
1093 waitForExpectations(timeout: 90)
1094 app.buttons["Random visualizer"].tap()
1095 XCTAssertFalse(app.staticTexts["mobileVisualizerName"].label.isEmpty)
1096 app.buttons["Favorite visualizer"].tap()
1097 library.tap()
1098 let groups = app.buttons.matching(identifier: "Randomize visualizer group")
1099 groups.element(boundBy: max(0, groups.count - 1)).tap()
1100 app.buttons["Randomize favorites"].tap()
1101 XCTAssertTrue(app.textFields["modalVisualizerSearch"].exists)
1102 XCTAssertTrue(String(describing: groups.element(boundBy: max(0, groups.count - 1)).value).contains("favorites"))
1103 groups.element(boundBy: max(0, groups.count - 1)).tap()
1104 app.buttons["Randomize Drive & flight"].tap()
1105 XCTAssertTrue(String(describing: groups.element(boundBy: max(0, groups.count - 1)).value).contains("Drive & flight"))
1106 groups.element(boundBy: max(0, groups.count - 1)).tap()
1107 app.buttons["Randomize all"].tap()
1108 app.buttons["Done"].tap()
1109 app.buttons["Favorite visualizer"].tap()
1110 app.buttons["Visual style"].tap()
1111 XCTAssertTrue(app.buttons["Reset"].waitForExistence(timeout: 10))
1112 app.buttons["Reset"].tap()
1113 let defaultChaos = String(describing: app.sliders["Chaos"].value)
1114 let styleScroll = app.scrollViews["mobileStyleScroll"]
1115 func reveal(_ element: XCUIElement) {
1116 for _ in 0..<16 {
1117 if element.exists && element.isHittable { return }
1118 let backwards = element.exists && element.frame.midY < styleScroll.frame.minY + 70
1119 let start = styleScroll.coordinate(withNormalizedOffset: CGVector(dx: 0.03, dy: backwards ? 0.4 : 0.8))
1120 let end = styleScroll.coordinate(withNormalizedOffset: CGVector(dx: 0.03, dy: backwards ? 0.75 : 0.4))
1121 start.press(forDuration: 0.05, thenDragTo: end)
1122 }
1123 print("STYLE REVEAL FAILURE: \(styleScroll.frame) target: \(element.debugDescription)\n" + app.debugDescription)
1124 let failure = XCTAttachment(screenshot: app.screenshot()); failure.name = "Style reveal failure"; failure.lifetime = .keepAlways; add(failure)
1125 }
1126 for title in ["Chaos", "Motion speed", "Zoom speed", "Brightness", "Element size", "Depth", "Liquid detail", "Content blur"] {
1127 let slider = app.sliders[title]
1128 reveal(slider)
1129 XCTAssertTrue(slider.isHittable, title)
1130 slider.adjust(toNormalizedSliderPosition: 0.65)
1131 }
1132 let strobe = app.switches["mobileStrobeToggle"]
1133 reveal(strobe); XCTAssertTrue(strobe.isHittable)
1134 if strobe.value as? String == "0" { strobe.coordinate(withNormalizedOffset: CGVector(dx: 0.93, dy: 0.5)).tap() }
1135 XCTAssertEqual(strobe.value as? String, "1")
1136 for title in ["Strobe sensitivity", "Strobe strength"] {
1137 let slider = app.sliders[title]; reveal(slider)
1138 XCTAssertTrue(slider.isHittable); slider.adjust(toNormalizedSliderPosition: 0.45)
1139 }
1140 for _ in 0..<6 { if strobe.isHittable { break }; styleScroll.swipeDown() }
1141 strobe.coordinate(withNormalizedOffset: CGVector(dx: 0.93, dy: 0.5)).tap()
1142 XCTAssertEqual(strobe.value as? String, "0")
1143 for _ in 0..<6 { if app.buttons["Reset"].isHittable { break }; styleScroll.swipeDown() }
1144 app.buttons["Randomize visual style"].tap()
1145 app.buttons["Reset"].tap()
1146 XCTAssertEqual(String(describing: app.sliders["Chaos"].value), defaultChaos)
1147 app.buttons["mobilePalettePicker"].tap()
1148 app.buttons["Blue Hour"].tap()
1149 app.buttons["Done"].tap()
1150 app.buttons["Apply to all"].tap()
1151 XCTAssertTrue(app.buttons["Apply to all scenes"].waitForExistence(timeout: 10))
1152 XCTAssertFalse(app.buttons["Apply to all scenes"].isEnabled)
1153 for title in ["Bars per scene", "Chaos", "Zoom speed", "Motion speed"] {
1154 let toggle = app.switches[title]
1155 toggle.coordinate(withNormalizedOffset: CGVector(dx: 0.93, dy: 0.5)).tap()
1156 XCTAssertEqual(toggle.value as? String, "1", "Apply setting must enable: \(title)\n" + app.debugDescription)
1157 }
1158 for title in ["Common chaos", "Common zoom speed", "Common motion speed"] {
1159 app.sliders[title].adjust(toNormalizedSliderPosition: 0.4)
1160 }
1161 let bars = app.steppers["mobileCommonBars"]
1162 XCTAssertTrue(bars.isHittable)
1163 bars.buttons["mobileCommonBars-Increment"].tap()
1164 XCTAssertEqual(bars.value as? String, "5")
1165 app.buttons["Apply to all scenes"].tap()
1166 XCTAssertTrue(app.buttons["Apply to all"].waitForExistence(timeout: 10))
1167 app.buttons["Randomize timeline"].tap()
1168 XCTAssertTrue(app.buttons["Randomize visualizers"].waitForExistence(timeout: 10))
1169 app.buttons["Randomize visualizers"].tap()
1170 app.buttons["Randomize timeline"].tap(); app.buttons["Randomize bar lengths"].tap()
1171 app.buttons["Choose visualizer for scene 1"].tap()
1172 XCTAssertTrue(app.textFields["modalVisualizerSearch"].waitForExistence(timeout: 10))
1173 app.buttons["Done"].tap()
1174 }
1175 @MainActor func testProjectFileActions() throws {
1176 let app = XCUIApplication()
1177 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
1178 app.launch()
1179 let library = app.buttons["mobileLibraryButton"]
1180 XCTAssertTrue(library.waitForExistence(timeout: 30))
1181 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
1182 waitForExpectations(timeout: 90)
1183 for action in ["Open project", "Import audio"] {
1184 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1185 XCTAssertTrue(app.buttons[action].waitForExistence(timeout: 10))
1186 app.buttons[action].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1187 let cancel = app.buttons.matching(identifier: "Cancel").firstMatch
1188 let presented = cancel.waitForExistence(timeout: 20)
1189 if !presented { print("FILES ACTION FAILURE: \(action)\n" + app.debugDescription) }
1190 XCTAssertTrue(presented, "\(action) must present its Files interface")
1191 print("PC_FILES_CANCEL_BEFORE \(action): \(cancel.frame)")
1192 cancel.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1193 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: cancel)
1194 waitForExpectations(timeout: 15)
1195 expectation(for: NSPredicate { _, _ in app.buttons["Project actions"].isHittable }, evaluatedWith: app)
1196 waitForExpectations(timeout: 10)
1197 }
1198 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(); app.buttons["Save project"].tap()
1199 let saveProject = app.buttons["DOCPicker.actionButton"]
1200 XCTAssertTrue(saveProject.waitForExistence(timeout: 15))
1201 nameSaveDestination(in: app, prefix: "PulseCanvas-QA-Project-")
1202 saveProject.tap()
1203 expectation(for: NSPredicate(format: "exists == false"), evaluatedWith: saveProject)
1204 waitForExpectations(timeout: 15)
1205 XCTAssertTrue(app.buttons["Project actions"].isHittable)
1206 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(); app.buttons["About & Support"].tap()
1207 XCTAssertTrue(app.navigationBars["About & Support"].waitForExistence(timeout: 10))
1208 app.buttons["Done"].tap()
1209 }
1210 @MainActor func testSceneAndExportOptionControls() throws {
1211 let app = XCUIApplication()
1212 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
1213 app.launch()
1214 let library = app.buttons["mobileLibraryButton"]
1215 XCTAssertTrue(library.waitForExistence(timeout: 30))
1216 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
1217 waitForExpectations(timeout: 90)
1218 let loop = app.descendants(matching: .any).matching(identifier: "Loop soundtrack").firstMatch
1219 XCTAssertTrue(loop.isHittable)
1220 let originalLoop = "\(String(describing: loop.value))-\(loop.isSelected)"
1221 loop.tap(); XCTAssertNotEqual("\(String(describing: loop.value))-\(loop.isSelected)", originalLoop)
1222 loop.tap(); XCTAssertEqual("\(String(describing: loop.value))-\(loop.isSelected)", originalLoop)
1223 app.buttons["Play scene 1"].tap()
1224 let play = app.buttons["mobilePlaybackButton"]
1225 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: play)
1226 waitForExpectations(timeout: 10)
1227 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1228 let bars = app.steppers["sceneBars-0"]
1229 XCTAssertTrue(bars.isHittable)
1230 let before = bars.value as? String
1231 bars.buttons["sceneBars-0-Increment"].tap()
1232 XCTAssertNotEqual(bars.value as? String, before)
1233 bars.buttons["sceneBars-0-Decrement"].tap()
1234 XCTAssertEqual(bars.value as? String, before)
1235 app.buttons["Select scene 1"].coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.2)).tap()
1236 app.buttons["Present visualizer"].tap()
1237 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10))
1238 app.buttons["Randomize"].tap()
1239 let presentationPlay = app.buttons["presentationPlayback"]
1240 presentationPlay.tap()
1241 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: presentationPlay)
1242 waitForExpectations(timeout: 10); presentationPlay.tap()
1243 app.buttons["Close"].tap()
1244 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(); app.buttons["Export MP4"].tap()
1245 XCTAssertTrue(app.buttons["Render video"].waitForExistence(timeout: 10))
1246 let canvas = app.buttons["mobileExportCanvas"]
1247 for option in ["4:3 · Landscape", "3:4 · Portrait", "9:16 · Phone", "1:1 · Square", "16:9 · Wide"] {
1248 canvas.tap(); app.buttons[option].tap()
1249 XCTAssertTrue(canvas.label.contains(option) || String(describing: canvas.value).contains(option))
1250 }
1251 for option in ["1080p", "4K", "720p", "24 fps", "30 fps", "60 fps"] {
1252 app.buttons[option].tap(); XCTAssertTrue(app.buttons[option].isSelected)
1253 }
1254 app.buttons["4K"].tap()
1255 app.buttons["Render video"].tap()
1256 let cancel = app.buttons["Cancel export"]
1257 XCTAssertTrue(cancel.waitForExistence(timeout: 10)); cancel.tap()
1258 XCTAssertTrue(app.buttons["Render video"].waitForExistence(timeout: 30))
1259 XCTAssertFalse(app.buttons["Save video"].exists)
1260 app.buttons["720p"].tap(); app.buttons["30 fps"].tap()
1261 app.buttons["Done"].tap()
1262 }
1263 @MainActor func testRadioFavoriteSongControls() throws {
1264 let app = XCUIApplication()
1265 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
1266 app.launch()
1267 let library = app.buttons["mobileLibraryButton"]
1268 XCTAssertTrue(library.waitForExistence(timeout: 30))
1269 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
1270 waitForExpectations(timeout: 90)
1271 app.buttons["Radio"].tap()
1272 let play = app.buttons["radioPlaybackButton"]
1273 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play)
1274 waitForExpectations(timeout: 30)
1275 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1276 XCTAssertTrue(app.buttons["Favorite song"].waitForExistence(timeout: 30))
1277 let title = app.staticTexts["radioCurrentSongTitle"].label
1278 app.buttons["Favorite song"].tap()
1279 app.buttons["Favorite songs"].tap()
1280 XCTAssertTrue(app.buttons["Play favorite songs"].waitForExistence(timeout: 10))
1281 XCTAssertTrue(app.buttons["Play favorite songs"].isEnabled)
1282 app.buttons["Play favorite songs"].tap()
1283 expectation(for: NSPredicate(format: "label == %@", "Favorite songs"), evaluatedWith: app.buttons["radioStationPicker"])
1284 waitForExpectations(timeout: 10)
1285 let lists = app.buttons.matching(identifier: "Favorite songs")
1286 // The song-list button precedes the station picker with the same title.
1287 lists.firstMatch.tap()
1288 XCTAssertTrue(app.buttons["Unfavorite \(title)"].waitForExistence(timeout: 10))
1289 app.buttons["Unfavorite \(title)"].tap()
1290 XCTAssertFalse(app.buttons["Play favorite songs"].isEnabled)
1291 app.buttons["Done"].tap()
1292 app.buttons["radioStationPicker"].tap(); app.buttons["All music"].tap()
1293 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: play)
1294 waitForExpectations(timeout: 30)
1295 let visualHeart = app.buttons["Favorite radio visualizer"]
1296 visualHeart.tap(); visualHeart.tap()
1297 if app.sliders["Radio volume"].exists {
1298 app.sliders["Radio volume"].adjust(toNormalizedSliderPosition: 0.35)
1299 app.sliders["Radio volume"].adjust(toNormalizedSliderPosition: 0.75)
1300 }
1301 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1302 }
1303 @MainActor func testStudioCentersPlayingCard() throws {
1304 let app = XCUIApplication()
1305 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
1306 app.launch()
1307 let play = app.buttons["mobilePlaybackButton"]
1308 XCTAssertTrue(play.waitForExistence(timeout: 30))
1309 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: app.buttons["mobileLibraryButton"])
1310 waitForExpectations(timeout: 90)
1311 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1312 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: play)
1313 waitForExpectations(timeout: 15)
1314 app.sliders["Soundtrack position"].adjust(toNormalizedSliderPosition: 0.5)
1315 let current = app.otherElements["currentStudioClip"]
1316 let timeline = app.scrollViews["mobileStudioTimeline"]
1317 XCTAssertTrue(current.waitForExistence(timeout: 10))
1318 XCTAssertTrue(timeline.exists)
1319 expectation(for: NSPredicate { _, _ in
1320 abs(current.frame.midX - timeline.frame.midX) < 24
1321 }, evaluatedWith: app)
1322 waitForExpectations(timeout: 15)
1323 XCTAssertEqual(play.label, "Pause")
1324 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1325 }
1326 @MainActor func testRadioEmptyFavoritesAndScrubbing() throws {
1327 let app = XCUIApplication()
1328 XCUIDevice.shared.orientation = ProcessInfo.processInfo.environment["PC_MOBILE_LANDSCAPE"] == "1" ? .landscapeLeft : .portrait
1329 app.launchArguments = ["-PCMobileQA", "-PCMobileRadioQA"]
1330 app.launch()
1331 let library = app.buttons["mobileLibraryButton"]
1332 XCTAssertTrue(library.waitForExistence(timeout: 30))
1333 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: library)
1334 waitForExpectations(timeout: 90)
1335 app.buttons["Radio"].tap()
1336 let play = app.buttons["radioPlaybackButton"]
1337 XCTAssertTrue(play.waitForExistence(timeout: 20))
1338 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: play)
1339 waitForExpectations(timeout: 30)
1340 app.buttons["Randomize visualizer group"].tap()
1341 app.buttons["Randomize favorites"].tap()
1342 let fallback = app.staticTexts["No saved favorite visualizers yet. Playing random visualizers from the full library."]
1343 XCTAssertTrue(fallback.waitForExistence(timeout: 10))
1344 XCTAssertFalse(app.buttons["retryRadioButton"].exists)
1345 XCTAssertTrue(play.isEnabled)
1346 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1347 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: play)
1348 waitForExpectations(timeout: 30)
1349 let position = app.sliders["radioSongPosition"]
1350 expectation(for: NSPredicate(format: "enabled == true"), evaluatedWith: position)
1351 waitForExpectations(timeout: 30)
1352 let visualHeart = app.buttons["Favorite radio visualizer"]
1353 let songHeart = app.buttons["Favorite song"]
1354 let visualHeartFrame = visualHeart.frame
1355 let songHeartFrame = songHeart.frame
1356 let playFrame = play.frame
1357 XCTAssertLessThanOrEqual(visualHeartFrame.maxX, songHeartFrame.maxX + 1)
1358 XCTAssertGreaterThanOrEqual(playFrame.width, 57.9)
1359 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap(); XCTAssertEqual(play.label, "Play")
1360 position.adjust(toNormalizedSliderPosition: 0.35)
1361 XCTAssertEqual(play.label, "Play", "Scrubbing while paused must stay paused")
1362 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1363 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: play)
1364 waitForExpectations(timeout: 15)
1365 app.buttons["Random radio visualizer"].tap()
1366 XCTAssertEqual(play.label, "Pause", "Randomizing empty favorites must not stop Radio")
1367 XCTAssertFalse(app.buttons["retryRadioButton"].exists)
1368 XCTAssertEqual(visualHeart.frame.minX, visualHeartFrame.minX, accuracy: 1)
1369 XCTAssertEqual(songHeart.frame.minX, songHeartFrame.minX, accuracy: 1)
1370 XCTAssertEqual(play.frame.width, playFrame.width, accuracy: 1)
1371 let screenshot = XCTAttachment(screenshot: app.screenshot()); screenshot.name = "Radio empty favorites fallback"; screenshot.lifetime = .keepAlways; add(screenshot)
1372 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1373 }
1374 @MainActor func testStudioAndCompactControls() throws {
1375 let app = XCUIApplication()
1376 XCUIDevice.shared.orientation = ProcessInfo.processInfo.environment["PC_MOBILE_LANDSCAPE"] == "1" ? .landscapeLeft : .portrait
1377 app.launchArguments = ["-PCMobileQA"]
1378 app.launch()
1379 let library = app.buttons["mobileLibraryButton"]
1380 XCTAssertTrue(library.waitForExistence(timeout: 30))
1381 let enabled = NSPredicate(format: "enabled == true")
1382 expectation(for: enabled, evaluatedWith: library)
1383 waitForExpectations(timeout: 90)
1384 XCTAssertFalse(app.staticTexts["mobileRenderError"].exists)
1385 let first = XCTAttachment(screenshot: app.screenshot()); first.name = "Studio"; first.lifetime = .keepAlways; add(first)
1386 let play = app.buttons["mobilePlaybackButton"]
1387 let heart = app.buttons["Favorite visualizer"]
1388 let name = app.staticTexts["mobileVisualizerName"]
1389 XCTAssertLessThan(heart.frame.maxX, name.frame.minX)
1390 let heartFrame = heart.frame
1391 let playFrame = play.frame
1392 XCTAssertGreaterThanOrEqual(playFrame.width, 57.9)
1393 XCTAssertTrue(play.isHittable); play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1394 expectation(for: NSPredicate(format: "label == %@", "Pause"), evaluatedWith: play)
1395 waitForExpectations(timeout: 15)
1396 XCTAssertEqual(play.frame.width, playFrame.width, accuracy: 1)
1397 play.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1398 XCTAssertEqual(play.label, "Play")
1399 XCTAssertEqual(play.frame.width, playFrame.width, accuracy: 1)
1400 app.buttons["Visual style"].tap()
1401 XCTAssertTrue(app.sliders["Chaos"].waitForExistence(timeout: 10))
1402 XCTAssertTrue(app.sliders["Motion speed"].exists)
1403 XCTAssertTrue(app.sliders["Zoom speed"].exists)
1404 app.sliders["Chaos"].adjust(toNormalizedSliderPosition: 0.8)
1405 let style = XCTAttachment(screenshot: app.screenshot()); style.name = "Style controls"; style.lifetime = .keepAlways; add(style)
1406 app.buttons["Done"].tap()
1407 library.tap()
1408 let randomizers = app.buttons.matching(identifier: "Randomize visualizer group")
1409 XCTAssertTrue(randomizers.firstMatch.waitForExistence(timeout: 10))
1410 let randomizer = randomizers.element(boundBy: max(0, randomizers.count - 1))
1411 XCTAssertGreaterThanOrEqual(randomizer.frame.height, 51.9)
1412 let search = app.textFields["modalVisualizerSearch"]
1413 XCTAssertTrue(search.waitForExistence(timeout: 10))
1414 search.tap(); search.typeText("Mercury\n")
1415 let choices = app.buttons.containing(.staticText, identifier: "Mercury Fold")
1416 XCTAssertTrue(choices.firstMatch.waitForExistence(timeout: 10))
1417 choices.element(boundBy: max(0, choices.count - 1)).coordinate(withNormalizedOffset: CGVector(dx: 0.25, dy: 0.5)).tap()
1418 XCTAssertEqual(app.staticTexts["mobileVisualizerName"].label, "Mercury Fold")
1419 XCTAssertEqual(heart.frame.minX, heartFrame.minX, accuracy: 1)
1420 XCTAssertEqual(heart.frame.width, heartFrame.width, accuracy: 1)
1421 XCTAssertLessThan(heart.frame.maxX, name.frame.minX)
1422 let aligned = XCTAttachment(screenshot: app.screenshot()); aligned.name = "Leading heart and stable playback"; aligned.lifetime = .keepAlways; add(aligned)
1423 app.buttons["Present visualizer"].tap()
1424 XCTAssertTrue(app.buttons["Close"].waitForExistence(timeout: 10))
1425 let full = XCTAttachment(screenshot: app.screenshot()); full.name = "Full screen"; full.lifetime = .keepAlways; add(full)
1426 app.buttons["Close"].tap()
1427 app.buttons["Project actions"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1428 app.buttons["Export MP4"].tap()
1429 XCTAssertTrue(app.buttons["Render video"].waitForExistence(timeout: 10))
1430 XCTAssertTrue(app.buttons["Done"].exists)
1431 app.buttons["720p"].tap()
1432 app.buttons["Render video"].tap()
1433 XCTAssertTrue(app.buttons["Save video"].waitForExistence(timeout: 180), "The actual eight-second native movie must render")
1434 let export = XCTAttachment(screenshot: app.screenshot()); export.name = "Export settings"; export.lifetime = .keepAlways; add(export)
1435 let save = app.buttons["Save video"]
1436 XCTAssertGreaterThanOrEqual(save.frame.height, 51.9)
1437 save.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5)).tap()
1438 XCTAssertTrue(app.buttons["DOCPicker.actionButton"].waitForExistence(timeout: 15))
1439 let files = XCTAttachment(screenshot: app.screenshot()); files.name = "Native Files save destination"; files.lifetime = .keepAlways; add(files)
1440 // Debug QA exports have unique names, so prior saved movies remain intact.
1441 app.buttons["DOCPicker.actionButton"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
1442 let saved = app.staticTexts["Video saved"].waitForExistence(timeout: 20)
1443 if !saved { print("FILES SAVE RESULT\n" + app.debugDescription) }
1444 XCTAssertTrue(saved, "The actual native Files save must finish, not just render the movie")
1445 app.buttons["Done"].tap()
1446 XCTAssertFalse(app.staticTexts["mobileRenderError"].exists)
1447 }
1448}