importImageIOimportSwiftUIimportUniformTypeIdentifiersimport XCTest@testable importCottonUI/// A capture utility, not a guard: with `COTTON_FACE_SHOTS=<dir>` set (through/// xcodebuild, `TEST_RUNNER_COTTON_FACE_SHOTS`) it draws the gallery's deck/// specimens — each face on its stock at the deck's card size, as the deck/// lays the front card — into `<dir>` as PNGs at the phone's scale, so a face/// is looked at before it ships. Without the variable it skips.@MainActorfinalclassFaceShotsTests: XCTestCase {func testDrawTheDeckSpecimens() throws {guardlet dir = ProcessInfo.processInfo.environment["COTTON_FACE_SHOTS"], !dir.isEmpty else {throw XCTSkip("set COTTON_FACE_SHOTS=<dir> to draw the specimens") }let out = URL(fileURLWithPath: dir, isDirectory: true)tryFileManager.default.createDirectory(at: out, withIntermediateDirectories: true)let faces = GalleryFaces.self shoot("session", faces.sessionCards, to: out) shoot("session-tasks", faces.stage(faces.card, SessionFaceCatalogue.runningSession) {SessionFace(card: SessionFaceCatalogue.runningSession, pages: faces.runningTasks, opened: 1) }, to: out) shoot("memory", faces.memoryCards, to: out) shoot("mood", faces.moodCards, to: out) shoot("meeting", faces.meetingCards, to: out) }privatefunc shoot(_ name: String, _ view: someView, to out: URL) {let renderer = ImageRenderer(content: view .environment(\.colorScheme, .light) .frame(width: 393) .background(Color(white: 0.93))) renderer.scale = 2guardlet 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") }}