#if canImport(UIKit)importCottonValuesimportImageIOimportSwiftUIimportUniformTypeIdentifiersimport XCTest@testable importCottonUI/// A capture utility, not a guard: with `EMAIL_THREAD_OUT=<dir>` set (through/// xcodebuild, `TEST_RUNNER_EMAIL_THREAD_OUT`) it draws the email face on the/// numbers of the house references (email 39, 75, 74, 40) — each on its/// stock, a 360 x 450 card at scale 3 — into `<dir>`, so they are laid/// beside the references. Each card carries only what the core's card block/// sends for an email (subject, sender, preview, day, count, unread, amount,/// people); every name is invented and a person's picture is the gallery's/// own. Without the out/// variable it skips.@MainActorfinalclassEmailThreadShotsTests: XCTestCase {privatestaticfunc person(_ name: String, _ picture: String?) -> RecordValue {var entry: [String: RecordValue] = ["name": .text(name)]iflet picture { entry["picture"] = .text(picture) }return .object(entry) }func testDrawTheEmailAndThreadReferences() throws {guardlet dir = ProcessInfo.processInfo.environment["EMAIL_THREAD_OUT"], !dir.isEmpty else {throw XCTSkip("set EMAIL_THREAD_OUT=<dir> to draw the email and thread references") }let out = URL(fileURLWithPath: dir, isDirectory: true)tryFileManager.default.createDirectory(at: out, withIntermediateDirectories: true)let emails: [(String, DeckCard)] = [ ("email-39", DeckCard(face: .email, fields: ["subtitle": .text("Priya at Example Broking"), "title": .text("Your contract note for 22 Oct"),"date": .text("Thu 22 Oct"), "count": .text("3"), "unread": .bool(true),"body": .text("Your contract note is ready.\nPlease find the details attached.\nThank you for trading with us."), ])), ("email-75", DeckCard(face: .email, fields: ["subtitle": .text("Studio Iyer"), "title": .text("Coorg homestay drawings revision 3"),"date": .text("Thu 22 Oct"), "count": .text("14"),"body": .text("Please find the revised drawings for the Coorg homestay attached. Revision 3 is ready for review.\n\nThe verandah is wider now, and the stair moves to the east wall so the kitchen keeps its window. Tell us what you think before Friday and we will send the final set to the builder."),"people": .list([Self.person("Meera Iyer", "guest-2"), Self.person("Arjun Rao", "guest-1")]), ])), ("email-74", DeckCard(face: .email, fields: ["subtitle": .text("Offers at Some Shop"), "title": .text("70 percent off today only"),"date": .text("Thu 22 Oct"), "count": .text("3"),"body": .text("Save 70 percent on your favourites.\nToday only, shop before midnight.\nDiscover our latest offers in store."), ])), ("email-40", DeckCard(face: .email, fields: ["subtitle": .text("Example Airways"), "title": .text("Boarding pass BLR to DEL"),"date": .text("Fri 23 Oct"), "count": .text("1"), "amount": .text("\u{20B9}6,480"),"body": .text("Your boarding pass is ready.\nHave a pleasant flight."), ])), ]for (name, card) in emails { shoot(name, card, EmailFace(card: card, picture: Optional<EmptyView>.none), to: out) } }privatefunc shoot(_ name: String, _ card: DeckCard, _ face: someView, to out: URL) {let theme = Theme.paperlet renderer = ImageRenderer(content: face .environment(\.theme, theme) .environment(\.colorScheme, .light) .environment(\.facePictureDrawer, DeckFace.pictures) .environment(\.facePictures) { FixturePictures.image($0) } .frame(width: 360, height: 450) .background(theme.colors.paper.color)) renderer.scale = 3guardlet image = renderer.cgImage,let dest = CGImageDestinationCreateWithURL(out.appendingPathComponent("\(name).png") as CFURL, UTType.png.identifier as CFString, 1, nil)else { return XCTFail("\(name) drew nothing") } CGImageDestinationAddImage(dest, image, nil) XCTAssertTrue(CGImageDestinationFinalize(dest), "\(name) was not written") }}#endif