// Every panel in Story opens from what names it and closes by a pull down// on it and by its close mark (or, for a short list of acts with no mark, a// tap above it); a sideways swipe on a panel over a scene leaves the scene// where it is (Android d26f0954e2). Invented script only.import XCTestfinalclassStoryPanelTests: StoryUITestCase {/// Pulls down from `element` (a panel's title or first row) by most of the screen. @MainActor privatefunc pullDown(_ element: XCUIElement) {StoryUI.drag(element, at: CGVector(dx: 0.5, dy: 0.5), by: CGVector(dx: 0, dy: 320), hold: 0.05) }/// Opens a panel by `open`, sees `mark`, and closes it by a pull down from it; then again by `close`. @MainActor privatefunc opensAndCloses(_ app: XCUIApplication, _ name: String, mark: XCUIElement,open: () -> Void, close: (() -> Void)?) throws {// The last panel's closing slide is done. _ = app.buttons["__settle__"].waitForExistence(timeout: 0.5)try skipUnderTheShellsCard(app, wait: 0)open() XCTAssertTrue(mark.waitForExistence(timeout: 5), "\(name) opened") XCTAssertTrue(StoryUI.inside(mark, app), "\(name) stands inside the safe area") pullDown(mark) XCTAssertTrue(mark.waitForNonExistence(timeout: 3), "a pull down closed \(name)")guardlet close else { return } _ = app.buttons["__settle__"].waitForExistence(timeout: 0.5)open() XCTAssertTrue(mark.waitForExistence(timeout: 5), "\(name) opened again") close() XCTAssertTrue(mark.waitForNonExistence(timeout: 3), "the close mark closed \(name)") }// RULE: the home's panels (Your scripts, ⋯, All views, a scene's ⋯, New script) open and close by a pull or their close. @MainActor func testTheHomesPanelsOpenAndClose() throws {let app = StoryUI.launch()let first = StoryUI.home(app)try skipUnderTheShellsCard(app)let close = StoryUI.button(app, "Close")try opensAndCloses(app, "Your scripts", mark: app.staticTexts["Your scripts"],open: { StoryUI.button(app, "The Long Platform").tap() }, close: { close.tap() })// ⋯ and a scene's ⋯ are short lists with no mark: a tap above closes them.let more = StoryUI.button(app, "More")let above = { app.windows.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.4)).tap() }try opensAndCloses(app, "the home's ⋯", mark: app.buttons["About this script"], open: { more.tap() }, close: above)try opensAndCloses(app, "All views", mark: app.staticTexts["The story"],open: { StoryUI.button(app, "All views").tap() }, close: { close.tap() })let ofScene = { first.coordinate(withNormalizedOffset: CGVector(dx: 0.97, dy: 0.3)).tap() }try opensAndCloses(app, "a scene's ⋯", mark: app.buttons["Duplicate"], open: ofScene, close: above)try opensAndCloses(app, "New script", mark: app.staticTexts["Give it a title. Everything else can come later."],open: {StoryUI.button(app, "The Long Platform").tap()StoryUI.button(app, "New script").tap() }, close: { close.tap() }) }// RULE: a row with its detail beside it (All views' Read, About's Drafts) stands one line tall, its detail shown. @MainActor func testARowWithADetailBesideItStandsOneLineTall() throws {let app = StoryUI.launch(["-story-ink-open", "views"])let read = app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Read,")).firstMatch XCTAssertTrue(read.waitForExistence(timeout: 60), "All views opened with Read and its count") XCTAssertLessThan(read.frame.height, 90, "All views' Read row is one line, its count beside it")let count = read.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "scenes")).firstMatchif count.exists { XCTAssertGreaterThan(count.frame.width, 60, "the count beside Read can be read") }StoryUI.button(app, "Close").tap() _ = app.buttons["__settle__"].waitForExistence(timeout: 0.5)try skipUnderTheShellsCard(app)StoryUI.button(app, "More").tap() app.buttons["About this script"].tap()let drafts = app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Drafts,")).firstMatch XCTAssertTrue(drafts.waitForExistence(timeout: 5), "About shows Drafts with the latest one beside it") XCTAssertLessThan(drafts.frame.height, 120, "About's Drafts row stands short, the latest draft beside it") XCTAssertTrue(StoryUI.button(app, "Delete this script").isHittable, "Delete this script stands on screen") }// RULE: a scene's panels (Where and when, who speaks, a line's acts, a direction) open and close by a pull or their close. @MainActor func testASceneSPanelsOpenAndClose() throws {let app = StoryUI.launch()try skipUnderTheShellsCard(app)let row = StoryUI.row(app, "Waiting Room") XCTAssertTrue(row.waitForExistence(timeout: 60)) row.tap()let bar = app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "1 · Waiting Room")).firstMatch XCTAssertTrue(bar.waitForExistence(timeout: 10), "the scene opened")let close = StoryUI.button(app, "Close")try opensAndCloses(app, "Where and when", mark: app.staticTexts["Where and when"], open: { bar.tap() }, close: { close.tap() })let chip = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", "Next line")).firstMatchtry opensAndCloses(app, "who speaks", mark: app.scrollViews["ink-speaker-rows"], open: { chip.tap() }, close: { app.buttons["ink-speaker-close"].tap() })// The scene's last line, a speech.let line = app.descendants(matching: .any).matching(identifier: "ink-line").allElementsBoundByIndex.last { $0.isHittable } ?? app.descendants(matching: .any).matching(identifier: "ink-line").firstMatchlet above = { app.windows.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.4)).tap() }try opensAndCloses(app, "a line's acts", mark: app.buttons["Write after this"], open: { line.press(forDuration: 0.8) }, close: above)try opensAndCloses(app, "a direction", mark: app.staticTexts["A direction"], open: { line.press(forDuration: 0.8) app.buttons["Add a direction"].tap() }, close: { close.tap() }) }// RULE: a sideways swipe on a panel over a scene keeps the scene and the panel. @MainActor func testASidewaysSwipeOnAPanelKeepsTheScene() throws {let app = StoryUI.launch()try skipUnderTheShellsCard(app)let row = StoryUI.row(app, "Platform One") XCTAssertTrue(row.waitForExistence(timeout: 60)) row.tap()let bar = app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "2 · Platform One")).firstMatch XCTAssertTrue(bar.waitForExistence(timeout: 10), "scene 2 opened")let lines = app.descendants(matching: .any).matching(identifier: "ink-line")let line = lines.allElementsBoundByIndex.last { $0.isHittable } XCTAssertNotNil(line) line?.press(forDuration: 0.8)let acts = app.buttons["Write after this"] XCTAssertTrue(acts.waitForExistence(timeout: 5), "the line's acts opened")StoryUI.drag(acts, at: CGVector(dx: 0.8, dy: 0.5), by: CGVector(dx: -250, dy: 0)) XCTAssertTrue(acts.exists, "the acts stayed open under a sideways swipe") XCTAssertTrue(bar.exists, "the scene under the acts stayed scene 2") app.windows.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.4)).tap() XCTAssertTrue(acts.waitForNonExistence(timeout: 3))// Outside a panel, a sideways swipe still turns the scene.StoryUI.drag(app, from: CGVector(dx: 0.8, dy: 0.45), by: CGVector(dx: -250, dy: 0))let next = app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "3 · Ticket Hall")).firstMatch XCTAssertTrue(next.waitForExistence(timeout: 5), "a sideways swipe on the scene turned to scene 3") }}