// Recordings in Comms (CONTRACT.md "Recordings"), on Comms Dev's seed: Calls lists the recordings with the calls under// day headings, with Record and Bring in a recording at the top and the notes mark on a call; a recording opens its// page (title, when, where the words are made, who, the audio, summary, actions, language, transcript) and Back returns;// an action becomes a to-do and Save as note says so; the title is his to change; play moves the place and lights the// line being said; Record shows the time running and Stop opens the new recording's page. Default size and the largest.import XCTestfinalclassChatRecordingsTests: XCTestCase {overridefunc setUp() { continueAfterFailure = false } @MainActor privatefunc launched(_ extra: [String] = []) -> XCUIApplication {let app = XCUIApplication() app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-place", "calls"] + extra app.launch() XCTAssertTrue(app.descendants(matching: .any)["chat-calls"].waitForExistence(timeout: 60), "Calls opens")return app } @MainActor privatefunc id(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any).matching(identifier: id).firstMatch } @MainActor privatefuncopen(_ app: XCUIApplication, _ recording: String) {let row = id(app, "chat-recording-row-\(recording)") XCTAssertTrue(row.waitForExistence(timeout: 20), "\(recording) stands in Calls") row.tap() XCTAssertTrue(id(app, "recording-title").waitForExistence(timeout: 20), "its page opens on its title") }/// Scrolls the page until `element` is on screen. @MainActor privatefunc reach(_ app: XCUIApplication, _ element: XCUIElement, tries: Int = 12) {var left = trieswhile left > 0, !(element.exists && element.isHittable) { app.swipeUp(velocity: .slow) left -= 1 } }// RULE: Calls holds Record, Bring in a recording, the day headings, the recordings among the calls, and the notes// mark on the call they were taken on, which opens them. @MainActor func testCallsListRecordingsByDay() {let app = launched() XCTAssertTrue(id(app, "calls-record").waitForExistence(timeout: 20), "Record stands at the top of Calls") XCTAssertTrue(id(app, "calls-bring").exists, "Bring in a recording stands beside it") XCTAssertGreaterThanOrEqual(app.descendants(matching: .any).matching(identifier: "chat-calls-day").count, 3, "the calls stand under their days") XCTAssertTrue(id(app, "chat-recording-row-rec-garden").exists, "a room recording stands with the calls") XCTAssertTrue(id(app, "chat-recording-row-rec-memo").exists, "a recording brought in stands with the calls")let notes = id(app, "chat-call-notes-rec-call") XCTAssertTrue(notes.exists, "the notes taken on Ravi's call stand on its row") notes.tap() XCTAssertTrue(id(app, "recording-title").waitForExistence(timeout: 20), "the mark opens the notes") XCTAssertEqual(id(app, "recording-title").label, "Call with Ravi") id(app, "recording-back").tap() XCTAssertTrue(id(app, "calls-record").waitForExistence(timeout: 10), "Back returns to Calls") }// RULE: the page shows the title, where the words are made, who, the summary, the actions and the transcript;// Add to to-dos and Save as note answer in the core's words; the title can be changed. @MainActor func testThePageAndItsActs() {let app = launched()open(app, "rec-garden") XCTAssertEqual(id(app, "recording-where").label, "Made on this phone") XCTAssertTrue(id(app, "recording-speaker-sp-asha").exists, "who: Asha") XCTAssertTrue(id(app, "recording-choose-sp-2").exists, "an unnamed voice can be tied to one of his people") XCTAssertTrue(id(app, "recording-summary").exists, "the summary stands")let todo = id(app, "recording-todo-a2") reach(app, todo) todo.tap() XCTAssertTrue(app.staticTexts["Added to to-dos"].waitForExistence(timeout: 10), "an action becomes a to-do")let note = id(app, "recording-note") reach(app, note) note.tap() XCTAssertTrue(app.staticTexts["Saved to Words"].waitForExistence(timeout: 10), "Save as note says where it went") reach(app, id(app, "recording-line-l6")) XCTAssertTrue(id(app, "recording-line-l6").exists, "the transcript stands to its last line")// The title, changed. app.swipeDown(velocity: .fast) app.swipeDown(velocity: .fast) id(app, "recording-title").tap()let field = id(app, "recording-title-field") XCTAssertTrue(field.waitForExistence(timeout: 10))// The keyboard's own first-use card, when it stands, is closed.let carry = app.buttons["Continue"]if carry.waitForExistence(timeout: 2) { carry.tap() } field.coordinate(withNormalizedOffset: CGVector(dx: 0.98, dy: 0.5)).tap() field.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 30) + "Party plans\n")let renamed = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label == %@", "Party plans"), object: id(app, "recording-title")) XCTAssertEqual(XCTWaiter().wait(for: [renamed], timeout: 10), .completed, "the title is his to change") }// RULE: play moves the place and lights the line being said. @MainActor func testPlayLightsTheLine() {let app = launched()open(app, "rec-garden") id(app, "recording-play").tap()let first = id(app, "recording-line-l1")let lit = XCTNSPredicateExpectation(predicate: NSPredicate(format: "isSelected == true"), object: first) XCTAssertEqual(XCTWaiter().wait(for: [lit], timeout: 15), .completed, "the line being said is lit")let moved = XCTNSPredicateExpectation(predicate: NSPredicate(format: "value != %@", "0:00"), object: id(app, "recording-scrubber")) XCTAssertEqual(XCTWaiter().wait(for: [moved], timeout: 10), .completed, "the place moves") }// RULE (073c52456a, CONTRACT "Search, the ±15 s skip and export"): words typed in the transcript's search show the// lines holding them, the core's count above, the hits lit; a hit tapped plays from it and lights it; words not said// say so; cleared, the whole transcript is back. @MainActor func testSearchInsideTheTranscript() {let app = launched()open(app, "rec-garden")let field = id(app, "recording-search") reach(app, field) XCTAssertTrue(field.exists, "the transcript has a search") XCTAssertEqual(field.placeholderValue, "Search what was said") field.tap() field.typeText("CAKE")let count = id(app, "recording-search-line") XCTAssertTrue(count.waitForExistence(timeout: 10), "the core says how many") XCTAssertEqual(count.label, "2 lines") XCTAssertTrue(id(app, "recording-hit-l5").exists && id(app, "recording-hit-l6").exists, "the lines holding it") XCTAssertFalse(id(app, "recording-line-l1").exists, "and only those") field.typeText("\n")// A hit tapped plays from it (the seed's audio is a three-second clip, so a hit in its first line). field.tap() field.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 4) + "garden\n")let one = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label == %@", "1 line"), object: count) XCTAssertEqual(XCTWaiter().wait(for: [one], timeout: 10), .completed, "one line holds it: \(count.label)")let hit = id(app, "recording-hit-l1") XCTAssertTrue(hit.waitForExistence(timeout: 10), "the line holding it") reach(app, hit) hit.tap()let lit = XCTNSPredicateExpectation(predicate: NSPredicate(format: "isSelected == true"), object: hit) XCTAssertEqual(XCTWaiter().wait(for: [lit], timeout: 15), .completed, "a hit tapped plays from it and is lit") reach(app, field) field.tap() field.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 6) + "zebra")let none = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label == %@", "Not said in this recording"), object: count) XCTAssertEqual(XCTWaiter().wait(for: [none], timeout: 10), .completed, "words not said say so: \(count.label)") field.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 5)) XCTAssertTrue(id(app, "recording-line-l1").waitForExistence(timeout: 10), "cleared, the whole transcript is back") }// RULE: two round buttons beside play move the playhead 15 seconds back and ahead, their labels the core's words. @MainActor func testTheSkipMovesThePlayhead() {let app = launched()open(app, "rec-garden")let back = id(app, "recording-skip-back"), ahead = id(app, "recording-skip-ahead"), play = id(app, "recording-play") XCTAssertTrue(back.waitForExistence(timeout: 10) && ahead.exists, "the skip stands") XCTAssertEqual(back.label, "Back 15 seconds") XCTAssertEqual(ahead.label, "Ahead 15 seconds") XCTAssertEqual(back.frame.midY, play.frame.midY, accuracy: 4, "beside play")let scrubber = id(app, "recording-scrubber") back.tap() XCTAssertEqual(scrubber.value as? String, "0:00", "back from the start stays at the start") ahead.tap()let moved = XCTNSPredicateExpectation(predicate: NSPredicate(format: "value != %@", "0:00"), object: scrubber) XCTAssertEqual(XCTWaiter().wait(for: [moved], timeout: 10), .completed, "ahead moves the place") }// RULE: Export offers the core's three choices; Text hands the transcript's file to the share sheet; the audio of a// recording with none is refused in the core's words. @MainActor func testExportToTheShareSheet() {let app = launched()open(app, "rec-garden")let export = id(app, "recording-export") reach(app, export) XCTAssertTrue(export.exists, "Export stands among the page's buttons") export.tap()for format in ["text", "srt", "audio"] { XCTAssertTrue(app.buttons.matching(identifier: "look-ask-recording-export-\(format)").firstMatch.waitForExistence(timeout: 5), "\(format) is offered") } XCTAssertEqual(app.buttons.matching(identifier: "look-ask-recording-export-srt").firstMatch.label, "Subtitles") app.buttons.matching(identifier: "look-ask-recording-export-text").firstMatch.tap()let sheet = app.otherElements["ActivityListView"] XCTAssertTrue(sheet.waitForExistence(timeout: 15), "the share sheet rose") XCTAssertTrue(app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS %@", "The garden party")).firstMatch .waitForExistence(timeout: 10), "holding the recording's file, named by its title") app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.12)).tap()if !sheet.waitForNonExistence(timeout: 3), sheet.exists { sheet.swipeDown(velocity: .fast) } XCTAssertTrue(sheet.waitForNonExistence(timeout: 10), "the share sheet closed") }// RULE: Record shows the time running and a large Stop; Stop files it and opens its page. @MainActor func testRecordThenStopOpensThePage() {// The microphone already allowed: Record records at once (its reason card is ChatReviewerPassTests').let app = launched(["-chat-warm-voice", "YES", "-chat-warm-mic", "authorized"]) id(app, "calls-record").tap()// iOS asks for the microphone the first time: allowed.let allow = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.buttons.element(boundBy: 1)if allow.waitForExistence(timeout: 5) { allow.tap() }let stop = id(app, "recording-stop") XCTAssertTrue(stop.waitForExistence(timeout: 20), "the recording screen stands with Stop")let time = id(app, "recording-time")let running = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label != %@", "0:00"), object: time) XCTAssertEqual(XCTWaiter().wait(for: [running], timeout: 15), .completed, "the time runs") stop.tap() XCTAssertTrue(id(app, "recording-title").waitForExistence(timeout: 30), "Stop opens the recording's page") }// RULE: at the largest text the page's acts and its last line are reached. @MainActor func testThePageAtTheLargestText() {let app = launched(["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXXL"])open(app, "rec-garden")let note = id(app, "recording-note") reach(app, note, tries: 20) XCTAssertTrue(note.isHittable, "Save as note is reached")let last = id(app, "recording-line-l6") reach(app, last, tries: 30) XCTAssertTrue(last.isHittable, "the transcript's last line is reached") }// RULE: while someone takes notes, the call screen says who at its top, and the folded bar keeps the mark. @MainActor func testTheNotesMarkStandsOnTheCall() {let app = XCUIApplication() app.launchArguments += ["-chat-warm-seed", "YES", "-chat-warm-call", "notes"] app.launch()let mark = id(app, "chat-call-notes") XCTAssertTrue(mark.waitForExistence(timeout: 60), "the notes mark stands on the call screen") XCTAssertTrue(mark.label.contains("taking notes"), "it says who is taking notes: \(mark.label)") app.terminate() app.launchArguments = ["-chat-warm-seed", "YES", "-chat-warm-call", "notes-bar"] app.launch()let bar = id(app, "chat-call-bar") XCTAssertTrue(bar.waitForExistence(timeout: 60), "the call folded to its bar") XCTAssertTrue(bar.label.contains("taking notes"), "the folded bar keeps the mark: \(bar.label)") }// RULE (owner, Comms 28 fixes 2): a recording's date is his to change: its date line opens a date-and-time picker// under the core's question, with Save and Cancel; Save sends the act and says the core's line. @MainActor func testTheDateLineChangesTheRecordingsDate() {let app = launched()open(app, "rec-garden")let date = id(app, "recording-date") XCTAssertTrue(date.waitForExistence(timeout: 10), "the date line can be tapped") date.tap() XCTAssertTrue(app.staticTexts["When was this recorded?"].waitForExistence(timeout: 5), "the picker, under the core's question") XCTAssertTrue(id(app, "recording-date-picker").exists, "a date and a time to choose") XCTAssertTrue(app.buttons["look-ask-recording-date-cancel"].exists, "Cancel")let save = app.buttons["look-ask-recording-date-save"] XCTAssertTrue(save.exists, "Save")let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot()) shot.name = "recording-date-picker" shot.lifetime = .keepAlways add(shot)if !save.isHittable { app.swipeUp(velocity: .slow) } save.tap() XCTAssertTrue(app.staticTexts["Date changed"].waitForExistence(timeout: 5), "Save says the core's line") XCTAssertTrue(id(app, "recording-title").exists, "still on the page") }}