Repository Public
1// SP Notes iOS2// File: UITests/CaptureUITests.swift3// Description: Quick Capture and the voice note screen driven like a user, on the dedicated simulator: the sheet opens with the4// keyboard up, a text capture lands in the inbox list, the modes switch, the layout holds under Reduce Motion and at5// the largest Dynamic Type size, the recorder (with the DEBUG microphone stand-in) saves a voice capture, and the6// voice screen plays, seeks from the transcript and inserts the AI summary only on request.7//8// Author: Simon-Pierre Boucher9// Contact: contact@spboucher.ai10import XCTest1112final class CaptureUITests: XCTestCase {13 private var app: XCUIApplication!1415 override func setUp() {16 continueAfterFailure = false17 XCUIDevice.shared.orientation = .portrait18 }1920 private func launch(route: String, appearance: String = "light", environment: [String: String] = [:], arguments: [String] = []) {21 app = XCUIApplication()22 app.launchEnvironment = ["SPNOTES_STORE": "memory", "SPNOTES_SESSION": "local", "SPNOTES_SEED": "1", "SPNOTES_OPEN": route].merging(environment) { _, new in new }23 app.launchArguments = ["-appearance", appearance, "-lock.enabled", "NO", "-AppleLanguages", "(fr)", "-AppleLocale", "fr_CA"] + arguments24 app.launch()25 }2627 private func shot(_ name: String) {28 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())29 attachment.name = "iphone-\(name)"30 attachment.lifetime = .keepAlways31 add(attachment)32 }3334 private func element(_ id: String) -> XCUIElement { app.descendants(matching: .any).matching(identifier: id).firstMatch }3536 @discardableResult37 private func wait(_ id: String, timeout: TimeInterval = 15) -> XCUIElement {38 let target = element(id)39 XCTAssertTrue(target.waitForExistence(timeout: timeout), "\(id) appears")40 return target41 }4243 /// The inbox entry: under « Plus » on iPhone (tab structure of 2.0), in the sidebar on iPad.44 private func revealInbox() -> XCUIElement {45 let plus = app.tabBars.buttons["Plus"]46 if plus.waitForExistence(timeout: 8) { plus.tap() }47 let inbox = element(plus.exists ? "more-inbox" : "sidebar-inbox")48 _ = inbox.waitForExistence(timeout: 8)49 for _ in 0..<6 where !(inbox.exists && inbox.isHittable) { app.swipeUp(velocity: .slow) }50 XCTAssertTrue(inbox.waitForExistence(timeout: 3), "the inbox entry is reachable")51 return inbox52 }5354 func testTextCaptureIsSavedIntoTheInbox() {55 launch(route: "capture", environment: ["SPNOTES_CAPTURE_STAY": "1"])56 let title = wait("capture-title")57 XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10), "the keyboard is up as soon as the sheet opens")58 XCTAssertFalse(element("capture-save").isEnabled, "nothing to save yet")59 title.typeText("Rappeler la banque")60 element("capture-text").tap()61 app.typeText("Demander la prolongation du taux garanti.")62 shot("capture-text-filled")63 XCTAssertTrue(element("capture-save").isEnabled)64 element("capture-save").tap()65 wait("capture-saved")66 shot("capture-saved")67 element("capture-done").tap()6869 // the capture is in the inbox list (iPhone: under « Plus »; on iPad the sidebar is behind the debug route's cover: the70 // save itself was asserted above, the inbox list is covered by the shell tests)71 guard app.tabBars.buttons["Plus"].waitForExistence(timeout: 8) else { return }72 revealInbox().tap()73 XCTAssertTrue(app.staticTexts["Rappeler la banque"].waitForExistence(timeout: 10), "the capture is listed in the inbox")74 shot("capture-in-inbox")75 }7677 func testModesSwitchAndADraftSurvivesTheDismissal() {78 launch(route: "capture:link")79 let link = wait("capture-link")80 XCTAssertTrue(element("capture-mode-link").isSelected)81 link.typeText("https://example.com/article")82 XCTAssertTrue(element("capture-save").isEnabled)83 for mode in ["photo", "scan", "file", "dictation", "idea"] {84 let chip = element("capture-mode-\(mode)")85 for _ in 0..<4 where !chip.isHittable { element("capture-mode-photo").exists ? app.swipeLeft(velocity: .slow) : () }86 XCTAssertTrue(chip.waitForExistence(timeout: 5), mode)87 chip.tap()88 XCTAssertTrue(chip.isSelected, "\(mode) is selected")89 }90 // photo, scan and file have nothing yet: the save button says so by being disabled91 wait("capture-title").tap()92 app.typeText("Une idée à garder")93 XCTAssertTrue(element("capture-save").isEnabled)94 element("capture-cancel").tap()95 let keep = app.buttons["Garder le brouillon"]96 XCTAssertTrue(keep.waitForExistence(timeout: 5), "cancelling a capture with text asks before losing it")97 keep.tap()98 guard app.tabBars.buttons["Plus"].waitForExistence(timeout: 8) else { return }99 XCTAssertTrue(revealInbox().exists, "back on the home screen")100 }101102 func testReduceMotionAndTheLargestTextSizeKeepTheSheetUsable() {103 // Reduce Motion: the sheet content fades in (no scale); everything is there and works104 launch(route: "capture:idea", environment: ["SPNOTES_CAPTURE_STAY": "1"], arguments: ["-UIAccessibilityReduceMotionEnabled", "YES", "-ReduceMotionEnabled", "YES"])105 wait("capture-title").typeText("Idée sans animation")106 element("capture-save").tap()107 wait("capture-saved")108 shot("capture-reduce-motion-saved")109 app.terminate()110111 // accessibility XXXL: the mode strip scrolls, the title and the save button stay reachable112 launch(route: "capture", arguments: ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"])113 let title = wait("capture-title")114 let save = element("capture-save")115 XCTAssertTrue(title.isHittable && save.exists)116 title.typeText("Grand texte")117 XCTAssertTrue(save.isEnabled && save.isHittable, "the save button is on screen above the keyboard")118 XCTAssertLessThanOrEqual(save.frame.maxX, app.windows.firstMatch.frame.maxX + 1, "no horizontal overflow")119 XCTAssertGreaterThanOrEqual(save.frame.height, 44)120 shot("capture-xxxl")121 let file = element("capture-mode-file")122 let strip = app.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: 0, dy: element("capture-mode-text").frame.midY))123 for _ in 0..<12 where !(file.exists && file.isHittable) {124 strip.withOffset(CGVector(dx: 330, dy: 0)).press(forDuration: 0.05, thenDragTo: strip.withOffset(CGVector(dx: 40, dy: 0)))125 }126 XCTAssertTrue(file.exists && file.isHittable, "the last mode is reachable by scrolling the strip")127 }128129 func testAVoiceCaptureIsRecordedPausedAndSaved() {130 launch(route: "capture:audio", environment: ["SPNOTES_FAKE_MIC": "demo", "SPNOTES_CAPTURE_STAY": "1"])131 wait("voice-meter")132 XCTAssertTrue(element("voice-status").label.contains("Enregistrement en cours"), "recording starts with the audio mode")133 shot("capture-audio-recording")134 element("voice-pause").tap()135 XCTAssertTrue(element("voice-status").label.contains("En pause"))136 element("voice-pause").tap()137 element("voice-record").tap()138 wait("voice-ready")139 element("capture-save").tap()140 wait("capture-saved")141 element("capture-open-note").tap()142 XCTAssertTrue(app.navigationBars.firstMatch.waitForExistence(timeout: 10), "« Ouvrir la note » opens the capture")143 shot("capture-audio-note")144 }145146 func testTheMicrophoneRefusedIsExplainedWithAWayToSettings() {147 launch(route: "capture:audio", environment: ["SPNOTES_FAKE_MIC": "denied"])148 wait("voice-mic-denied")149 XCTAssertTrue(element("voice-open-settings").isHittable)150 XCTAssertFalse(element("capture-save").isEnabled)151 shot("voice-mic-denied")152 // not a dead end: writing instead works153 element("capture-mode-text").tap()154 XCTAssertTrue(wait("capture-title").isHittable)155 }156157 func testTheVoiceNoteScreenPlaysSeeksAndInsertsTheSummaryOnlyOnRequest() {158 launch(route: "voice")159 wait("voice-note-title")160 XCTAssertTrue(element("voice-segment-1").waitForExistence(timeout: 10))161 XCTAssertTrue(app.staticTexts["Transcription du serveur · openai:whisper-1"].exists, "the engine is labelled")162 shot("voice-note")163 // a tap on the second line plays from 1.1 s164 element("voice-segment-1").tap()165 let position = element("voice-position")166 XCTAssertTrue(position.waitForExistence(timeout: 5))167 let moved = NSPredicate(format: "label != %@", "0:00")168 XCTAssertEqual(XCTWaiter().wait(for: [XCTNSPredicateExpectation(predicate: moved, object: position)], timeout: 8), .completed, "the playhead moved")169 element("voice-speed").tap()170 XCTAssertEqual(element("voice-speed").value as? String, "1,25×")171172 let summary = element("voice-insert-summary")173 for _ in 0..<5 where !(summary.exists && summary.isHittable) { app.swipeUp(velocity: .slow) }174 XCTAssertTrue(summary.exists)175 XCTAssertTrue(summary.label.contains("Insérer le résumé"), "the AI summary is shown, not yet in the note")176 shot("voice-summary")177 summary.tap()178 XCTAssertTrue(element("voice-insert-summary").label.contains("Résumé inséré"))179 element("voice-create-tasks").tap()180 XCTAssertTrue(element("voice-create-tasks").label.contains("Tâches créées"))181 }182}183