Cotton code
65 lines · 3.5 KB · SwiftRaw
// Nothing in Story is out of reach at the end of a long list: the sixty-// fourth scene of the invented script can be scrolled to, stands clear of// the "+", and opens, upright, turned sideways, and at the largest text.import XCTestfinal class StoryReachTests: StoryUITestCase {    @MainActor private func reachesTheLastScene(_ app: XCUIApplication, _ how: String) throws {        _ = StoryUI.home(app)        try skipUnderTheShellsCard(app)        let last = StoryUI.row(app, "End of the Line")        let reached = StoryUI.scrollTo(last, in: app, tries: 60)        if !reached { try skipUnderTheShellsCard(app, wait: 0) }        XCTAssertTrue(reached, "the last scene can be scrolled to (\(how))")        // Once more, so the list stands at its very end.        StoryUI.drag(app, from: CGVector(dx: 0.5, dy: 0.7), by: CGVector(dx: 0, dy: -400))        XCTAssertTrue(last.isHittable, "the last scene stands on screen at the list's end (\(how))")        let plus = StoryUI.button(app, "New scene")        if plus.exists {            XCTAssertFalse(plus.frame.intersects(last.frame.insetBy(dx: 0, dy: 6)), "the + stands clear of the last scene (\(how))")        }        XCTAssertTrue(StoryUI.inside(last, app, top: 0, bottom: 10), "the last scene stands above the screen's foot (\(how))")        last.tap()        let bar = app.buttons.matching(NSPredicate(format: "label CONTAINS[c] %@", "End of the Line")).firstMatch        XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "ink-line").firstMatch.waitForExistence(timeout: 10), "the last scene opened (\(how))")        XCTAssertTrue(bar.exists)    }    // RULE: upright, the last of sixty-four scenes is reachable and opens.    @MainActor func testTheLastSceneIsReachableUpright() throws {        XCUIDevice.shared.orientation = .portrait        try reachesTheLastScene(StoryUI.launch(), "upright")    }    // RULE: turned sideways, the last scene is reachable and opens.    @MainActor func testTheLastSceneIsReachableSideways() throws {        XCUIDevice.shared.orientation = .landscapeLeft        try reachesTheLastScene(StoryUI.launch(), "sideways")    }    // RULE: at the largest text, the last scene is reachable and opens.    @MainActor func testTheLastSceneIsReachableAtTheLargestText() throws {        XCUIDevice.shared.orientation = .portrait        try reachesTheLastScene(StoryUI.launch(StoryUI.largestText), "largest text")    }    // RULE: sideways, a scene's writing bar stands whole on screen and Where and when's Done can be reached.    @MainActor func testASceneSideways() throws {        XCUIDevice.shared.orientation = .landscapeLeft        let app = StoryUI.launch()        try skipUnderTheShellsCard(app)        let first = StoryUI.home(app)        first.tap()        let send = StoryUI.button(app, "Send")        XCTAssertTrue(send.waitForExistence(timeout: 10), "the scene opened sideways")        XCTAssertTrue(StoryUI.inside(send, app, top: 0, bottom: 0), "the writing bar's Send stands on screen sideways")        app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "1 · Waiting Room")).firstMatch.tap()        let done = StoryUI.button(app, "Done")        XCTAssertTrue(done.waitForExistence(timeout: 5), "Where and when opened sideways")        for _ in 0..<6 where !done.isHittable {            StoryUI.drag(app.staticTexts["Night"].exists ? app.staticTexts["Night"] : app.windows.firstMatch, at: CGVector(dx: 0.5, dy: 0.5), by: CGVector(dx: 0, dy: -120))        }        XCTAssertTrue(done.isHittable, "Where and when's Done can be reached sideways")    }}