import CottonKit import CottonValues import Foundation import XCTest @testable import CottonUI /// Settings on its views (the owner, 23 Oct 2026: a deck like everything /// else, never a list): the dial's Settings card stands on one view per row, /// as the core answers them (`shell.fan`), and the page under the chosen /// view is that row's own screen. Every row is the shipped board's. @MainActor final class SettingsRingTests: XCTestCase { /// The Settings card's views as the core answers them: each row by its /// name, opening its route, the first the default. private static let views: [ToolView] = [ ("this-device", "This device", "/device"), ("city", "Your city", "/me?raise=city"), ("bring-in", "Bring in", "/bring-in"), ("export", "Export", "/export"), ("about", "About", "/about"), ].enumerated().map { at, row in var view = ToolView(id: row.0, label: row.1, isDefault: at == 0, read: .init(table: SettingsRing.table)) view.address = row.2 return view } /// RULE: The core's Settings views decode with the route each opens, and draw one leaf each in their order. func testTheAnsweredViewsAreItsLeaves() throws { let json = #"{"id":"export","label":"Export","default":false,"count":null,"address":"/export","read":{"table":"settings"}}"# let view = try JSONDecoder().decode(ToolView.self, from: Data(json.utf8)) XCTAssertEqual(view.address, "/export") let tier = ViewTier.make(tool: SettingsRing.tool, views: Self.views, current: "export") XCTAssertEqual(tier.cards.map(\.id), Self.views.map(\.id)) XCTAssertEqual(tier.cards.map(\.label), Self.views.map(\.label)) XCTAssertTrue(tier.cards.allSatisfy { $0.style == .leaf }) XCTAssertEqual(tier.raised, "export") } /// RULE: A view's page is the thing itself — the screen its row's route draws: This device's own record, the Me page with its city raised, Bring in, Export and About. func testAViewsPageIsItsRowsOwnScreen() throws { XCTAssertEqual(Self.views.map(SettingsRing.route(of:)), [.device, .raised(.me, part: "city"), .bringIn, .export, .about]) var stray = Self.views[0] stray.address = "/no-such-screen" XCTAssertNil(SettingsRing.route(of: stray), "a route this build has no screen for opens none") } /// RULE: Holding the Export view turns the fan into the tables (`ExportFan`), as the Export card's hold did; no other view, and no other tool's view of the same id, opens it. func testOnlyTheExportViewHoldsTheTables() throws { let held = Self.views.compactMap { SettingsRing.exports(tool: SettingsRing.tool, view: $0) } XCTAssertEqual(held, [DeckEditTarget(table: "settings", record: "export", date: nil)]) let export = try XCTUnwrap(Self.views.first { $0.id == "export" }) XCTAssertNil(SettingsRing.exports(tool: "todos", view: export)) } }