// The fan's cases, plus the "+ fan" block of the capture dock's four — the two that assert WHICH rows and WHERE each one goes come // over; the two that assert a sheet library's present/dismiss handle die with // the library, per this target's own rule about render assertions. // // The fan is the DETERMINISTIC lane — nothing in it asks a model anything — so // what a test can protect is the shape of the list: stable keys, a destination // per row, the glyph each one wears, and the one ordering decision the meetings // pair carries. // // Since chain 2 (ruling R11) a row has TWO possible destinations: a route to // push, or a SHEET the host owns. Memory is the only sheet row, and it exists // because a project's sentences are written where the project is — there is no // "new memory" route to push, and inventing one would be a second way to do the // thing. import CottonKit import XCTest @testable import CottonUI private let day = "2026-09-09" private func rows(canAddMemory: Bool = false) -> [AddFanAction] { addFanActions(today: day, canAddMemory: canAddMemory) } private func row(_ key: String, canAddMemory: Bool = false) -> AddFanAction? { rows(canAddMemory: canAddMemory).first { $0.key == key } } private func pushedPath(_ action: AddFanAction?) -> String? { guard case .push(let route)? = action?.destination else { return nil } return route.path } final class AddFanActionsTests: XCTestCase { // ── The list's shape ────────────────────────────────────────────────── func testGivesEveryRowAUniqueKeyTheyAreIdentifiersToo() { // The only claim worth making over a hard-coded list: two rows with one // key would silently collide in the fan's accessibility identifiers and // in `ForEach`'s own identity, which is a redraw bug rather than a // visible one. let keys = rows(canAddMemory: true).map(\.key) XCTAssertEqual(Set(keys).count, keys.count) } func testOffersTheMemoryRowOnlyToAHostThatCanOpenTheSheet() { // `canAddMemory` is the host saying "I can open my own creation sheet". // Only the project page can today: Home's dock is capture and Me's dock // is the memory composer, so a Memory row there would be a second way // to write the same sentence. XCTAssertFalse(rows().map(\.key).contains("memory")) XCTAssertTrue(rows(canAddMemory: true).map(\.key).contains("memory")) } func testTheMemoryRowOpensASheetNeverARoute() { let memory = row("memory", canAddMemory: true) XCTAssertNotNil(memory) // The VALUE is the behaviour: the sheet pushes a row whose destination // is a route and hands a `.sheet` row back to the host, so naming the // sheet is what says "this row opens the host's own surface". XCTAssertEqual(memory?.destination, .hosted(.memory)) } // ── The rows that went with their placeholder pages ─────────────────── // ── The two verbs a meeting is made by ──────────────────────────────── // ── Where each row goes (CaptureDock's fan block) ───────────────────── func testTheEventRowIsAnchoredOnTheDayItWasHanded() { // The create/edit screen with no id = create. The previous function // read today's key itself; this one takes the day, so the anchor is a // fact a test can state rather than a wall clock it has to chase. XCTAssertEqual( row("event")?.destination, .push(.calendarEventEdit(id: nil, date: day, at: nil)) ) XCTAssertEqual( addFanActions(today: "2027-01-01").first(where: { $0.key == "event" })?.destination, .push(.calendarEventEdit(id: nil, date: "2027-01-01", at: nil)) ) } // ── The glyphs ──────────────────────────────────────────────────────── // ── The words ───────────────────────────────────────────────────────── // ── The two rows that put a picture on the thought ──────────────────── /// Only a host holding a DRAFT is offered Picture — Home's own fan and the /// project page are not, so their counts above are unchanged — and the /// Camera row stands beside it only where this machine has a camera. func testPictureRowsAreOfferedOnlyToAHostWithADraft() { XCTAssertFalse(rows().map(\.key).contains("picture")) XCTAssertFalse(rows().map(\.key).contains("camera")) let withLibrary = addFanActions(today: day, canAttachPictures: true) XCTAssertEqual(withLibrary.first?.key, "picture", "they act on the thought, so they lead") XCTAssertFalse(withLibrary.map(\.key).contains("camera"), "no camera, no Camera row") XCTAssertEqual(withLibrary.count, rows().count + 1) let withCamera = addFanActions(today: day, canAttachPictures: true, hasCamera: true) XCTAssertEqual(withCamera.prefix(2).map(\.key), ["picture", "camera"]) // A camera without a draft is still no row: there is nothing to put // the photograph on. XCTAssertFalse( addFanActions(today: day, hasCamera: true).map(\.key).contains("camera")) } /// Both are sheets the HOST raises over the draft, never a push — the /// capture surface stays up under them. func testPictureRowsRaiseTheHostsOwnSheets() { let rows = addFanActions(today: day, canAttachPictures: true, hasCamera: true) XCTAssertEqual(rows.first { $0.key == "picture" }?.destination, .hosted(.photoLibrary)) XCTAssertEqual(rows.first { $0.key == "camera" }?.destination, .hosted(.camera)) for action in rows.prefix(2) { XCTAssertNotNil( Glyph.symbol(action.icon), "\(action.key) wears '\(action.icon)', which Glyph's table does not answer" ) XCTAssertFalse(action.label.isEmpty) } } }