Cotton code
66 lines · 3.7 KB · SwiftRaw
// No bottom sheets in the deck's editing (door row 7; owner, 23 Oct: sheets// are out of the design). Pick a date and Pick a time open as rows on the fan// — every day of the coming weeks, every half hour, as the core answers them// (`shell_input_tests.rs`) — in the sheet's place.import CottonKitimport XCTest@testable import CottonUI@MainActorfinal class DeckNoSheetsTests: XCTestCase {    private let target = DeckEditTarget(table: "todo", record: "t1", date: "due")    /// The core's Pick a date: every day from today (`shell.opened {step: when, all: true}`),    /// four of them; the row of days the corner opens on asks without `all` and gets two.    private func core() -> InputCore {        InputCore { method, request in            guard method == "shell.opened", request["step"]?.string == "when" else {                return .failure(CottonCallError(code: "missing", message: "Not here"))            }            let days = (0..<(request["all"] == .bool(true) ? 4 : 2)).map { #"{"value":"pick-2026-11-0\#($0 + 5)","words":"Day \#($0)","kind":"day","day":"2026-11-0\#($0 + 5)"}"# }            return .success(InputCore.json(#"{"step":{"kind":"when","rows":[\#(days.joined(separator: ","))]}}"#))        }    }    /// RULE: Pick a date opens as a row on the fan, its days the core's; a    /// day picked with no times offered is the whole edit.    func testPickOpensTheRowOnTheFan() async throws {        let core = core()        let editor = DeckEditor.standing()        editor.openDays(target, record: nil, core: core)        editor.openPick()        XCTAssertEqual(editor.editing, .pickDays(target))        XCTAssertTrue(editor.circles("t1"))        try await eventually { editor.pickedDays.count == 4 }        // The corner's days, its times and the pick are asked side by side, so        // in no fixed order: the pick is the one ask with `all`, and the four        // days drawn are its answer.        XCTAssertEqual(core.asked("shell.opened").filter { $0["all"] == .bool(true) }.map { $0["step"] }, [.string("when")])        XCTAssertEqual(editor.pickedDays[3].label, "Day 3", "in the core's words")        editor.choose(editor.pickedDays[3], store: nil, core: nil)        XCTAssertFalse(editor.isEditing, "with no times offered, a picked day is the whole edit")    }    func testTheDecksEditingPresentsNoSheet() throws {        let root = SourceSweep.iosSources.deletingLastPathComponent()  // apps/cotton, from the checkout under test        let editing = root.appendingPathComponent("Sources/CottonUI/Deck/Shell")        let files = try FileManager.default.contentsOfDirectory(atPath: editing.path).filter { $0.hasSuffix(".swift") }        XCTAssertFalse(files.isEmpty, "\(editing.path) read as empty")        for file in files {            var source = try String(contentsOf: editing.appendingPathComponent(file), encoding: .utf8)            // The system camera a picture door opens (DeckPictureDoors, 204d91f2d)            // is a door into a new record, as the photo picker is, never an            // editor: it covers the screen because the camera does. Its one            // cover is taken out; any other cover still fails.            source = source.replacingOccurrences(                of: #"\.fullScreenCover\(isPresented: \$camera\) \{\s*CameraPicker\("#,                with: "", options: .regularExpression            )            // `theme.sheet(.cream)` is the paper's colour, not a presenter.            for presenter in [".sheet(item:", ".sheet(isPresented:", ".fullScreenCover(", ".presentationDetents("] {                XCTAssertFalse(source.contains(presenter), "\(file) presents \(presenter) — bottom sheets are out of the deck")            }        }    }}