// The Bin as its table's list and page, with nothing the old Bin screen showed // lost (the no-loss audit's thirteen): every binned record newest first, under // its table's heading in core's order with "N items", the table as one plain // word, "Binned ", drawn faded; Restore typed under each row and on its // page, the record leaving the list once restored; the empty words; the grid; // no Delete per row and nothing editable; "Empty the bin" with its line by // hand, its question stating the count, and "Bin emptied" — and Settings' // "In the bin" count, read by the model that moved beside it. Each is a // generic definition key or surface drawn once, never the Bin's own Swift. // Every record is invented. import CottonKit import CottonValues import Foundation import XCTest @testable import CottonUI @MainActor final class BinNoLossTests: XCTestCase { private static var resources: Bundle? { Bundle(url: SourceSweep.iosSources.appendingPathComponent("CottonUI/Resources")) } private static var calendar: Calendar { var out = Calendar(identifier: .gregorian) out.timeZone = TimeZone(identifier: "Asia/Kolkata") ?? .gmt out.locale = Locale(identifier: "en_US_POSIX") return out } private func bin() throws -> TableDefinition { let loaded = FixtureDefinitions.load(from: try XCTUnwrap(Self.resources)) return try XCTUnwrap(loaded.definitions.first { $0.id == "bin" }) } private func binned() throws -> [TableRecord] { try FixtureDefinitions.fixtureRecords(for: "bin", bundle: try XCTUnwrap(Self.resources)) } private func code(_ path: String) throws -> String { SourceSweep.withoutComments( try String(contentsOf: SourceSweep.iosSources.appendingPathComponent("CottonUI/\(path)"), encoding: .utf8)) } private func row(_ id: String, kind: String, at iso: String, state: String = "binned") -> TableRecord { TableRecord(id: id, values: [ "kind": .text(kind), "title": .text(id), "trashed_at": .text(iso), "state": .text(state), ]) } /// RULE: Restore is a typed verb under every binned row (never a swipe) that writes state "restored" through the generic update_record — the engine's restore_from_bin — after which the row offers no verb and goes at the next read (43cf0aa68), and its receipt names the verb. func testRestoreIsAnAnswerAndARestoredRowLeaves() async throws { let definition = try bin() let rows = try binned() let first = try XCTUnwrap(rows.first) XCTAssertEqual(definition.drawnAnswers(first).count, 1) let store = FixtureRecords(definitions: [definition], records: ["bin": rows]) let model = RecordListModel(definition: definition, store: store, core: ListCoreFake(), seeds: ListSeeds()) await model.reload(project: nil, query: "") XCTAssertEqual(model.records.count, rows.count) let answered = try await model.answer(first, "restored") let change = try XCTUnwrap(answered) XCTAssertEqual(change.after?["state"].text, "restored") XCTAssertEqual(definition.drawnAnswers(try XCTUnwrap(change.after)), [], "no verb once restored") } /// RULE: Empty the bin erases every row through the generic delete_record, one at a time — the old Empty dialog's one act; its question and count are the core's (`clear`). func testEmptyTheBinErasesEveryRow() async throws { let definition = try bin() let rows = try binned() let store = FixtureRecords(definitions: [definition], records: ["bin": rows]) let model = RecordListModel(definition: definition, store: store, core: ListCoreFake(), seeds: ListSeeds()) await model.reload(project: nil, query: "") let outcome = await model.delete(ids: model.records.map(\.id)) XCTAssertEqual(outcome.deleted.count, rows.count) XCTAssertEqual(outcome.failed, []) await model.reload(project: nil, query: "") XCTAssertEqual(model.records, []) } }