// Nancy's Naga Kitchen's faces: which cards wear them, what they read off a // delivery's columns and its columns' labels, the letters drawn with no // picture, and the rupee every amount is said in. The faces stay with the // kitchen kit, whose views name them; Nancy's app left the tree (22 Nov 2026). import CottonValues import ImageIO import SwiftUI import UniformTypeIdentifiers import XCTest import CottonPaper @testable import CottonFaces @testable import CottonUI @MainActor final class KitchenFacesTests: XCTestCase { /// A delivery as the kitchen package names it. static func delivery() throws -> TableDefinition { let json = """ {"id":"kitchen_delivery","name":"Delivery","plural":"Deliveries","builtin":false, "columns":[{"key":"name","name":"Delivery","type":"text"}, {"key":"delivered","name":"Delivered","type":"bool"}, {"key":"paid","name":"Paid","type":"bool"}, {"key":"subscription","name":"Plan","type":"text"}, {"key":"address","name":"Address","type":"longtext"}, {"key":"total","name":"Total","type":"amount"}, {"key":"due_on","name":"Due","type":"date"}], "title":"name","date":null,"project":null,"order":null, "slip":{"title":"name"},"tile":{"face":"slip-list"},"page":[], "card":{"face":"nancy.delivery","fields":[ {"slot":"title","column":"name"},{"slot":"body","column":"address"}, {"slot":"amount","column":"total"},{"slot":"date","column":"due_on"}]}, "tables":[]} """ return try JSONDecoder().decode(TableDefinition.self, from: Data(json.utf8)) } /// RULE: a card wears the kitchen's face its kit names (`nancy.dish`, …), drawn by the deck from Loom's registry with its table's labels on its card — never chosen by the flavour the app runs as, and every one a face Loom registers. func testTheKitchensFacesAreTheIdsItsKitNames() throws { XCTAssertEqual(FaceRegistry.ids, Set(FaceRegistry.all.map(\.id)), "the registry's ids are not its faces'") let faces: [DefinitionCardKind] = [.nancyDish, .nancyChef, .nancyPlan, .nancyPlace, .nancyCatering, .nancyDelivery] for face in faces { XCTAssertEqual(DeckFace.registered(DeckCard(face: face, fields: [:]))?.id, face.rawValue, "\(face.rawValue) is no face Loom registers") XCTAssertTrue(DeckFace.draws(DeckCard(face: face, fields: ["title": .text("Invented")]))) } let deck = SourceSweep.withoutComments(try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Deck/DeckCardFill.swift", ownedBy: "loom")) XCTAssertFalse(deck.contains("FlavourLook"), "the kitchen's faces are chosen by the flavour") } /// RULE: a delivery's Delivered, Paid and plan state are read from its own columns (`delivered`, `paid`, `subscription`), never from the words its card says. func testADeliverysStateIsItsColumns() throws { let row = TableRecord(id: "d-1", values: ["delivered": .bool(true), "paid": .bool(false), "subscription": .text("sub-1")]) XCTAssertEqual(KitchenDeliveryState.of(row), KitchenDeliveryState(delivered: true, paid: false, onPlan: true)) let bare = TableRecord(id: "d-2", values: ["subscription": .text(" ")]) XCTAssertEqual(KitchenDeliveryState.of(bare), KitchenDeliveryState(delivered: false, paid: false, onPlan: false), "an unset bool is not done, and a blank link is no plan") } /// RULE: the plan tag is the plan column's own label, shown only while the delivery is a meal on a plan. func testThePlanTagIsThePlanColumnsLabelWhileOnAPlan() throws { let labels = DeckCardFill.labels(try Self.delivery()) XCTAssertEqual(KitchenDeliveryState.of(TableRecord(id: "d", values: ["subscription": .text("s")])).planTag(labels), "Plan") XCTAssertNil(KitchenDeliveryState.of(TableRecord(id: "d", values: [:])).planTag(labels), "off a plan there is no tag") } /// RULE: every fact on a kitchen face stands under its column's label as the package wrote it — a card place by the column its card names ("Address", "Due", "Total"), a state by its own column ("Delivered", "Paid"). func testEachPlaceIsLabelledByItsColumn() throws { let labels = DeckCardFill.labels(try Self.delivery()) XCTAssertEqual(labels[slot: "body"], "Address") XCTAssertEqual(labels[slot: "date"], "Due") XCTAssertEqual(labels[slot: "amount"], "Total") XCTAssertEqual(labels[column: "delivered"], "Delivered") XCTAssertNil(labels[slot: "photo"], "a place the card does not fill has no label") XCTAssertEqual(DeckCardFill.labels(nil), CardLabels(), "no definition, no labels") } /// RULE: a delivery's Delivered and Paid are drawn only as states, stamped under their columns' labels and only once the columns hold them — never as buttons; the acts are on the long-press fan. func testDeliveredAndPaidAreStampedOnlyWhenHeld() throws { let labels = DeckCardFill.labels(try Self.delivery()) XCTAssertEqual(KitchenDeliveryState(delivered: true, paid: true, onPlan: false).stamps(labels), ["Delivered", "Paid"]) XCTAssertEqual(KitchenDeliveryState(delivered: false, paid: true, onPlan: false).stamps(labels), ["Paid"]) XCTAssertEqual(KitchenDeliveryState(delivered: false, paid: false, onPlan: true).stamps(labels), []) } /// RULE: a kitchen face draws the record's own picture, else its name's letters — never a stock face. func testAPictureElseTheNamesLetters() { XCTAssertEqual(KitchenPortrait.of(DeckCard(face: .plain, fields: ["title": .text("Nancy"), "photo": .text("photo:1")])), .photo("photo:1")) XCTAssertEqual(KitchenPortrait.of(DeckCard(face: .plain, fields: ["title": .text("Naga Kitchen")])), .monogram("NK")) XCTAssertNil(KitchenPortrait.of(DeckCard(face: .plain, fields: [:])), "no name, no letters") } /// RULE: an amount in rupees is said with ₹ wherever Swift spells one (the editor's echo), as the core's money lines say it — never the locale's "Rs". func testRupeesAreSaidWithTheRupeeSign() { for locale in ["en_IN", "en_US", "en_GB", "ur_PK", "ne_NP"].map(Locale.init(identifier:)) { let said = AmountValue(minor: 29900, currency: "INR").words(locale: locale) XCTAssertTrue(said.contains("₹"), "\(locale.identifier) said \(said)") XCTAssertFalse(said.contains("Rs"), "\(locale.identifier) said \(said)") XCTAssertEqual(AmountValue.symbol("INR", locale: locale), "₹") } XCTAssertEqual(AmountValue.coreSymbol("inr"), "₹", "a code in any case") XCTAssertNil(AmountValue.coreSymbol("XTS"), "a code the money lines do not name has none") } }