Cotton code
38 lines · 2.0 KB · SwiftRaw
// The plus card left open on its acts once its record is made// (Rigby 11 walk, 8 Nov 2026: a new todo stood as a blank strip).import CottonValuesimport XCTest@testable import CottonUIfinal class DeckDraftCardTests: XCTestCase {    private func definition() throws -> TableDefinition {        let json = """        {"id":"todo","name":"Todo","plural":"Todos","builtin":false,         "columns":[{"key":"title","type":"text"}],         "title":"title","project":null,"order":null,         "slip":{"title":"title"},"tile":{"face":"slip-list"},"page":[],"commands":[],"tables":[],         "create":{"label":"New todo"},         "card":{"face":"todo.card","fields":[{"slot":"title","column":"title"}]}}        """        return try JSONDecoder().decode(TableDefinition.self, from: Data(json.utf8))    }    private func card(title: String) -> DeckCard {        DeckCard(face: "todo.card", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text(title)])    }    /// RULE: a new plus card wears the core's draft card; once its record is made it wears the record's own card, never the empty card said before its title.    func testAMadeDraftWearsItsRecordsCard() throws {        var draft = DeckDraft(id: "draft-1", definition: try definition(), record: TableRecord(id: "draft-1", values: [:]))        draft.said = card(title: "")        XCTAssertEqual(draft.card.fields["title"], .text(""), "new: the core's draft card")        var made = TableRecord(id: "todo-1", values: ["title": .text("Post the letter")])        made.values[DeckCard.key] = .object(["face": .text("todo.card"), "fields": .object(["title": .text("Post the letter")])])        draft.record = made        draft.isNew = false        XCTAssertEqual(draft.card.fields["title"], .text("Post the letter"), "made: the record's own card")        draft.record = TableRecord(id: "todo-1", values: ["title": .text("Post the letter")])        XCTAssertEqual(draft.card.fields["title"], .text(""), "made but read without its card: the last card said stands")    }}