// The board draws Home's tiles, and only the shown database's own: its answer// or kept answer, in the one order every fan has (by name) — and an answer is// drawn only under the database it was read for.importCottonKitimport XCTest@testable importCottonUI@MainActorfinalclassBoardArrangementTests: XCTestCase {privatefunc answer(order: [String]) -> String {TodayAnswerJSON.answer(arrangement: TodayAnswerJSON.arrangement(order)) }// RULE: The fan never draws a set of the app's own: a database with no answer and no kept answer draws no tile at all — the bundle's built-ins are no database's tiles — and a database read draws its own (295 A, walker294: every switch passed through the bundle's set, then re-dealt).func testADatabaseNeverReadDrawsNoTileNotTheBundlesOrder() async {let core = ScriptedCore([:])let home = HomeModel(core: core, toasts: ToastCenter(scheduler: ManualToastScheduler()))var aimed: String? = nil home.askingDatabase = { aimed } XCTAssertNil(home.drawnTiles(for: nil), "nothing read: no order to draw")let methods = await core.methodsCalled() XCTAssertEqual(methods, [], "and nothing is read to say so")await core.answer(CottonMethod.shellToday, .ok(answer(order: ["todos", "notes"])))await home.load() XCTAssertEqual(home.drawnTiles(for: nil)?.tools, ["todos", "notes"], "the answer draws the database's own arrangement") aimed = "allotment" home.turned() XCTAssertFalse(home.isArranged) XCTAssertNil(home.drawnTiles(for: "allotment"), "a database never read draws nothing, never the last database's set") XCTAssertEqual(HomeTiles(answer: nil).tiles, [], "an answer with no arrangement holds no tile") XCTAssertNil(HomeTiles(arranged: .object([:])), "and is no arrangement") }// RULE: Home's answer is drawn only under the database it was read for — a cold launch whose first read went to another database draws nothing, then reads again; the head says no 'only you' and no figures until then.func testAnAnswerIsDrawnOnlyUnderTheDatabaseItWasReadFor() asyncthrows {let core = ScriptedCore([:])let home = HomeModel(core: core, toasts: ToastCenter(scheduler: ManualToastScheduler()))var aimed: String? = nil home.askingDatabase = { aimed }await core.answer(CottonMethod.shellToday, .ok(answer(order: ["calendar", "notes", "todos"])))await home.load() XCTAssertTrue(home.answers(nil), "read before the calls were aimed: Personal's answer") XCTAssertFalse(home.answers("allotment"), "never drawn under Allotment")await home.readAgainIfAskedElsewhere(shown: "allotment") XCTAssertFalse(home.answers("allotment"), "the calls still name Personal: nothing to read again yet") aimed = "allotment"await home.readAgainIfAskedElsewhere(shown: "allotment") XCTAssertTrue(home.answers("allotment"), "aimed at Allotment, Home reads again for it") aimed = "garden" home.turned() XCTAssertFalse(home.answers("allotment"), "a switch never draws another database's answer") XCTAssertFalse(home.answers("garden"), "Garden was never read: nothing of it to draw") }// RULE: A switch to a database read before draws its own last answer at once — its arrangement and its head, under its own name only — and the read that follows brings it up to date: a switch never draws the shipped set and an unanswered Me for a read away and then deals the database's own set over it (293 row 2, walker292: read.home took 1–1.8 s on the real household, so every switch showed the bundle's set and Me's Today standing where its head goes, then re-dealt).func testASwitchBackDrawsTheDatabasesOwnLastAnswerAtOnce() async {let core = ScriptedCore([:])let home = HomeModel(core: core, toasts: ToastCenter(scheduler: ManualToastScheduler()))var aimed: String? = nil home.askingDatabase = { aimed }await core.answer(CottonMethod.shellToday, .ok(answer(order: ["todos", "notes"])))await home.load() aimed = "allotment" home.turned()await core.answer(CottonMethod.shellToday, .ok(answer(order: ["mood", "goals", "calendar"])))await home.load() XCTAssertEqual(home.homeTiles.tools, ["mood", "goals", "calendar"])let reads = await core.methodsCalled().filter { $0 == CottonMethod.shellToday }.count aimed = nil home.turned() XCTAssertTrue(home.answers(nil), "Personal's own last answer, drawn at the switch") XCTAssertFalse(home.answers("allotment")) XCTAssertEqual(home.homeTiles.tools, ["todos", "notes"], "its own arrangement, before any read") XCTAssertEqual(home.drawnTiles(for: nil)?.tools, ["todos", "notes"]) XCTAssertTrue(home.hasRead(nil))let after = await core.methodsCalled().filter { $0 == CottonMethod.shellToday }.count XCTAssertEqual(after, reads, "drawn with no read") aimed = "allotment" home.turned() XCTAssertTrue(home.answers("allotment")) XCTAssertEqual(home.homeTiles.tools, ["mood", "goals", "calendar"], "and Allotment's, never Personal's")await core.answer(CottonMethod.shellToday, .ok(answer(order: ["goals", "mood"])))await home.load() XCTAssertEqual(home.homeTiles.tools, ["goals", "mood"], "the read that follows brings it up to date") }}