import CottonKit import XCTest @testable import CottonUI /// A route either opens or says its one line (walker pass 4, 16 Oct 2026: /// cottondev://memory opened nothing and said nothing). @MainActor final class DeepLinksTests: XCTestCase { func testBareToolArrivalUsesItsTileEvenWhenTheLegacyRouteDiffers() { XCTAssertTrue(BoardLayout.arrives(.money, at: .toolBoard(id: "money"), tool: "money")) XCTAssertTrue(BoardLayout.arrives(.todos(new: false), at: .todos(new: false), tool: "todos")) XCTAssertFalse(BoardLayout.arrives(.moneyTransaction(id: "sample"), at: .toolBoard(id: "money"), tool: "money")) } func testToolArrivalUsesTheTilePageAndColdArrivalIsAdopted() { let navigator = Navigator() var selected: Route? navigator.fanOpens = { selected = $0; return $0 == .todos(new: false) } navigator.open(.todos(new: false)) XCTAssertEqual(selected, .todos(new: false)) XCTAssertTrue(navigator.stack.isEmpty) let cold = Navigator() cold.open(.todos(new: false)) XCTAssertNil(cold.top, "Home must mount before the cold tool arrival can be placed") cold.fanOpens = { $0 == .todos(new: false) } XCTAssertTrue(cold.stack.isEmpty) let untiled = Navigator() untiled.open(.money) XCTAssertNil(untiled.top) untiled.fanOpens = { _ in false } XCTAssertEqual(untiled.top, .money, "a list absent from the fan still opens once the fan has answered") } /// RULE: a link that opens nothing says one line, on the phone and on the Mac alike — never silence. func testALinkOpensOrSaysItsLine() throws { let named = try XCTUnwrap(DeepLinks.link(try XCTUnwrap(URL(string: "cottondev://todos?database=invented-db")))) XCTAssertEqual(named.database, "invented-db", "the database the link names comes along") XCTAssertNotNil(DeepLinks.link(try XCTUnwrap(URL(string: "cottondev://todos"))), "a route the scheme names still opens") XCTAssertEqual(DeepLinks.link(try XCTUnwrap(URL(string: "cottondev://films")))?.route, .toolBoard(id: "films")) let nowhere = try XCTUnwrap(URL(string: "cottondev://no-such-place/bad")) XCTAssertNil(DeepLinks.link(nowhere)) XCTAssertTrue(DeepLinks.opensNothing(nowhere).contains("no-such-place"), "the line names what was asked for") } }