// Everything a board opens is a route on the navigator's path (build 228's // walk, run-bc912cd47: the Disk card on the Tools screen opened nothing). // // The Tools screen and the database page are boards PUSHED over Home, which is // itself a board. SwiftUI honours the `navigationDestination(item:)` for a // given item type declared nearest the stack's root and ignores the same // declaration on a pushed screen ("A navigationDestination for … was declared // earlier on the stack"), so a pushed board's own destination was a tap that // did nothing — and the simulator walks that stood on Home never saw it. A // destination declared per surface is therefore wrong on any surface that can // be pushed, and the board's opens are routes instead (`/tools/board/[id]`, // `/lists/[table]/[id]`, `/lists/[table]`). import CottonKit import XCTest @testable import CottonUI final class BoardOpensThroughRoutesTests: XCTestCase { /// RULE: A data tool's card opens its one table's list, or — a package of more than one table — its own board's route; a table that names no screen opens `/lists/[table]` (the Disk card's table, `disk_claim`, opened nothing on build 228). func testADataToolOpensARoute() { let claim = table("disk_claim") let lesson = table("lesson") let pupil = table("pupil") let definitions = TableDefinitions([claim, lesson, pupil]) let disk = tool("disk", tables: ["disk_claim"]) let classroom = tool("classroom", tables: ["lesson", "pupil"]) let list = Route.tableList(table: "disk_claim", filter: nil, title: nil, query: nil) XCTAssertEqual(BoardLayout.route(for: disk, in: definitions, tools: [disk, classroom]), list) XCTAssertEqual(BoardLayout.route(for: classroom, in: definitions, tools: [disk, classroom]), .toolBoard(id: "classroom")) XCTAssertEqual(BoardLayout.route(forTable: claim), list, "a table that names no screen opens its list") XCTAssertEqual(BoardLayout.listRoute(for: table("member")), .members, "a Settings source opens its own route") } /// RULE: The two routes a board opens parse back from their own paths, so a deep link, a held tap and the path agree on them. func testTheBoardsRoutesRoundTrip() { for route in [Route.toolBoard(id: "disk"), .tableRecord(table: "disk_claim", id: "c-1")] { XCTAssertEqual(Route.parse(route.path), route, route.path) } XCTAssertEqual(Route.toolBoard(id: "disk").listRoot, .toolBoard(id: "disk"), "a tool's board is a list") XCTAssertEqual( Route.tableRecord(table: "disk_claim", id: "c-1").listRoot, .tableList(table: "disk_claim", filter: nil, title: nil, query: nil), "a record is picked from its table's list") } /// RULE: A data tool opens as its home table's list when its other tables are `list` sections of the home's page — the owner's Quotas (quota + quota_reading, the readings on each account's page) opened a "Quotas / Readings" sections page instead of the account cards — and such a supporting table gets no section of its own; a table that is neither keeps the sections page. func testAToolWhoseOtherTablesAreSectionsOfItsHomeOpensAsTheHomesList() { var quota = table("quota") quota.page.append(PageSection(heading: "History", list: SectionList(table: "quota_reading", link: "quota_id"))) let reading = table("quota_reading") let note = table("quota_note") let definitions = TableDefinitions([quota, reading, note]) let quotas = tool("quotas", tables: ["quota", "quota_reading"]) XCTAssertEqual(BoardLayout.directTable(for: quotas, in: definitions)?.id, "quota") XCTAssertEqual(BoardLayout.route(for: quotas, in: definitions, tools: [quotas]), .tableList(table: "quota", filter: nil, title: nil, query: nil)) let mixed = tool("quotas", tables: ["quota", "quota_reading", "quota_note"]) XCTAssertNil(BoardLayout.directTable(for: mixed, in: definitions)) XCTAssertEqual(BoardLayout.route(for: mixed, in: definitions, tools: [mixed]), .toolBoard(id: "quotas")) XCTAssertEqual(BoardLayout.tables(for: mixed, in: definitions).map(\.id), ["quota", "quota_note"]) } private func table(_ id: String) -> TableDefinition { TableDefinition( id: id, name: id, plural: id, picture: nil, columns: [ColumnDefinition(key: "title", type: .text)], title: "title", slip: SlipLayout(title: "title"), tile: TileLayout(face: .slipList), page: [PageSection(heading: nil, columns: ["title"])]) } private func tool(_ id: String, tables: [String]) -> ToolDefinition { ToolDefinition( id: id, name: id, picture: nil, tables: tables, instructions: "", automations: [], author: ToolDefinition.Author(device: "test", name: "Test"), signature: nil) } }