29 lines · 1.7 KB · SwiftRaw
// Search is a deck (coordinator's ruling, 23 Oct): one card per record a// search found, in its order, each the record the core says the hit stands// for (`read.find`'s `record`), under one chip per table that has hits.import XCTest@testable import CottonUI@MainActorfinal class SearchDeckTests: XCTestCase { private func hit(_ kind: String, _ id: String, card: (String, String)?) -> FindHit { FindHit(kind: kind, id: id, title: "Synthetic", card: card.map { FindHit.Card(table: $0.0, id: $0.1) }) } func testEachHitIsACardOfTheRecordItStandsFor() { let items: [SearchItem] = [ .sectionLabel(key: "s", section: "todo", words: "Todos", count: 1), .hit(key: "1", hit: hit("todo", "t1", card: ("todo", "t1")), section: "todo", words: "Todos"), .hit(key: "2", hit: hit("message", "m1", card: ("thread", "th1")), section: "message", words: "Messages"), .hit(key: "3", hit: hit("message", "m2", card: ("thread", "th1")), section: "message", words: "Messages"), .hit(key: "4", hit: hit("photo", "p1", card: ("media", "p1")), section: "photo", words: "Photos"), .hit(key: "5", hit: hit("session_message", "sm1", card: nil), section: "session_message", words: "Bus"), .hit(key: "6", hit: hit("recipe", "r1", card: ("recipe", "r1")), section: "recipe", words: "Recipes"), ] let hits = SearchDeckHit.of(items) XCTAssertEqual(hits.map(\.id), ["todo|t1", "thread|th1", "media|p1", "recipe|r1"], "two messages of one conversation are its one card; a hit that stands for no record is no card") XCTAssertEqual(hits.last?.words, "Recipes", "a chip with no definition reads its section's words") }}