Cotton code
53 lines · 2.6 KB · SwiftRaw
// Cotton Sites Dev on a simulator, with invented sites only (`-sites-fresh`, `-sites-seed`; the two at the invented// club are `scripts/invented-site.py` on this Mac, port 8765). Nothing here is anyone's real site.import XCTestfinal class SitesFirstRunTests: XCTestCase {    /// A fresh list says what makes the app different, with Add your first site and Quick visit.    @MainActor func testAFreshListSaysEachSiteKeepsItsOwnSignIn() {        let app = XCUIApplication()        app.launchArguments += ["-sites-fresh"]        app.launch()        XCTAssertTrue(app.staticTexts["sites-first-line"].waitForExistence(timeout: 60))        XCTAssertTrue(app.buttons["sites-first-add"].exists)        XCTAssertTrue(app.buttons["sites-first-quick"].exists)        XCTAssertTrue(app.buttons["sites-search"].exists)    }    /// Adding a site puts it in the list, in its own words.    @MainActor func testAddingASiteListsIt() {        let app = XCUIApplication()        app.launchArguments += ["-sites-fresh"]        app.launch()        XCTAssertTrue(app.staticTexts["sites-first-line"].waitForExistence(timeout: 60))        let address = app.textFields["sites-add-address"]        for _ in 0..<3 where !address.exists {            app.buttons["sites-first-add"].tap()            _ = address.waitForExistence(timeout: 5)        }        XCTAssertTrue(address.exists)        address.typeText("club.example")        let save = app.buttons["sites-add-save"]        XCTAssertTrue(save.waitForExistence(timeout: 5))        XCTAssertTrue(app.staticTexts["Add Club"].waitForExistence(timeout: 5) || save.label.contains("Club"))        save.tap()        XCTAssertTrue(app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH 'sites-row-'")).firstMatch.waitForExistence(timeout: 10))    }    /// A link handed over by Post opens the chooser, the one-time code masked, and nothing loads until he picks.    @MainActor func testALinkFromPostOpensTheChooserMasked() {        let app = XCUIApplication()        app.launchArguments += ["-sites-fresh", "-sites-seed", "-sites-link", "https://club.example/login?token=Zx81kQpLm2", "-sites-from", "post"]        app.launch()        let title = app.staticTexts["sites-choose-title"]        XCTAssertTrue(title.waitForExistence(timeout: 60))        XCTAssertEqual(title.label, "Open a link from Post")        let link = app.staticTexts["sites-choose-link"]        XCTAssertTrue(link.exists)        XCTAssertFalse(link.label.contains("81kQpLm2"), "the one-time code is masked")        XCTAssertTrue(app.staticTexts["sites-choose-once"].exists)        XCTAssertFalse(app.otherElements["sites-page"].exists, "nothing loaded")    }}