import BaseKit import Foundation import RastrilloApple import RastrilloSnapshots import SwiftUI import XCTest #if os(macOS) /// The Mac app (Task 13): window B, the menu-bar panel and Settings' three /// tabs, light and dark, from fixtures (mockups mac-main-b, mac-menubar, /// mac-settings). final class MacSnapshots: XCTestCase { @MainActor func testMac() async throws { try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") BaseFonts.register() await assertSnapshots(of: Self.catalog) } @MainActor static var catalog: SnapshotCatalog { SnapshotCatalog(app: "base-mac", settings: SnapshotSettings(tint: LookSnapshots.tint), screens: [ SnapshotScreen("window", mac: .fixed(width: 1280, height: 800), iphone: nil) { MacMainView(me: HomeFixtures.me, home: HomeFixtures.home, ask: AskFixtures.thread(), transport: nil, actions: .none, sidebarShown: .constant(true)).skyFrozen() }, SnapshotScreen("menubar", mac: .fixed(width: 410, height: 560), iphone: nil) { MenuPanel(me: HomeFixtures.me, ask: AskFixtures.thread(), shortcut: "⌃Space", openBase: {}, actions: .none).skyFrozen() }, // Astra's Task 16 finding 6: many jobs waiting, in the panel's // fixed size: they scroll in their own region; the header, the // conversation, the composer and the foot stay. SnapshotScreen("menubar-many", mac: .fixed(width: 410, height: 560), iphone: nil) { MenuPanel(me: HomeFixtures.me, ask: AskFixtures.manyWaiting(), shortcut: "⌃Space", openBase: {}, actions: .none).skyFrozen() }, SnapshotScreen("settings-general", mac: .width(560), iphone: nil) { settings(.general) }, SnapshotScreen("settings-account", mac: .width(560), iphone: nil) { settings(.account) }, SnapshotScreen("settings-ask", mac: .width(560), iphone: nil) { settings(.ask) }, ]) } @MainActor static func settings(_ tab: MacSettingsView.Tab) -> some View { MacSettingsView(model: .init(me: HomeFixtures.me, identity: "paul@fennel.example", askPhase: .ready, installed: ["Docs", "Sheets", "Calls"], shortcutSet: false), showMenuBar: .constant(true), openAtLogin: .constant(false), openIn: .constant(.app), tab: tab, tabBar: false, setAppearance: { _ in }, disconnect: {}, actions: .none) { EmptyView() } .skyFrozen() } } #endif /// Home and the member as the mockups show them: Fennel & Rye's Base. @MainActor enum HomeFixtures { static let me = Me(member: .init(id: "mb1", name: "Paul Campbell", email: "paul@fennel.example", initials: "PC", owner: true), base: .init(name: "Fennel & Rye", slug: "fennel", origin: URL(string: "https://fennel.base.example"), timezone: "Europe/Dublin")) static let home: HomeData = { let people = #""# let store = #""# let settings = #""# let spark = #""# let note = #""# func oficina(_ id: String, _ name: String) -> String { #"{"id":"\#(id)","kind":"oficina","name":"\#(name)","url":"https://fennel.\#(id).oficina.works/","icon_url":"/static/oficina/\#(id).svg","bundle_id":"works.oficina.\#(id)"}"# } let json = """ {"greeting":"Good morning, Paul","lede":"","steps":[{"label":"Signed in","done":true},{"label":"Invite your team","done":true},{"label":"Install your first app","done":false}], "apps":[\(oficina("calendar", "Calendar")),\(oficina("docs", "Docs")),\(oficina("sheets", "Sheets")),\(oficina("memoria", "Memoria")),\(oficina("calls", "Calls")),\(oficina("equipo", "Equipo")), {"id":"welcome","kind":"installed","name":"Welcome","url":"https://welcome.fennel.example/","tint":"amber","icon_svg":"\(spark)"}, {"id":"scratchpad","kind":"installed","name":"Scratchpad","url":"https://scratchpad.fennel.example/","tint":"rose","icon_svg":"\(note)"}, {"id":"store","kind":"own","name":"Store","url":"https://fennel.base.example/store","tint":"teal","icon_svg":"\(store)"}, {"id":"people","kind":"own","name":"People","url":"https://fennel.base.example/people","tint":"violet","icon_svg":"\(people)"}, {"id":"settings","kind":"own","name":"Settings","url":"https://fennel.base.example/settings","tint":"mist","icon_svg":"\(settings)"}]} """ return try! JSONDecoder().decode(HomeData.self, from: Data(json.utf8)) }() } /// The iPhone app (Task 14): Ask first, the Apps sheet and the job sheet, /// light and dark, at the default size and AX3 (mockups phone-ask, /// phone-apps, phone-job). final class PhoneSnapshots: XCTestCase { @MainActor func testPhone() async throws { try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") BaseFonts.register() await assertSnapshots(of: Self.catalog) } @MainActor static var catalog: SnapshotCatalog { SnapshotCatalog(app: "base-phone", settings: SnapshotSettings(tint: LookSnapshots.tint), screens: [ SnapshotScreen("ask", mac: nil, iphone: .fixed(width: 402, height: 874)) { PhoneAskScreen(me: HomeFixtures.me, home: HomeFixtures.home, ask: AskFixtures.thread(), transport: nil, actions: .none).skyFrozen() }, SnapshotScreen("apps", mac: nil, iphone: .width(402)) { AppsSheet(me: HomeFixtures.me, home: HomeFixtures.home, transport: nil, actions: .none) {}.skyFrozen() }, SnapshotScreen("job", mac: nil, iphone: .fixed(width: 402, height: 437)) { JobView(job: AskFixtures.job, timeZone: AskFixtures.zone, close: {}, now: SnapshotSettings.now) }, ]) } }