// R4 "receipts say what happened" and R2 "the bar's words name only what it// can do there", the Swift leftovers: a Settings switch names its record, a// command's receipt is brought into sight, a new password is answered with a// receipt, the bar on a page says what typing does on that record, and a// confirmed delete closes its page.//// Every record and name here is invented.importCottonValuesimportFoundationimport XCTestimportCottonKit@testable importCottonUI@MainActorfinalclassReceiptsSayWhatHappenedTests: XCTestCase {/// Read from the source tree, as the other definition tests read them:/// the package's own resource bundle is not there under `swift test` on a Mac.privatestaticvar resources: Bundle? {Bundle(url: SourceSweep.iosSources.appendingPathComponent("CottonUI/Resources")) }privatefunc bundled(_ id: String) throws -> TableDefinition {let loaded = FixtureDefinitions.load(from: try XCTUnwrap(Self.resources))returntry XCTUnwrap(loaded.definitions.first { $0.id == id }, "no bundled \(id)") }// ── C: a command's receipt is in sight ──// ── D and E: the bar's words on a page ──// ── F: Passwords' Keep it ──/// RULE: Keeping a new password answers a change — the list's receipt says it was added, by name, with an Undo that bins it — never a page opened with no word of what was kept.func testKeepingANewPasswordWearsAReceipt() asyncthrows {let (records, core) = tryPasswordsRecordsTests.records()let acts = await records.listActions(table: "secret")let login = try XCTUnwrap(acts.first { $0.id == "new-login" })let answers = try XCTUnwrap(login.answers(["name": "Harbour Mutual", "password": "an-invented-password"]))let outcome = tryawait records.perform(login, values: answers, table: "secret", record: nil)guardcase .change(let kept) = outcome else { return XCTFail("Keep it answered \(outcome), not a change") }let definition = try XCTUnwrap(PasswordsRecordsTests.definitions().first { $0.id == "secret" })let lines = ChangeLines.lines(kept, table: definition).map(\.kind) XCTAssertEqual(lines.count, 1)guardcase .added(let name)? = lines.first else { return XCTFail("Keep it is not an added line: \(lines)") } XCTAssertFalse(name.isEmpty, "the receipt names what was kept") XCTAssertTrue(kept.undoable) _ = tryawait records.undo(change: kept.id)// The bin is the core's (4b2351020): Undo of a Keep it is the core's delete, which bins it.let binned = awaitPasswordsRecordsTests.body(core, of: "records.delete") XCTAssertEqual(binned?["id"] as? String, "s-new", "Undo bins the password just kept") }// ── G: a confirmed delete closes its page ──}