Cotton code
58 lines · 3.4 KB · SwiftRaw
// The UX walk's findings for Notes, Todos, Journal and Goals (4 Oct 2026),// fixed at the definition level and held here: a todo's slip reads its// words, a todo's page offers the old menu's acts, the journal's "+" is// today's page, Goals has a "+" and words of its own, a note's page asks// for its title and its words, and the Rust copy of each definition carries// the same keys. Every record is invented.import CottonKitimport CottonValuesimport Foundationimport XCTest@testable import CottonUI@MainActorfinal class UxWalkFixesTests: XCTestCase {    private static var resources: Bundle? {        Bundle(url: SourceSweep.iosSources.appendingPathComponent("CottonUI/Resources"))    }    private func definition(_ id: String) throws -> TableDefinition {        let loaded = FixtureDefinitions.load(from: try XCTUnwrap(Self.resources))        return try XCTUnwrap(loaded.definitions.first { $0.id == id }, "no bundled \(id) definition")    }    private func record(_ id: String, _ values: [String: RecordValue]) -> TableRecord {        TableRecord(id: "example-\(id)", values: values)    }    // ── Todos ───────────────────────────────────────────────────────────    // ── Journal ─────────────────────────────────────────────────────────    // ── Goals ───────────────────────────────────────────────────────────    // ── Notes ───────────────────────────────────────────────────────────    // ── Alarms, News, Locations, Mood ───────────────────────────    /// RULE: A blank page starts with every column's `default` and then the create key's dated column — a new alarm is on before a word is typed, as the old alarm sheet made it; a table with no defaults starts as before.    func testABlankPageStartsWithEveryColumnsDefault() throws {        let bare = try TableDefinition.decode(Data("""            {"id":"example","name":"Example","plural":"Examples","builtin":false,             "columns":[{"key":"title","type":"text"},{"key":"on","type":"bool","default":true},{"key":"kind","type":"choice","choices":["a","b"],"default":"b"},                        {"key":"at","type":"date"},{"key":"blank","type":"text","default":""}],             "title":"title","slip":{"title":"title"},"tile":{"face":"slip-list"},"page":[{"heading":null,"columns":["title"]}],             "create":{"label":"New example","dated":"at"}}            """.utf8))        let preset = bare.createPreset(now: Date(timeIntervalSince1970: 1_790_000_000))        XCTAssertEqual(preset["on"], .bool(true))        XCTAssertEqual(preset["kind"], .text("b"))        XCTAssertNil(preset["blank"], "an empty default is no default")        XCTAssertNotNil(preset["at"], "the dated column is still today")    }    // ── The two copies ──────────────────────────────────────────────────}