// A contact by the desk telephone: the name and the picture the core's and // tagged; the first number the person is reached at, else the phone place's; // the handset tagged as the call and the camera key as the video call, each // saying itself; the card lies bare on the calling desk's leather and is // stepped by a cut. @testable import CottonFaces import CottonPaper import CottonValues import SwiftUI import XCTest @MainActor final class PersonTelephoneTests: XCTestCase { typealias Catalogue = PersonTelephoneFaceCatalogue /// RULE: The card types the first number the person is reached at, else the phone place's first, else none; their initials stand where they have no picture. func testTheCardSaysTheFirstNumber() { XCTAssertEqual(PersonTelephoneWords(Catalogue.colleague).number, "+1 555 0121") XCTAssertNil(PersonTelephoneWords(Catalogue.noNumber).number) var slot = DeckCard(face: "person.telephone", corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text("Ravi Iyer"), "phone": .text("+1 555 0177")]) XCTAssertEqual(PersonTelephoneWords(slot).number, "+1 555 0177") slot.reach = CardReach(phones: [" ", "+1 555 0178"]) XCTAssertEqual(PersonTelephoneWords(slot).number, "+1 555 0178") XCTAssertEqual(PersonTelephoneWords(Catalogue.noPicture).initials, "DK") } /// RULE: The handset is the call and the camera key the video call, tagged whether or not the person has a number (a Cotton call goes to the person); the name and the picture are tagged too. func testTheHandsetCallsAndTheCameraKeyCallsWithVideo() { XCTAssertEqual(tagged(Catalogue.friend, picture: true), [.picture, .title, .call, .videoCall]) XCTAssertEqual(tagged(Catalogue.noNumber, picture: false), [.picture, .title, .call, .videoCall]) } /// RULE: The call and the video call say themselves in the cards set's words, never their paths. func testThePartsSayThemselves() { XCTAssertEqual(ShellLines.line("cards", "faces.call"), "Call") XCTAssertEqual(ShellLines.line("cards", "faces.video_call"), "Video call") } /// RULE: The camera key lies on the painting's third line key and the handset over its cradle, both inside the painting. func testThePartsLieOnThePainting() { let knobs = PersonTelephoneFaceKnobs.self let unit = CGRect(x: 0, y: 0, width: 1, height: 1) XCTAssertTrue(unit.contains(knobs.handset)) let key = knobs.cameraKey.outline(in: CGSize(width: 1, height: 1)).boundingRect XCTAssertTrue(unit.contains(key)) XCTAssertLessThan(knobs.handset.maxY, key.minY, "the handset stands above the keys") XCTAssertNotNil(CottonMedia.image("telephone", scale: 3)) } /// RULE: The card lies bare on the calling desk's oxblood leather, draws its own card, and is stepped by a cut. func testTheCardLiesOnTheLeatherAndCuts() { XCTAssertEqual(FaceRegistry.ground("person.telephone"), .leatherDesk) XCTAssertEqual(FaceRegistry.stock("person.telephone"), .own) XCTAssertEqual(Catalogue.face.steps, .cut) XCTAssertEqual(Catalogue.face.specimens.map(\.name), ["friend", "colleague", "no-picture", "long-name", "no-number"]) } private func tagged(_ card: DeckCard, picture: Bool) -> Set { final class Tagged { var parts: Set = [] } let tagged = Tagged() let drawn = PersonTelephoneFace(card: card, photo: picture ? FacePicture(key: "rolodex-friend", edge: 120) : nil) .frame(width: 340, height: 451) .backgroundPreferenceValue(FacePartsKey.self) { regions in let _ = tagged.parts.formUnion(regions.map(\.part)) Color.clear } XCTAssertNotNil(ImageRenderer(content: drawn).cgImage) return tagged.parts } }