| 1 | import BaseKit |
| 2 | import Foundation |
| 3 | import RastrilloApple |
| 4 | import RastrilloSnapshots |
| 5 | import SwiftUI |
| 6 | import XCTest |
| 7 | |
| 8 | #if os(macOS) |
| 9 | /// The Mac app (Task 13): window B, the menu-bar panel and Settings' three |
| 10 | /// tabs, light and dark, from fixtures (mockups mac-main-b, mac-menubar, |
| 11 | /// mac-settings). |
| 12 | final class MacSnapshots: XCTestCase { |
| 13 | @MainActor func testMac() async throws { |
| 14 | try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") |
| 15 | BaseFonts.register() |
| 16 | await assertSnapshots(of: Self.catalog) |
| 17 | } |
| 18 | |
| 19 | @MainActor static var catalog: SnapshotCatalog { |
| 20 | SnapshotCatalog(app: "base-mac", settings: SnapshotSettings(tint: LookSnapshots.tint), screens: [ |
| 21 | SnapshotScreen("window", mac: .fixed(width: 1280, height: 800), iphone: nil) { |
| 22 | MacMainView(me: HomeFixtures.me, home: HomeFixtures.home, ask: AskFixtures.thread(), transport: nil, |
| 23 | actions: .none, sidebarShown: .constant(true)).skyFrozen() |
| 24 | }, |
| 25 | SnapshotScreen("menubar", mac: .fixed(width: 410, height: 560), iphone: nil) { |
| 26 | MenuPanel(me: HomeFixtures.me, ask: AskFixtures.thread(), shortcut: "⌃Space", openBase: {}, actions: .none).skyFrozen() |
| 27 | }, |
| 28 | // Astra's Task 16 finding 6: many jobs waiting, in the panel's |
| 29 | // fixed size: they scroll in their own region; the header, the |
| 30 | // conversation, the composer and the foot stay. |
| 31 | SnapshotScreen("menubar-many", mac: .fixed(width: 410, height: 560), iphone: nil) { |
| 32 | MenuPanel(me: HomeFixtures.me, ask: AskFixtures.manyWaiting(), shortcut: "⌃Space", openBase: {}, actions: .none).skyFrozen() |
| 33 | }, |
| 34 | SnapshotScreen("settings-general", mac: .width(560), iphone: nil) { settings(.general) }, |
| 35 | SnapshotScreen("settings-account", mac: .width(560), iphone: nil) { settings(.account) }, |
| 36 | SnapshotScreen("settings-ask", mac: .width(560), iphone: nil) { settings(.ask) }, |
| 37 | ]) |
| 38 | } |
| 39 | |
| 40 | @MainActor static func settings(_ tab: MacSettingsView<EmptyView>.Tab) -> some View { |
| 41 | MacSettingsView(model: .init(me: HomeFixtures.me, identity: "paul@fennel.example", askPhase: .ready, |
| 42 | installed: ["Docs", "Sheets", "Calls"], shortcutSet: false), |
| 43 | showMenuBar: .constant(true), openAtLogin: .constant(false), openIn: .constant(.app), tab: tab, tabBar: false, |
| 44 | setAppearance: { _ in }, disconnect: {}, actions: .none) { EmptyView() } |
| 45 | .skyFrozen() |
| 46 | } |
| 47 | } |
| 48 | #endif |
| 49 | |
| 50 | /// Home and the member as the mockups show them: Fennel & Rye's Base. |
| 51 | @MainActor enum HomeFixtures { |
| 52 | static let me = Me(member: .init(id: "mb1", name: "Paul Campbell", email: "paul@fennel.example", initials: "PC", owner: true), |
| 53 | base: .init(name: "Fennel & Rye", slug: "fennel", origin: URL(string: "https://fennel.base.example"), timezone: "Europe/Dublin")) |
| 54 | |
| 55 | static let home: HomeData = { |
| 56 | let people = #"<svg viewBox=\"0 0 24 24\"><circle cx=\"9\" cy=\"9\" r=\"3\"/><circle cx=\"16.5\" cy=\"10.5\" r=\"2.5\"/><path d=\"M3.5 19a5.5 5.5 0 0 1 11 0M14 19a4 4 0 0 1 7 0\"/></svg>"# |
| 57 | let store = #"<svg viewBox=\"0 0 24 24\"><path d=\"M5 8h14l-1.2 11.2a1 1 0 0 1-1 .8H7.2a1 1 0 0 1-1-.8z\"/><path d=\"M9 8V6.5a3 3 0 0 1 6 0V8\"/></svg>"# |
| 58 | let settings = #"<svg viewBox=\"0 0 24 24\"><path d=\"M4 7h10M18 7h2M4 17h2M10 17h10\"/><circle cx=\"16\" cy=\"7\" r=\"2\"/><circle cx=\"8\" cy=\"17\" r=\"2\"/></svg>"# |
| 59 | let spark = #"<svg viewBox=\"0 0 24 24\"><path d=\"M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M5.6 18.4l2.8-2.8M15.6 8.4l2.8-2.8\"/></svg>"# |
| 60 | let note = #"<svg viewBox=\"0 0 24 24\"><path d=\"M6 3h9l4 4v14H6z\"/><path d=\"M9 12h7M9 16h5\"/></svg>"# |
| 61 | func oficina(_ id: String, _ name: String) -> String { |
| 62 | #"{"id":"\#(id)","kind":"oficina","name":"\#(name)","url":"https://fennel.\#(id).oficina.works/","icon_url":"/static/oficina/\#(id).svg","bundle_id":"works.oficina.\#(id)"}"# |
| 63 | } |
| 64 | let json = """ |
| 65 | {"greeting":"Good morning, Paul","lede":"","steps":[{"label":"Signed in","done":true},{"label":"Invite your team","done":true},{"label":"Install your first app","done":false}], |
| 66 | "apps":[\(oficina("calendar", "Calendar")),\(oficina("docs", "Docs")),\(oficina("sheets", "Sheets")),\(oficina("memoria", "Memoria")),\(oficina("calls", "Calls")),\(oficina("equipo", "Equipo")), |
| 67 | {"id":"welcome","kind":"installed","name":"Welcome","url":"https://welcome.fennel.example/","tint":"amber","icon_svg":"\(spark)"}, |
| 68 | {"id":"scratchpad","kind":"installed","name":"Scratchpad","url":"https://scratchpad.fennel.example/","tint":"rose","icon_svg":"\(note)"}, |
| 69 | {"id":"store","kind":"own","name":"Store","url":"https://fennel.base.example/store","tint":"teal","icon_svg":"\(store)"}, |
| 70 | {"id":"people","kind":"own","name":"People","url":"https://fennel.base.example/people","tint":"violet","icon_svg":"\(people)"}, |
| 71 | {"id":"settings","kind":"own","name":"Settings","url":"https://fennel.base.example/settings","tint":"mist","icon_svg":"\(settings)"}]} |
| 72 | """ |
| 73 | return try! JSONDecoder().decode(HomeData.self, from: Data(json.utf8)) |
| 74 | }() |
| 75 | } |
| 76 | |
| 77 | /// The iPhone app (Task 14): Ask first, the Apps sheet and the job sheet, |
| 78 | /// light and dark, at the default size and AX3 (mockups phone-ask, |
| 79 | /// phone-apps, phone-job). |
| 80 | final class PhoneSnapshots: XCTestCase { |
| 81 | @MainActor func testPhone() async throws { |
| 82 | try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") |
| 83 | BaseFonts.register() |
| 84 | await assertSnapshots(of: Self.catalog) |
| 85 | } |
| 86 | |
| 87 | @MainActor static var catalog: SnapshotCatalog { |
| 88 | SnapshotCatalog(app: "base-phone", settings: SnapshotSettings(tint: LookSnapshots.tint), screens: [ |
| 89 | SnapshotScreen("ask", mac: nil, iphone: .fixed(width: 402, height: 874)) { |
| 90 | PhoneAskScreen(me: HomeFixtures.me, home: HomeFixtures.home, ask: AskFixtures.thread(), transport: nil, actions: .none).skyFrozen() |
| 91 | }, |
| 92 | SnapshotScreen("apps", mac: nil, iphone: .width(402)) { |
| 93 | AppsSheet(me: HomeFixtures.me, home: HomeFixtures.home, transport: nil, actions: .none) {}.skyFrozen() |
| 94 | }, |
| 95 | SnapshotScreen("job", mac: nil, iphone: .fixed(width: 402, height: 437)) { |
| 96 | JobView(job: AskFixtures.job, timeZone: AskFixtures.zone, close: {}, now: SnapshotSettings.now) |
| 97 | }, |
| 98 | ]) |
| 99 | } |
| 100 | } |
| 101 | |