Cotton code
48 lines · 2.3 KB · SwiftRaw
// Home's board under a screen that covers it (coordinator 08:57Z, walk6 sev 2):// a cold launch into cottondev://money read Home's 26 tiles (6 s) beside// Money's own read on the one reader, so Money's accounts landed at ~9–14 s.import CottonKitimport XCTest@testable import CottonUIfinal class BoardCoveredTests: XCTestCase {    /// RULE: Home's board reads only while no screen covers it — a deep link straight into a list reads that list alone, and the board reads when it shows.    func testTheBoardReadsNothingWhileAScreenCoversIt() throws {        // The phone: anything pushed covers the board.        XCTAssertFalse(BoardCover.covered([], columns: false))        XCTAssertTrue(BoardCover.covered([.money], columns: false))        XCTAssertTrue(BoardCover.covered([.emailId(id: "t")], columns: false))        // The Mac: the board is the list column's root, so only a list covers        // it; a page opens beside it.        XCTAssertFalse(BoardCover.covered([], columns: true))        XCTAssertTrue(BoardCover.covered([.money], columns: true))        XCTAssertEqual(BoardCover.covered([.emailId(id: "t")], columns: true), Route.emailId(id: "t").tier == .list)        // A link still arriving covers it: the read once began ~80 ms before        // the deep link's push.        XCTAssertTrue(BoardCover.covered([], columns: false, arriving: true))        XCTAssertTrue(BoardCover.covered([], columns: true, arriving: true))    }    /// RULE: A link is arriving from the moment it lands until its route is delivered, held or being placed — and not after.    @MainActor    func testALinkIsArrivingUntilItsRouteIsDelivered() async {        let taps = PendingTaps()        XCTAssertFalse(taps.arriving)        taps.arrive(Route.money)        XCTAssertTrue(taps.arriving, "a held link")        let delivered = expectation(description: "delivered")        let release = AsyncStream<Void>.makeStream()        taps.open(placing: { link in            for await _ in release.stream { break }            return link.route        }) { _ in delivered.fulfill() }        XCTAssertTrue(taps.arriving, "a link being placed")        release.continuation.yield()        await fulfillment(of: [delivered], timeout: 2)        await Task.yield()        XCTAssertFalse(taps.arriving)    }}