Cotton code
51 lines · 3.0 KB · SwiftRaw
// A hold in Story opens what it should: a still hold on a scene row its// acts, a still hold on a line its acts; a hold then drag on a scene row// moves the scene, and the others part for it. The drag puts the order// back, so the invented script stands as it came in.import XCTestfinal class StoryHoldTests: StoryUITestCase {    // RULE: a still hold on a scene row opens its acts; on a scene's line, the line's acts.    @MainActor func testAStillHoldOpensTheActs() {        let app = StoryUI.launch()        let first = StoryUI.home(app)        first.press(forDuration: 0.8)        XCTAssertTrue(app.buttons["Duplicate"].waitForExistence(timeout: 5), "a hold on a scene row opened its acts")        XCTAssertTrue(app.buttons["New scene after this"].exists)        app.windows.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.4)).tap()        XCTAssertTrue(app.buttons["Duplicate"].waitForNonExistence(timeout: 3))        first.tap()        let lines = app.descendants(matching: .any).matching(identifier: "ink-line")        XCTAssertTrue(lines.firstMatch.waitForExistence(timeout: 10), "the scene opened")        // The scene's last line, a speech.        guard let line = lines.allElementsBoundByIndex.last(where: { $0.isHittable }) else { return XCTFail("a line can be touched") }        line.press(forDuration: 0.8)        XCTAssertTrue(app.buttons["Write after this"].waitForExistence(timeout: 5), "a hold on a line opened its acts")        XCTAssertTrue(app.buttons["Change speaker"].exists)    }    // RULE: hold a scene row and drag it: it moves to where it is let go; dragged back, the order is as before.    @MainActor func testAHoldAndDragMovesAScene() {        let app = StoryUI.launch()        let first = StoryUI.home(app)        let second = StoryUI.row(app, "Platform One")        XCTAssertTrue(second.waitForExistence(timeout: 5))        XCTAssertLessThan(first.frame.minY, second.frame.minY, "Waiting Room stands first")        // Platform One up above Waiting Room.        let from = second.coordinate(withNormalizedOffset: CGVector(dx: 0.4, dy: 0.5))        let to = first.coordinate(withNormalizedOffset: CGVector(dx: 0.4, dy: 0.1))        from.press(forDuration: 0.7, thenDragTo: to, withVelocity: .slow, thenHoldForDuration: 0.4)        let moved = NSPredicate { _, _ in second.frame.minY < first.frame.minY }        expectation(for: moved, evaluatedWith: nil)        waitForExpectations(timeout: 5)        XCTAssertFalse(app.buttons["Duplicate"].exists, "a hold that moved opened no acts")        // And back down below it.        let back = second.coordinate(withNormalizedOffset: CGVector(dx: 0.4, dy: 0.5))        let below = first.coordinate(withNormalizedOffset: CGVector(dx: 0.4, dy: 0.95))        back.press(forDuration: 0.7, thenDragTo: below, withVelocity: .slow, thenHoldForDuration: 0.4)        let restored = NSPredicate { _, _ in first.frame.minY < second.frame.minY }        expectation(for: restored, evaluatedWith: nil)        waitForExpectations(timeout: 5)    }}