Cotton code
142 lines · 6.3 KB · SwiftRaw
// CINEMAS' MOTION, filmed (MOTION.md "The numbers"), on Cinemas Dev's invented library with its invented TV: the app// opening and the featured title settling in; a row flung and snapping; a poster pressed in, grown into its page, the// page scrolled (parallax) and pulled past the top, then dragged back by hand; a poster held (the lift and the sheet);// a series' season switch; a tab change (only the chosen icon springs); Play on TV (the TV bar slides up), the bar// grown into the remote and back; the toast above the TV bar. Each moment is held long enough to be seen in the video// scripts/cinemas-walk.sh records around it (CINEMAS_TEST=CinemasMotionTests).import XCTestfinal class CinemasMotionTests: XCTestCase {    override func setUp() {        continueAfterFailure = false    }    @MainActor private func element(_ app: XCUIApplication, _ id: String) -> XCUIElement {        app.descendants(matching: .any)[id].firstMatch    }    @MainActor private func shot(_ app: XCUIApplication, _ name: String) {        let attachment = XCTAttachment(screenshot: app.screenshot())        attachment.name = name        attachment.lifetime = .keepAlways        add(attachment)    }    private func hold(_ seconds: Double) { Thread.sleep(forTimeInterval: seconds) }    @MainActor func testMotion() throws {        let app = XCUIApplication()        app.launchArguments += ["-cinemas-invent", "-cinemas-tv"]        app.launch()        // App opens (220 ms), the featured title settles in (700 ms backdrop, title and buttons rising 16 pt).        XCTAssertTrue(element(app, "cinemas-featured").waitForExistence(timeout: 30))        hold(2.5)        shot(app, "01 Settled")        // A row flung, then its soft snap to a poster's leading edge.        app.swipeUp(velocity: .slow)        hold(1)        let films = element(app, "cinemas-row-films")        XCTAssertTrue(films.waitForExistence(timeout: 5))        films.swipeLeft(velocity: .fast)        hold(1.5)        films.swipeRight(velocity: .fast)        hold(1.5)        shot(app, "02 Row snapped")        app.swipeDown(velocity: .slow)        hold(1)        // Press-in, then the poster grows into its page (spring 0.45 / 0.88; text fades in after it lands).        let poster = element(app, "cinemas-poster-carry_on-f-ferry")        XCTAssertTrue(poster.waitForExistence(timeout: 8))        poster.tap()        XCTAssertTrue(element(app, "cinemas-title-play").waitForExistence(timeout: 8))        hold(1.5)        shot(app, "03 Grown into its page")        // Parallax: the backdrop at half the scroll, fading and blurring. (Pulled down at the top, a grown page goes        // back into its poster: the system's zoom.)        app.swipeUp(velocity: .slow)        hold(1.2)        shot(app, "04 Scrolled: the backdrop fades")        app.swipeDown(velocity: .slow)        hold(1)        // Back by hand, slowly, following the finger, into the poster again.        let edge = app.coordinate(withNormalizedOffset: CGVector(dx: 0.01, dy: 0.5))        edge.press(forDuration: 0.1, thenDragTo: app.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5)), withVelocity: .slow, thenHoldForDuration: 0)        XCTAssertTrue(element(app, "cinemas-featured").waitForExistence(timeout: 8))        hold(1.5)        // Held: at 350 ms the poster lifts to 1.04 and the sheet rises (0.4 / 0.86); a group ticked says so in a toast.        let held = element(app, "cinemas-poster-carry_on-f-ferry")        held.press(forDuration: 0.9)        XCTAssertTrue(element(app, "cinemas-item-sheet").waitForExistence(timeout: 6))        hold(1.2)        shot(app, "05 The sheet risen")        let group = element(app, "cinemas-sheet-group-g-kids")        if group.waitForExistence(timeout: 3) { group.tap() }        hold(1)        element(app, "cinemas-sheet-done").tap()        hold(1.5)        // A tab change: the content cross-fades, only the chosen icon springs 0.9 → 1.        XCTAssertTrue(element(app, "cinemas-tab-search").waitForExistence(timeout: 5), "each tab is its own element")        element(app, "cinemas-tab-search").tap()        hold(1.2)        element(app, "cinemas-tab-home").tap()        hold(1.2)        // A series: the season switch slides the episodes 24 pt the season's way.        let series = element(app, "cinemas-poster-carry_on-s-lowmarsh")        XCTAssertTrue(series.waitForExistence(timeout: 6))        series.tap()        XCTAssertTrue(element(app, "cinemas-title-play").waitForExistence(timeout: 8))        hold(1)        app.swipeUp(velocity: .slow)        hold(1)        let seasons = element(app, "cinemas-season-switch")        XCTAssertTrue(seasons.waitForExistence(timeout: 5))        seasons.buttons.element(boundBy: 1).tap()        hold(1.2)        seasons.buttons.element(boundBy: 0).tap()        hold(1.2)        shot(app, "06 Season switched back")        app.swipeDown(velocity: .fast)        hold(1)        // Play on TV: the TV bar slides up above the bottom bar (300 ms); a tap grows it into the remote, and the        // remote goes back into it.        element(app, "cinemas-title-tv").tap()        let bar = element(app, "cinemas-tv-bar")        XCTAssertTrue(bar.waitForExistence(timeout: 6))        hold(2)        shot(app, "07 The TV bar")        bar.tap()        XCTAssertTrue(element(app, "cinemas-remote").waitForExistence(timeout: 6))        hold(2)        shot(app, "08 The remote")        element(app, "cinemas-remote-pause").tap()        hold(1)        element(app, "cinemas-remote-pause").tap()        hold(1)        element(app, "cinemas-remote-close").tap()        hold(1.5)        // A toast while the TV plays stands above the TV bar.        app.swipeUp(velocity: .slow)        hold(0.5)        let add = element(app, "cinemas-title-add")        if add.waitForExistence(timeout: 4) {            add.tap()            let tick = element(app, "cinemas-sheet-group-g-sundays")            if tick.waitForExistence(timeout: 4) { tick.tap() }            hold(0.8)            // Done when it is in reach; else the sheet goes down by a swipe, as a thumb sends it.            let done = element(app, "cinemas-sheet-done")            if done.exists && done.isHittable { done.tap() } else { app.swipeDown(velocity: .fast) }            hold(1)            shot(app, "09 The toast above the TV bar")        }        hold(2)    }}