// A card asked for from Home opens on its tool's deck, the fan turned to it// (real-data walk, 23 Oct: a deck stacked on Home had no fan and no way back).import XCTest@testable importCottonUI@MainActorfinalclassNavigatorBringsTests: XCTestCase {/// RULE: A record the fan can turn to is brought there and nothing is stacked on the page it was asked from.func testARecordTheFanHoldsIsBroughtNotStacked() {let navigator = Navigator()var asked: [String] = [] navigator.fanBrings = { table, id, many in XCTAssertFalse(many, "a card asked for is one card") asked.append("\(table)/\(id)")returntrue } navigator.open(table: "todo", id: "t-1", definition: nil) XCTAssertEqual(asked, ["todo/t-1"]) XCTAssertTrue(navigator.stack.isEmpty) }/// RULE: A record no tile on the fan holds opens as its page in place, as before.func testARecordTheFanDoesNotHoldOpensInPlace() {let navigator = Navigator() navigator.fanBrings = { _, _, _ infalse } navigator.open(table: "todo", id: "t-1", definition: nil) XCTAssertEqual(navigator.stack, [.tableRecord(table: "todo", id: "t-1")]) }/// RULE: The tile a card is brought to stands at its own deck, its pages let go.func testTheTileStandsAtItsRoot() {let navigator = Navigator() navigator.tile = "todos" navigator.push(.tableRecord(table: "todo", id: "t-9")) XCTAssertFalse(navigator.stack.isEmpty) navigator.standsAtRoot("todos") XCTAssertTrue(navigator.stack.isEmpty) }/// RULE: the first of many brought at once stands on the tool's view that reads the table whole — Books' All, never Reading, On this phone or a list.func testTheFirstOfManyStandsOnTheWholeView() throws {let url = SourceSweep.repoRoot.appendingPathComponent("crates/cotton-core/kits/personal/tables/book.json")let book = tryTableDefinition.decode(Data(contentsOf: url))let kit = SourceSweep.repoRoot.appendingPathComponent("crates/cotton-core/kits/personal/tools/books/manifest.json")let books = tryToolDefinition.decode(Data(contentsOf: kit)) XCTAssertEqual(book.id, "book")let views = try books.views.map { view inToolView(id: view.id, label: view.label, isDefault: view.isDefault, read: try JSONDecoder().decode(ToolView.Read.self, from: JSONEncoder().encode(view.read))) } XCTAssertGreaterThan(views.count, 2) XCTAssertEqual(ToolView.whole(of: "book", in: views)?.id, "all") XCTAssertNil(ToolView.whole(of: "highlight_none", in: views)) XCTAssertTrue(Navigator.Bringing(table: "book", id: "b", many: true).many) XCTAssertFalse(Navigator.Bringing(table: "book", id: "b").many) }/// RULE: a card of another table on the deck's own tool turns the ring to the tool's view that reads that table whole — a link shared into Web pages while it stood on Made for you (documents) opens on All at its card (Rigby 11 walk, 8 Nov 2026); a card of the deck's own table is taken where it stands, the first of many on the whole view, and another tool's deck leaves it.func testABroughtCardOfAnotherTableTurnsTheToolToItsWholeView() throws {let kit = SourceSweep.repoRoot.appendingPathComponent("crates/cotton-core/kits/personal/tools/artifacts/manifest.json")let artifacts = tryToolDefinition.decode(Data(contentsOf: kit))let views = try artifacts.views.map { view inToolView(id: view.id, label: view.label, isDefault: view.isDefault, read: try JSONDecoder().decode(ToolView.Read.self, from: JSONEncoder().encode(view.read))) }let made = try XCTUnwrap(views.first { $0.id == "made" })let all = try XCTUnwrap(ToolView.whole(of: "page", in: views)) XCTAssertNotEqual(made.read.table, "page", "Made for you reads another table")let link = Navigator.Bringing(table: "page", id: "p-1") XCTAssertEqual(DeckBrought.step(link, deckTable: made.read.table, deckView: "artifacts/made", tool: "artifacts", views: views), .turn(all.id)) XCTAssertEqual(DeckBrought.step(link, deckTable: "page", deckView: "artifacts/\(all.id)", tool: "artifacts", views: views), .take) XCTAssertEqual(DeckBrought.step(link, deckTable: "todo", deckView: "todos/all", tool: "todos", views: []), .leave)let many = Navigator.Bringing(table: "page", id: "p-1", many: true) XCTAssertEqual(DeckBrought.step(many, deckTable: "page", deckView: "artifacts/elsewhere", tool: "artifacts", views: views), .turn(all.id)) }/// RULE: the fan's closures read the board as it stood when they were set, so they are set again whenever its tiles, its tables, its tools, its arrangement or its page drawer change — never on the tiles' keys alone.func testTheFanBringsAgainAsTheBoardChanges() throws {let board = tryString(contentsOf: SourceSweep.source("CottonUI/Surfaces/BoardSurface.swift"), encoding: .utf8) XCTAssertFalse(board.contains(".task(id: tiles.map(\\.key)) {\n navigator?.fanBrings"), "armed on the tiles' keys alone") XCTAssertTrue(board.contains("FanArming(tiles: tiles.map(\\.key), tables: definitions.all.map(\\.id), tools: catalogue.all.map(\\.id)"),"armed again as the definitions and the tools come") }}