Cotton code
49 lines · 3.0 KB · SwiftRaw
import CottonKitimport CottonValuesimport Foundationimport XCTest@testable import CottonUI/// A list split into days — Calendar, Meetings, Calls — is read from the day/// it opens on; how its days are split is the core's (`shell_list_tests.rs`).@MainActorfinal class PlannedCalendarTests: XCTestCase {    private static let calendar = TableDefinition(        id: "event", name: "Event", plural: "Calendar",        columns: [ColumnDefinition(key: "title", type: .text), ColumnDefinition(key: "starts_at", type: .date)],        title: "title", date: "starts_at", slip: SlipLayout(title: "title"), tile: TileLayout(face: .slipList),        page: [PageSection(heading: nil, columns: ["title", "starts_at"])], dayGrouping: "starts_at")    private static func event(_ id: String, _ day: String) -> TableRecord {        TableRecord(id: id, values: ["title": .text(id), "starts_at": .text(day)])    }    /// Walker 298: holding a thought's "captured · Yesterday" opened the    /// Calendar on Today; the route named the day and the screen dropped it.    ///    /// RULE: a date slip opens its own day — the route carries the slip's date, the Calendar's list is read from that day (`PlanView.today`), and a list a route names no day for reads from this device's today — because a date a person taps is the day they mean.    func testADateSlipsRouteOpensTheCalendarOnItsOwnDay() async throws {        let dated = TableRecord(id: "t", values: ["captured_at": .text("2026-10-17T21:40:00+05:30")])        let day = try XCTUnwrap(TableDefinition.dayKey(dated["captured_at"], calendar: .current))        XCTAssertEqual(Route.calendar(date: day).path, "/calendar?date=\(day)", "the route carries the slip's date")        XCTAssertEqual(RouteScreen.day(day), day)        XCTAssertNil(RouteScreen.day(nil))        XCTAssertNil(RouteScreen.day("tomorrow"))        let store = FixtureRecords(definitions: [Self.calendar], records: ["event": [Self.event("e", "2026-10-17T09:00:00+05:30")]])        let core = ListCoreFake()        await RecordListModel(definition: Self.calendar, store: store, core: core, opensOn: day, seeds: ListSeeds())            .reload(project: nil, query: "")        XCTAssertEqual(core.asked.first?["today"] as? String, day, "the list is read from the slip's day")        let plain = ListCoreFake()        await RecordListModel(definition: Self.calendar, store: store, core: plain, seeds: ListSeeds()).reload(project: nil, query: "")        XCTAssertNil(plain.asked.first?["today"] as? String, "a list named no day reads from this device's today")        let screen = SourceSweep.withoutComments(try SourceSweep.mustRead(            "apps/cotton/Sources/CottonUI/Boot/RouteScreen.swift", ownedBy: "phonefixes")).filter { !$0.isWhitespace }        XCTAssertTrue(screen.contains("case.calendar(letdate,_),.calendarMonth(letdate):returnany(TableListRoute(table:\"event\",opensOn:RouteScreen.day(date))"),                      "the Calendar's route hands its date to the list")    }}