// What a note carries, and the four rules the screen stands on.//// The read shape is `get_record`'s: `attachments: [{kind, id, position,// caption, recordCaption, title, contentType|mime, key, missing, bytes}]`,// absent or empty until the tools lane answers one. Every fixture here is// invented.importCottonKitimport XCTest@testable importCottonUIprivateenumAttachmentFixtures {staticfunc row( kind: String, id: String, position: Int, caption: String? = nil, recordCaption: String? = nil, title: String? = nil, key: String? = nil, mime: String? = nil, missing: Bool = false ) -> JSONValue {var out: [String: JSONValue] = ["kind": .string(kind),"id": .string(id),"position": .number(Double(position)),"missing": .bool(missing), ]iflet caption { out["caption"] = .string(caption) }iflet recordCaption { out["recordCaption"] = .string(recordCaption) }iflet title { out["title"] = .string(title) }iflet key { out["key"] = .string(key) }iflet mime { out["contentType"] = .string(mime) }return .object(out) }staticfunc record(_ rows: [JSONValue]) -> JSONValue { .object(["id": .string("note:1"), "body": .string(""), "attachments": .array(rows)]) }staticfunc attachment( kind: String = "photo", id: String, position: Int = 0, caption: String? = nil, recordCaption: String? = nil, title: String? = nil, key: String? = nil, contentType: String? = nil, missing: Bool = false ) -> RecordAttachment {RecordAttachment( kind: kind, id: id, position: position, caption: caption, recordCaption: recordCaption, title: title, key: key, missing: missing, contentType: contentType ) }}// ── The read ────────────────────────────────────────────────────────────────finalclassRecordAttachmentsReadTests: XCTestCase {}// ── The missing rule ────────────────────────────────────────────────────────finalclassRecordAttachmentMissingTests: XCTestCase {/// The tables the app ships, which say which attachments draw as prints.staticvar shipped: TableDefinitions {TableDefinitions(FixtureDefinitions.load(from: Bundle(url: SourceSweep.iosSources.appendingPathComponent("CottonUI/Resources"))).definitions) }}// ── The list, added to and taken from ───────────────────────────────────────finalclassRecordAttachmentListTests: XCTestCase {privatelet one = AttachmentFixtures.attachment(id: "photo:a", position: 0)privatelet two = AttachmentFixtures.attachment(kind: "video", id: "video:b", position: 1)func testTheWriteCarriesThePairAndNothingElse() {let captioned = AttachmentFixtures.attachment( id: "photo:a", caption: "From the read", key: "k", contentType: "image/jpeg") XCTAssertEqual(RecordAttachments.argument([captioned, two]), .array([ .object(["kind": .string("photo"), "id": .string("photo:a")]), .object(["kind": .string("video"), "id": .string("video:b")]), ]),"an entry with no `caption` key leaves the stored caption alone" ) }}// ── Inline, or in the strip ─────────────────────────────────────────────────finalclassRecordAttachmentPartitionTests: XCTestCase {privatelet picture = AttachmentFixtures.attachment(id: "photo:a", position: 0)privatelet film = AttachmentFixtures.attachment( kind: "video", id: "video:b", position: 1)privatelet paper = AttachmentFixtures.attachment( kind: "document", id: "6f1e", position: 2)}// ── Which caption a tile writes under itself ────────────────────────────────/// Two captions arrive on one row and they are not the same sentence: `caption`/// is what THIS note said about the picture, `recordCaption` what the record/// says about itself everywhere. The note's own words win; the record's stand/// when the note wrote none; the title carries a row from a server that answers/// neither, because both fields are optional on the wire.finalclassRecordAttachmentCaptionTests: XCTestCase {}// ── Moving one, and captioning one ──────────────────────────────────────────/// The two edit-mode verbs that rewrite the WHOLE list.////// `update_note`'s `attachments` replaces the set in the order it is given, so/// an order is only ever expressible whole — and an entry with NO `caption` key/// leaves the stored caption alone, which is the only reason a reorder can be/// sent without every caption on the note being rewritten by the phone.finalclassRecordAttachmentMoveTests: XCTestCase {privatelet one = AttachmentFixtures.attachment(id: "photo:a", position: 0)privatelet two = AttachmentFixtures.attachment( kind: "video", id: "video:b", position: 1)privatelet three = AttachmentFixtures.attachment( kind: "document", id: "6f1e", position: 2)privatevar list: [RecordAttachment] { [one, two, three] }// ── A move made in the strip ──────────────────────────────────────────}/// A caption written onto ONE picture, with every other entry's left alone.finalclassRecordAttachmentCaptionWriteTests: XCTestCase {privatelet one = AttachmentFixtures.attachment( id: "photo:a", position: 0, caption: "The wall before", recordCaption: "Kitchen, July")privatelet two = AttachmentFixtures.attachment( kind: "video", id: "video:b", position: 1, recordCaption: "The rehearsal")privatelet three = AttachmentFixtures.attachment( kind: "document", id: "6f1e", position: 2, title: "Lease")privatevar list: [RecordAttachment] { [one, two, three] }}