#if canImport(UIKit) import CottonValues import ImageIO import SwiftUI import UniformTypeIdentifiers import XCTest @testable import CottonUI /// A capture utility, not a guard: with `HOUSE_A_OUT=` set (through /// xcodebuild, `TEST_RUNNER_HOUSE_A_OUT`) it draws the birthday face on the /// numbers of the house references (a photo, a round portrait, a yearless /// day) — each on its stock, a 360 x 450 card at scale 3 — into /// ``, to be laid beside the references. Every name is invented; the /// portraits are the gallery's own. Without the out variable it skips. @MainActor final class HouseTodoBirthdayShotsTests: XCTestCase { func testDrawTheTodoAndBirthdayReferences() throws { guard let dir = ProcessInfo.processInfo.environment["HOUSE_A_OUT"], !dir.isEmpty else { throw XCTSkip("set HOUSE_A_OUT= to draw the birthday references") } let out = URL(fileURLWithPath: dir, isDirectory: true) try FileManager.default.createDirectory(at: out, withIntermediateDirectories: true) let ananya = DeckCard(face: .birthday, corner: "Birthday in 3 days", fields: [ "title": .text("Ananya Rao"), "subtitle": .text("Bengaluru"), "date": .text("Mon 26 Oct"), "turns": .text("turns 30"), "wishes": .bool(true), ]) let ravi = DeckCard(face: .birthday, fields: [ "title": .text("Ravi Menon"), "date": .text("Thu 29 Oct"), "turns": .text("turns 52"), "wishes": .bool(true), "last_wished": .text("Wed 29 Oct 2025"), ]) let kiran = DeckCard(face: .birthday, fields: [ "title": .text("Kiran"), "date": .text("Sat 14 Nov"), "wishes": .bool(false), "last_wished": .text("Fri 14 Nov 2025"), ]) shoot("birthday-photo", ananya, BirthdayFace(card: ananya, photo: GalleryFaces.picture("guest-0")), to: out) shoot("birthday-round", ravi, BirthdayFace(card: ravi, photo: GalleryFaces.picture("guest-1")), to: out) shoot("birthday-yearless", kiran, BirthdayFace(card: kiran, photo: nil), to: out) } private func shoot(_ name: String, _ card: DeckCard, _ face: some View, to out: URL) { let theme = Theme.paper let renderer = ImageRenderer(content: face .environment(\.theme, theme) .environment(\.colorScheme, .light) .frame(width: 360, height: 450) .background(theme.colors.paper.color)) renderer.scale = 3 guard let 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