| 1 | import BaseKit |
| 2 | import RastrilloApple |
| 3 | import Foundation |
| 4 | import RastrilloSnapshots |
| 5 | import SwiftUI |
| 6 | import XCTest |
| 7 | |
| 8 | /// Base's look for the screenshot gate (Task 9): the sky at its still pose, |
| 9 | /// the three surfaces over it, the type scale and the marks, in light and |
| 10 | /// dark (and on iPhone at AX3). `native/scripts/snapshots.sh` runs it; |
| 11 | /// `swift test` alone skips it, because baselines match only the OS that |
| 12 | /// drew them. The fonts are registered first, or the baselines would |
| 13 | /// record the system face. |
| 14 | final class LookSnapshots: XCTestCase { |
| 15 | @MainActor func testLook() async throws { |
| 16 | try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") |
| 17 | BaseFonts.register() |
| 18 | await assertSnapshots(of: Self.catalog) |
| 19 | await assertSnapshots(of: Self.typeCatalog) |
| 20 | } |
| 21 | |
| 22 | static let tint = OficinaPalette.accent(.base) |
| 23 | |
| 24 | @MainActor static var catalog: SnapshotCatalog { |
| 25 | // Nothing here holds text that grows: light and dark at the default |
| 26 | // size only (each picture of the sky is a few hundred kilobytes). |
| 27 | SnapshotCatalog(app: "base-look", variants: [.init(.light, .standard), .init(.dark, .standard)], |
| 28 | settings: SnapshotSettings(tint: tint), screens: [ |
| 29 | SnapshotScreen("sky", mac: .fixed(width: 640, height: 400), iphone: .fixed(width: 402, height: 874)) { |
| 30 | Sky().skyFrozen() |
| 31 | }, |
| 32 | SnapshotScreen("surfaces", mac: .fixed(width: 720, height: 420), iphone: .fixed(width: 402, height: 760)) { |
| 33 | ZStack { Sky(); SurfacesSample().padding(24) }.skyFrozen() |
| 34 | }, |
| 35 | SnapshotScreen("marks", mac: .fixed(width: 520, height: 160), iphone: .fixed(width: 402, height: 200)) { |
| 36 | ZStack { Sky(); MarksSample().padding(20) }.skyFrozen() |
| 37 | }, |
| 38 | ]) |
| 39 | } |
| 40 | |
| 41 | /// The type scale, at the accessibility size too. |
| 42 | @MainActor static var typeCatalog: SnapshotCatalog { |
| 43 | SnapshotCatalog(app: "base-type", settings: SnapshotSettings(tint: tint), screens: [ |
| 44 | SnapshotScreen("type", mac: .fixed(width: 640, height: 560), iphone: .width(402, minHeight: 700)) { |
| 45 | ZStack { Sky(); TypeSample().padding(20) }.skyFrozen() |
| 46 | }, |
| 47 | ]) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /// Fixture words: what each surface carries in the mockups. |
| 52 | struct SurfacesSample: View { |
| 53 | @Environment(\.colorScheme) private var scheme |
| 54 | var body: some View { |
| 55 | let p = Palette(scheme) |
| 56 | ViewThatFits(in: .horizontal) { |
| 57 | HStack(alignment: .top, spacing: 18) { cards(p) } |
| 58 | VStack(alignment: .leading, spacing: 18) { cards(p) } |
| 59 | } |
| 60 | .foregroundStyle(p[.frost]) |
| 61 | } |
| 62 | |
| 63 | @ViewBuilder func cards(_ p: Palette) -> some View { |
| 64 | card(title: "Glass", line: "The sidebar and the phone's buttons").glass(cornerRadius: 18) |
| 65 | card(title: "Sheet", line: "The conversation, the Settings window").glassSheet(cornerRadius: 18) |
| 66 | card(title: "Solid", line: "Menus and the job view").solid(cornerRadius: 16) |
| 67 | } |
| 68 | |
| 69 | func card(title: String, line: String) -> some View { |
| 70 | VStack(alignment: .leading, spacing: 6) { |
| 71 | Text(verbatim: title).font(BaseFont.heading(17)) |
| 72 | Text(verbatim: line).font(BaseFont.body(14)).foregroundStyle(Palette(scheme)[.haze]) |
| 73 | } |
| 74 | .padding(16) |
| 75 | .frame(width: 200, alignment: .leading) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | struct TypeSample: View { |
| 80 | @Environment(\.colorScheme) private var scheme |
| 81 | var body: some View { |
| 82 | let p = Palette(scheme) |
| 83 | VStack(alignment: .leading, spacing: 10) { |
| 84 | HStack(spacing: 9) { BaseMark(size: 18); Text(verbatim: "Base").font(BaseFont.heading(24)) } |
| 85 | Text(verbatim: "Sign in to Base").font(BaseFont.heading(30, .medium, relativeTo: .largeTitle)) |
| 86 | Text(verbatim: "Ask Base").font(BaseFont.heading(20, .medium, relativeTo: .title3)) |
| 87 | Text(verbatim: "Christmas order form").font(BaseFont.heading(16, .semibold, relativeTo: .headline)) |
| 88 | Text(verbatim: "Use your Oficina ID, the same one as Docs, Sheets and Calls.").font(BaseFont.body(17)) |
| 89 | Text(verbatim: "On it. You'll see a first look in a couple of minutes, with the menu from your Sheets.").font(BaseFont.body(15)) |
| 90 | Text(verbatim: "Bakery website · Building a first look").font(BaseFont.body(13.5, .semibold, relativeTo: .subheadline)) |
| 91 | Text(verbatim: "Started 5 minutes ago").font(BaseFont.body(13, relativeTo: .footnote)).foregroundStyle(p[.haze]) |
| 92 | } |
| 93 | .foregroundStyle(p[.frost]) |
| 94 | .padding(20) |
| 95 | .frame(maxWidth: .infinity, alignment: .leading) |
| 96 | .glassSheet(cornerRadius: 18) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | struct MarksSample: View { |
| 101 | var body: some View { |
| 102 | HStack(spacing: 14) { |
| 103 | BaseMark(size: 18) |
| 104 | ForEach(JobState.allCases, id: \.self) { StateMark($0) } |
| 105 | } |
| 106 | .padding(16) |
| 107 | .glass(cornerRadius: 999) |
| 108 | } |
| 109 | } |
| 110 | |