Cotton code
152 lines · 7.1 KB · SwiftRaw
// THE STORE REVIEWER'S FIRST FIVE MINUTES on iPhone (coordinator, 24 Nov 2026; LAUNCH.md; android-finish walked// Android in 89981b413d and ff8d3a8a78). Run by hand on a fresh install of the app the scheme builds (Words, Days or// Story): what a reviewer meets first, Settings, Help and feedback with Privacy policy and Help and contact, and Sign// in up to the code step with an invented number that never reaches a phone. A screenshot and the screen's// accessibility tree at each step (store-NN-*), for a person to read; it fails only where a step cannot be taken.import XCTestfinal class StoreFirstFiveTests: XCTestCase {    private var step = 0    override func setUp() {        continueAfterFailure = true        XCUIDevice.shared.orientation = .portrait    }    @MainActor private func keep(_ app: XCUIApplication, _ name: String) {        step += 1        let stem = String(format: "store-%02d-%@", step, name)        let shot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())        shot.name = stem        shot.lifetime = .keepAlways        add(shot)        let tree = XCTAttachment(string: app.debugDescription)        tree.name = stem + "-tree"        tree.lifetime = .keepAlways        add(tree)    }    @MainActor private func any(_ app: XCUIApplication, _ identifiers: [String]) -> XCUIElement? {        for identifier in identifiers {            let found = app.descendants(matching: .any).matching(identifier: identifier).firstMatch            if found.exists { return found }        }        return nil    }    @MainActor private func labelled(_ app: XCUIApplication, _ words: [String]) -> XCUIElement? {        for word in words {            let found = app.buttons.matching(NSPredicate(format: "label ==[c] %@", word)).firstMatch            if found.exists && found.isHittable { return found }        }        return nil    }    @MainActor func testFirstFiveMinutes() {        let app = XCUIApplication()        app.launch()        Thread.sleep(forTimeInterval: 6)        keep(app, "first")        // Whatever stands first and asks to be passed (a welcome, a notice), passed the way a reviewer would.        for _ in 0..<3 {            guard let next = labelled(app, ["Continue", "Get started", "Start", "Not now", "OK", "Skip"]) else { break }            next.tap()            Thread.sleep(forTimeInterval: 2)            keep(app, "passed")        }        app.swipeUp()        Thread.sleep(forTimeInterval: 1)        keep(app, "scrolled")        app.swipeDown()        // Settings, the way a reviewer finds it: the top corner's More, then Settings in what it opens.        var settings = labelled(app, ["Settings", "More: settings"])        if settings == nil, let more = any(app, ["notes-more", "ellipsis"]) ?? labelled(app, ["More"]) {            more.tap()            Thread.sleep(forTimeInterval: 1.5)            keep(app, "more")            settings = labelled(app, ["Settings"])                ?? app.descendants(matching: .any).matching(NSPredicate(format: "label ==[c] 'Settings'")).firstMatch        }        if let found = settings, !found.exists { settings = nil }        guard let settings else {            keep(app, "no-settings")            XCTFail("no way to Settings was found on the first screen")            return        }        settings.tap()        Thread.sleep(forTimeInterval: 2)        keep(app, "settings")        // Help and feedback, its two links.        if let help = any(app, ["settings-row-help"]) ?? labelled(app, ["Help and feedback"]) {            help.tap()            Thread.sleep(forTimeInterval: 2)            app.swipeUp()            keep(app, "help")            let privacy = app.descendants(matching: .any).matching(identifier: "settings-link-privacy").firstMatch            XCTAssertTrue(privacy.exists, "Privacy policy on Help and feedback")            XCTAssertTrue(app.descendants(matching: .any).matching(identifier: "settings-link-support").firstMatch.exists, "Help and contact")            if privacy.exists && privacy.isHittable {                privacy.tap()                let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")                if safari.wait(for: .runningForeground, timeout: 20) {                    Thread.sleep(forTimeInterval: 4)                    keep(app, "privacy-in-safari")                }                app.activate()                Thread.sleep(forTimeInterval: 2)            }            if let back = any(app, ["days-settings-back", "story-settings-back", "settings-back"]) { back.tap() }            Thread.sleep(forTimeInterval: 1)        } else {            keep(app, "no-help")            XCTFail("no Help and feedback row in Settings")        }        // Days: Google calendars, signed out, says why and offers Sign in right there.        let calendars = app.descendants(matching: .any).matching(identifier: "settings-row-calendars").firstMatch        if calendars.exists {            SettingsPartsUI.reach(app, calendars)            calendars.tap()            Thread.sleep(forTimeInterval: 2)            keep(app, "days-google")            let signIn = app.buttons["days-google-sign-in"]            if app.descendants(matching: .any).matching(identifier: "days-google-unavailable").firstMatch.label.localizedCaseInsensitiveContains("sign in") {                XCTAssertTrue(signIn.exists, "signed out, Google calendars offers Sign in")            }            if let back = any(app, ["days-settings-back"]) { back.tap() }            Thread.sleep(forTimeInterval: 1)        }        // Sign in, up to the code step, with an invented number (+1 555 01xx never reaches a phone).        let card = app.descendants(matching: .any).matching(identifier: "settings-card").firstMatch        if card.exists {            if !card.isHittable { app.swipeDown() }            card.tap()            let phone = app.descendants(matching: .any).matching(identifier: "home-customer-phone").firstMatch            if phone.waitForExistence(timeout: 15) {                keep(app, "sign-in-number")                phone.tap()                phone.typeText("+15550100199")                if let send = any(app, ["home-customer-send"]) {                    let circle = send.buttons.firstMatch.exists ? send.buttons.firstMatch : send                    circle.tap()                }                let sentTo = app.descendants(matching: .any).matching(identifier: "home-customer-sent-to").firstMatch                if sentTo.waitForExistence(timeout: 20) {                    keep(app, "sign-in-code")                    // The number shown back masked: its country code and last two digits (NEXT-SIGNIN, 28 Nov 2026).                    XCTAssertTrue(sentTo.label.contains("+1 ••••••••99"), sentTo.label)                    XCTAssertFalse(sentTo.label.contains("5550100199"), sentTo.label)                    XCTAssertTrue(app.buttons["home-customer-send-again"].exists, "Send the code again")                } else {                    keep(app, "sign-in-after-send")                }            } else {                keep(app, "signed-in-profile")            }        }    }}