95 lines · 4.7 KB · SwiftRaw
// When → date then time (door row 4, cards/cases/todos-time): No date first// in the days, a day chosen goes straight on to the times (No time first),// the date line stays circled through both, and each write keeps the half it// is not given.import CottonValuesimport XCTest@testable import CottonUI@MainActorfinal class DeckEditorWhenTests: XCTestCase { func testTheCurrentLeafIsRaisedAtCentreWithLeavesOnBothSides() throws { let fan = FanGeometry(scale: Theme.paper.scale).withHub(diameter: 64) let current = 5 let theta = Double(current) * fan.step let centre = try XCTUnwrap(fan.placement(index: current, theta: theta, width: 393)) XCTAssertEqual(centre.centre.x, 393 / 2.0) XCTAssertEqual(centre.angle, 0) XCTAssertEqual(centre.nearness, 1) let left = try XCTUnwrap(fan.placement(index: current - 1, theta: theta, width: 393)) let right = try XCTUnwrap(fan.placement(index: current + 1, theta: theta, width: 393)) XCTAssertLessThan(left.centre.x, centre.centre.x) XCTAssertGreaterThan(right.centre.x, centre.centre.x) XCTAssertEqual(left.centre.y, right.centre.y) XCTAssertGreaterThan(left.centre.y, centre.centre.y) } func testArrivingChoicesCentreTheCurrentPickAndKeepLaterRiffles() { var tier = FanTier(id: "synthetic-days", cards: []) XCTAssertNil(tier.restingIndex, "an empty tier must not start motion and publish an initial zero settle") let none = FanTier.Card(id: "none", label: "Synthetic none") tier.replaceCards([none], restingAt: 0) XCTAssertEqual(tier.raised, "none") let days = [none] + (1...12).map { FanTier.Card(id: "day-\($0)", label: "Synthetic \($0)") } tier.replaceCards(days, restingAt: 5) XCTAssertEqual(tier.restingIndex, 5) XCTAssertEqual(tier.raised, "day-5", "the temporary first card must not override the current pick when choices arrive") tier.raised = "day-9" tier.replaceCards(days, restingAt: 5) XCTAssertEqual(tier.raised, "day-9", "repainting the same membership keeps the person's riffle") let fan = FanGeometry(scale: Theme.paper.scale).withHub(diameter: 64) let theta = 5 * fan.step XCTAssertNotNil(fan.placement(index: 4, theta: theta, width: 393)) XCTAssertNotNil(fan.placement(index: 6, theta: theta, width: 393)) } private let target = DeckEditTarget(table: "todo", record: "t1", date: "due") private let monday = DateChoice(key: "weekday-1", kind: "day", label: "Mon", detail: "26 Oct", day: "2026-10-26") func testADayGoesStraightOnToTheTimesWhenTheCoreOffersThem() { let editor = DeckEditor.standing() editor.show(times: [ TimeChoice(key: "none", label: "No time"), TimeChoice(key: "09:00", label: "9:00", time: "09:00"), TimeChoice(key: "10:30", label: "10:30", time: "10:30", chosen: true), TimeChoice(key: "pick", label: "Pick a time"), ]) editor.openDays(target, record: nil, core: nil) editor.choose(monday, store: nil, core: nil) XCTAssertEqual(editor.editing, .times(target)) XCTAssertEqual(editor.chosenDay, "2026-10-26") XCTAssertTrue(editor.circles("t1"), "the date line stays circled while the times stand") editor.choose(nil, store: nil, core: nil) XCTAssertFalse(editor.isEditing, "No time is the end of the edit") } func testDaysPushAndTimesReplaceAndCloseReturnsToActs() { let editor = DeckEditor.standing() editor.openActs(target, record: nil) editor.open(.days(target), core: nil) editor.show(times: [TimeChoice(key: "none", label: "No time")]) let depth = editor.navigation.depth editor.choose(monday, store: nil, core: nil) XCTAssertEqual(editor.navigation.depth, depth, "days → times replaces the shared tier") XCTAssertEqual(editor.navigation.open?.editorState, .times(target)) XCTAssertEqual(editor.editing, .times(target)) editor.close() XCTAssertEqual(editor.editing, .acts(target), "times replaced days; closing must not return to days") editor.close() XCTAssertNil(editor.editing) } func testWithoutTimesTheDayIsTheWholeEdit() { let editor = DeckEditor.standing() editor.openDays(target, record: nil, core: nil) editor.choose(monday, store: nil, core: nil) XCTAssertFalse(editor.isEditing) XCTAssertEqual(editor.marked?.record, "t1") } func testNoDateEndsTheEdit() { let editor = DeckEditor.standing() editor.openDays(target, record: nil, core: nil) editor.chooseNoDate(store: nil, core: nil) XCTAssertFalse(editor.isEditing) }}