import BaseKit import Foundation import RastrilloApple import RastrilloSnapshots import RastrilloTestSupport import SwiftUI import XCTest /// Ask, drawn (Task 11): the approved mockups' thread (mac-main-b, /// phone-ask) on the Mac and the iPhone, the job view, and Ask's other /// states, in light and dark, and on iPhone at AX3. Fixed fixtures; no /// server. The window's bar and sidebar are Tasks 13 and 14's: the frame /// here is only enough to compare with the mockups. final class AskSnapshots: XCTestCase { @MainActor func testAsk() 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-ask", settings: SnapshotSettings(tint: LookSnapshots.tint), screens: [ SnapshotScreen("thread", mac: .fixed(width: 1000, height: 720), iphone: .fixed(width: 402, height: 874)) { AskFrame { AskView(model: AskFixtures.thread(), layout: frameLayout, timeZone: AskFixtures.zone, actions: AskActions {}) } }, SnapshotScreen("job-view", mac: .width(320), iphone: .width(402)) { JobView(job: AskFixtures.job, timeZone: AskFixtures.zone, close: {}, now: SnapshotSettings.now) }, // Review finding 9: many ended cards in the job view's real // bounds (the popover's 320 × 520; half the iPhone, the sheet's // medium detent): the details scroll, Close stays in reach. SnapshotScreen("job-view-long", mac: .fixed(width: 320, height: 520), iphone: .fixed(width: 402, height: 437)) { JobView(job: AskFixtures.longJob, timeZone: AskFixtures.zone, close: {}, now: SnapshotSettings.now) }, // Clearer paused work (2026-11-24): a paused job's pill (the // clock on indigo, "Paused until 21:00") beside a stopped one // (its square) and one working; and the paused job's view with // its sentence and Carry on now. SnapshotScreen("paused", mac: .fixed(width: 640, height: 360), iphone: .fixed(width: 402, height: 420)) { AskFrame { AskView(model: AskFixtures.paused(), layout: frameLayout, timeZone: AskFixtures.zone, actions: AskActions {}) } }, SnapshotScreen("job-view-paused", mac: .width(320), iphone: .width(402)) { JobView(job: AskFixtures.pausedJob, timeZone: AskFixtures.zone, close: {}, now: SnapshotSettings.now) }, // Fable's review S3: a failed Carry on now says so in the view. SnapshotScreen("job-view-paused-failed", mac: .width(320), iphone: .width(402)) { JobView(job: AskFixtures.pausedJob, timeZone: AskFixtures.zone, close: {}, now: SnapshotSettings.now, carryOnError: BaseText.text("ask.not_sent")) }, // The person's own words in the Assistant's little Markdown // (2026-11-26): bold, italics, a list with a link, lines kept; // and a plain message, exactly as written. SnapshotScreen("person-markdown", mac: .fixed(width: 640, height: 520), iphone: .fixed(width: 402, height: 620)) { AskFrame { AskView(model: AskFixtures.personMarkdown(), layout: frameLayout, timeZone: AskFixtures.zone, actions: AskActions {}) } }, SnapshotScreen("norunner", mac: .fixed(width: 640, height: 420), iphone: .fixed(width: 402, height: 520)) { AskFrame { AskView(model: AskFixtures.model(state: "norunner", extra: AskFixtures.shortThread), layout: frameLayout, timeZone: AskFixtures.zone, actions: AskActions {}) } }, SnapshotScreen("connect", mac: .fixed(width: 640, height: 300), iphone: .fixed(width: 402, height: 360)) { AskFrame { AskView(model: AskFixtures.model(state: "connect"), layout: frameLayout, timeZone: AskFixtures.zone, actions: AskActions {}) } }, SnapshotScreen("not-linked", mac: .fixed(width: 640, height: 300), iphone: .fixed(width: 402, height: 360)) { AskFrame { AskView(model: AskFixtures.notLinked(), layout: frameLayout, timeZone: AskFixtures.zone, actions: AskActions {}) } }, ]) } } let frameLayout: AskLayout = { #if os(macOS) .window #else .phone #endif }() /// The sky and the conversation's sheet, with its title bar, as the /// mockups frame Ask. struct AskFrame: View { @ViewBuilder let content: Content @Environment(\.colorScheme) private var scheme var body: some View { let p = Palette(scheme) ZStack { Sky() VStack(spacing: 0) { HStack(spacing: 9) { BaseMark(size: 16) Text(BaseText.text("native.sidebar.ask")).font(BaseFont.heading(17, .semibold)) Spacer() } .padding(.horizontal, 20).frame(height: 52) .overlay(alignment: .bottom) { Rectangle().fill(p[.rule]).frame(height: 1) } content.frame(maxWidth: 760) } .foregroundStyle(p[.frost]) .glassSheet(cornerRadius: 18) .padding(10) } .skyFrozen() } } @MainActor enum AskFixtures { static let zone = TimeZone(identifier: "Europe/Dublin")! static func model(state: String, extra: String = "") -> AskModel { let m = AskModel(client: BaseClient(transport: ScriptedTransport()) {}, schedule: { _, _ in }) let json = #"{"state":"\#(state)","messages":[\#(extra)],"jobs":[],"cards":[],"turn":null,"status":"","cursor":1,"equipo_origin":"https://equipo.fennel.example"}"# m.applyForPreview(try! JSONDecoder().decode(AskSnapshot.self, from: Data(json.utf8))) return m } static let shortThread = #"{"id":"m1","role":"person","text":"What's on tomorrow?","turn_id":"t1"}"# static func notLinked() -> AskModel { let m = model(state: "connect") m.show(.notLinked) return m } /// The mockups' thread: the bakery website on its way, a question on /// the Christmas order form, invoice reminders ready, and tomorrow's /// plan streaming in. static func thread() -> AskModel { let m = AskModel(client: BaseClient(transport: ScriptedTransport()) {}, schedule: { _, _ in }) let json = #""" {"state":"ready","cursor":40,"status":"","turn":null,"cards":[], "messages":[ {"id":"m1","role":"person","text":"Can you make us a website for the bakery? Use the menu in our Sheets.","turn_id":"t1"}, {"id":"m2","role":"assistant","text":"On it. You'll see a first look in a couple of minutes, with the menu from your Sheets.","turn_id":"t1"}], "jobs":[ {"id":"j1","revision":1,"kind":"job","state":"working","question":"Bakery website","result":"Building a first look","options":[],"links":[]}, {"id":"j2","revision":1,"kind":"job","state":"asking","question":"Christmas order form","result":"One question for you","options":[],"links":[], "cards":[{"id":"c1","revision":1,"kind":"question","state":"open","question":"When should Christmas orders close?","job":"j2", "options":[{"value":"fri","label":"Fri 18 Dec"},{"value":"tue","label":"Tue 22 Dec"},{"value":"else","label":"Something else"}],"links":[]}]}, {"id":"j3","revision":1,"kind":"job","state":"ready","question":"Invoice reminders","result":"Ready to try","options":[], "links":[{"label":"Try it","url":"https://fennel.base.example/apps/reminders"}]}]} """# m.applyForPreview(try! JSONDecoder().decode(AskSnapshot.self, from: Data(json.utf8))) m.apply(.message(AskMessage(id: "m3", role: "person", text: "What's on tomorrow?", turnID: "t2"))) m.apply(.delta(AskDelta(turnID: "t2", offset: 0, text: "Three things tomorrow:\n- 08:00 Flour delivery\n- 11:30 Ana, about the Christmas menu\n- 15:00 Call with the accountant\n"))) return m } /// Five jobs waiting on the person, each with a decision under it. static func manyWaiting() -> AskModel { let m = thread() for n in 1...5 { m.apply(.card(AskCard(id: "w\(n)", revision: 1, kind: "job", state: n % 2 == 0 ? "stopped" : "asking", question: "Waiting job \(n)", result: n % 2 == 0 ? "Stopped: needs you" : "One question for you"))) m.apply(.card(AskCard(id: "wc\(n)", revision: 1, kind: "confirm", state: "open", question: "Go ahead with job \(n)?", options: [.init(value: "yes", label: "Go ahead"), .init(value: "no", label: "Not yet")], job: "w\(n)"))) } return m } static func personMarkdown() -> AskModel { model(state: "ready", extra: #""" {"id":"m1","role":"person","text":"**Christmas menu** for the bakery, *draft two*:\n- Mince pies, [see the recipe](https://fennel.example/menu/pies)\n- **Stollen**\n\nAna signs it off\non Friday.","turn_id":"t1"}, {"id":"m2","role":"assistant","text":"Got it. I'll add **both** to the *Christmas* menu.","turn_id":"t1"}, {"id":"m3","role":"person","text":"Two lines,\n2*3 and a_b_c stay as typed.","turn_id":"t2"} """#) } /// A paused job that offers Carry on now, a stopped one and one working. static func paused() -> AskModel { let m = model(state: "ready", extra: #"{"id":"m1","role":"person","text":"Can you put together a simple website for the bakery?","turn_id":"t1"}"#) m.apply(.card(pausedJob.card)) m.apply(.card(AskCard(id: "j5", revision: 2, kind: "job", state: "stopped", question: "Invoice reminders", result: "Stopped: needs you"))) m.apply(.card(AskCard(id: "j6", revision: 1, kind: "job", state: "working", question: "Christmas menu", result: "Building a first look"))) return m } static let pausedJob = AskModel.Job( card: AskCard(id: "j4", revision: 3, kind: "job", state: "paused", question: "Bakery website", links: [.init(label: "Open in Equipo", url: URL(string: "https://equipo.fennel.example/tasks/tk4"), rel: "equipo")], result: "Paused until 21:00", detail: "It has reached the limit on its plan for now. It will carry on by itself at 21:00 (in 9 hours).", startedAt: SnapshotSettings.now.addingTimeInterval(-2 * 3600), carryOn: true)) static let longJob = AskModel.Job(card: job.card, open: [], ended: (1...6).map { n in AskCard(id: "e\(n)", kind: "confirm", state: "answered", question: "Decision \(n): use the autumn menu's prices for the Christmas boxes?", result: n % 2 == 0 ? "You said yes" : "You said no", job: "j2") }) static let job = AskModel.Job( card: AskCard(id: "j2", revision: 3, kind: "job", state: "asking", question: "Christmas order form", links: [.init(label: "Open in Equipo", url: URL(string: "https://equipo.fennel.example/tasks/tk2"), rel: "equipo")], result: "One question for you", detail: "The form is built and works. It needs a closing date before it goes on the website.", startedAt: SnapshotSettings.now.addingTimeInterval(-18 * 3600)), open: [], ended: [AskCard(id: "c0", kind: "confirm", state: "answered", question: "Use the autumn menu's prices?", result: "You said yes", job: "j2")]) }