// The Export card's fan (the owner, 23 Oct 2026): held, Settings' Export // card turns the fan into every table on the phone — as the core's // Everything table lists them, with their counts — and Everything first; a // table's card exports that table alone, Everything every table a package // carries. // The fan is drawn on the phone only (`EditingFan.swift` is `#if os(iOS)`). #if os(iOS) import CottonValues import XCTest @testable import CottonUI @MainActor final class ExportFanTests: XCTestCase { private func table(_ id: String, _ plural: String, kind: String? = nil) -> TableDefinition { var definition = TableDefinition( id: id, name: plural, plural: plural, columns: [ColumnDefinition(key: "name", type: .text)], title: "name", slip: SlipLayout(title: "name"), tile: TileLayout(face: .slipList), page: []) definition.recordKind = kind return definition } private var definitions: TableDefinitions { TableDefinitions([ table("todo", "Todos", kind: "todo"), table("person", "People", kind: "person"), table("device", "Devices"), table("everything", "Everything"), ]) } private func row(_ id: String, _ name: String?, count: Double?) -> TableRecord { var values: [String: RecordValue] = ["count": count.map(RecordValue.number) ?? .null] if let name { values["name"] = .text(name) } return TableRecord(id: id, values: values) } /// RULE: The fan offers every table the Everything read lists — the stored ones and those a package does not carry alike — by name, each once, never the Everything table itself. func testEveryTableOnThePhoneIsOffered() { let rows = [ row("todo", "Todos", count: 12), row("device", "Devices", count: 2), row("person", "People", count: 40), row("todo", "Todos", count: 12), row("everything", "Everything", count: 4), ] let tables = ExportFan.tables(rows, definitions: definitions) XCTAssertEqual(tables.map(\.id), ["device", "person", "todo"]) XCTAssertEqual(tables.map(\.count), [2, 40, 12]) XCTAssertEqual(tables.map(\.carried), [false, true, true]) } /// RULE: A row the core could not count says no count, never zero; a row with no name says its table's plural. func testAnUncountedTableSaysNoCount() { let tables = ExportFan.tables([row("person", nil, count: nil)], definitions: definitions) XCTAssertEqual(tables, [ExportTable(id: "person", name: "People", count: nil, carried: true)]) let items = ExportFan.items(tables, everything: "Everything") XCTAssertNil(items.last?.detail) } /// RULE: Everything stands first, then one card per table with its count under its name. func testEverythingStandsFirstThenTheTables() { let tables = ExportFan.tables( [row("todo", "Todos", count: 12), row("device", "Devices", count: 2)], definitions: definitions) let items = ExportFan.items(tables, everything: "Everything") XCTAssertEqual(items.map(\.word), ["Everything", "Devices", "Todos"]) XCTAssertEqual(items.map(\.detail), [nil, "2", "12"]) XCTAssertEqual(items.first?.id, ExportFan.everythingItem) } /// RULE: A table's card exports that table's id alone; Everything exports every offered table a package carries, in the order offered. func testWhatATapExports() { let tables = ExportFan.tables( [row("todo", "Todos", count: 1), row("device", "Devices", count: 1), row("person", "People", count: 1)], definitions: definitions) let items = ExportFan.items(tables, everything: "Everything") XCTAssertEqual(items.map(\.does), [ .export(["person", "todo"]), .export(["device"]), .export(["person"]), .export(["todo"]), ]) } /// RULE: With no word for it, or no table a package carries, there is no Everything card — the tables still stand. func testNoEverythingWithoutItsWordOrATableToCarry() { let carried = ExportFan.tables([row("todo", "Todos", count: 1)], definitions: definitions) XCTAssertEqual(ExportFan.items(carried, everything: nil).map(\.id), ["export-todo"]) let uncarried = ExportFan.tables([row("device", "Devices", count: 1)], definitions: definitions) XCTAssertEqual(ExportFan.items(uncarried, everything: "Everything").map(\.id), ["export-device"]) } /// RULE: Only Settings' Export card opens the export fan on a hold; every other card opens its acts. func testOnlyTheExportCardOpensTheFan() { XCTAssertTrue(ExportFan.opens(table: "settings", record: "export")) XCTAssertFalse(ExportFan.opens(table: "settings", record: "bring-in")) XCTAssertFalse(ExportFan.opens(table: "todo", record: "export")) } /// RULE: The export fan is a hold's answer: the record button under it is the acts' pale close, and the fan answers for the Export card. func testTheExportFanIsAHoldsAnswer() { let editor = DeckEditor.standing() let target = DeckEditTarget(table: "settings", record: "export", date: nil) editor.openExports(target, record: nil) XCTAssertEqual(editor.editing, .exports(target)) XCTAssertEqual(editor.target, target) XCTAssertTrue(editor.holdsActs) editor.close() XCTAssertFalse(editor.isEditing) } } #endif