SPB Git

Repository Public

KnowledgeSnapshotTests.swift 6.0 KB 113 lines swift

1// SP Notes Core2// File: Tests/SPNotesFeaturesTests/KnowledgeSnapshotTests.swift3// Description: Hosted renders of the knowledge screens (graph, constellation, timeline, time machine, health, brief,4//              semantic zoom) in light / dark × compact / regular, from loaded view models over the fake backend.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8#if os(macOS)9import Foundation10import SPNotesAPI11import SPNotesSync12import SwiftUI13import Testing14@testable import SPNotesFeatures15@testable import SPNotesFeaturesCatalog1617@Suite("Knowledge: snapshots", .serialized)18@MainActor19struct KnowledgeSnapshotTests {20    @Test("graph: global view, a selection, the insights panel, the relation form, offline")21    func graph() async throws {22        let world = try await FeatureWorld()23        let model = GraphModel(repositories: world.repositories)24        await model.load()25        await model.loadInsights()26        Snapshot.render("graph") { GraphScreen(model: model) }27        model.select(nodeId: model.nodes.first?.id)28        Snapshot.render("graph-selected") { GraphScreen(model: model) }29        Snapshot.render("graph-insights") { GraphScreen(model: model, showsInsights: true) }30        model.beginRelation(from: try #require(model.nodes.first), to: model.nodes.last)31        model.form?.note = "Les deux notes partagent la même hypothèse."32        Snapshot.render("graph-relation-form", compactSize: CGSize(width: 390, height: 560), regularSize: CGSize(width: 420, height: 520)) {33            ScrollView { GraphRelationFormView(model: model).padding(16) }34        }35        model.form = nil36        await model.setView(GraphView.timeline)37        Snapshot.render("graph-timeline") { GraphScreen(model: model) }38        await model.setView(GraphView.global)39        world.setOffline(true)40        await model.load()41        _ = await model.accept(try #require(model.edges.first(where: GraphModel.isDecidable)))42        Snapshot.render("graph-offline") { GraphScreen(model: model) }43    }4445    @Test("constellation: server projection and local layout")46    func constellation() async throws {47        let world = try await FeatureWorld()48        let server = ConstellationModel(repositories: world.repositories, projection: FeatureCatalog.sampleConstellationSource(world))49        await server.load()50        server.select(server.map?.stars.first?.id)51        Snapshot.render("constellation-server") { ConstellationScreen(model: server) }52        let local = ConstellationModel(repositories: world.repositories)53        await local.load()54        Snapshot.render("constellation-local") { ConstellationScreen(model: local) }55    }5657    @Test("timeline: the journal, the time machine, the restore confirmation, the empty journal")58    func timeline() async throws {59        let world = try await FeatureWorld()60        let utc = TimeZone(identifier: "UTC")!61        let model = TimelineModel(repositories: world.repositories, timeZone: utc)62        await model.load()63        Snapshot.render("timeline") { TimelineScreen(model: model) }64        let machine = TimeMachineModel(repositories: world.repositories, scope: .page(KnowledgeSamples.timePageId), date: KnowledgeSamples.timeMachineDate,65                                       now: { FeatureSamples.now.addingTimeInterval(86_400) })66        await machine.load()67        let page = TimelineModel(repositories: world.repositories, scope: .page(KnowledgeSamples.timePageId), timeZone: utc)68        await page.load()69        Snapshot.render("timemachine") { TimelineScreen(model: page, timeMachine: machine, showsTimeMachine: true) }70        machine.requestRestore(try #require(machine.snapshot?.pages.first))71        Snapshot.render("timemachine-confirm") { TimelineScreen(model: page, timeMachine: machine, showsTimeMachine: true) }72        let empty = try await FeatureWorld(samples: false)73        empty.fake.stub("GET", path: "^/api/events$", json: #"{"events":[],"nextCursor":null}"#)74        let none = TimelineModel(repositories: empty.repositories, timeZone: utc)75        await none.load()76        Snapshot.render("timeline-empty") { TimelineScreen(model: none) }77    }7879    @Test("health and brief (before and after the explicit AI summary), offline with nothing cached")80    func healthAndBrief() async throws {81        let world = try await FeatureWorld()82        let health = KnowledgeHealthModel(repositories: world.repositories)83        await health.load()84        Snapshot.render("health") { KnowledgeHealthScreen(model: health) }85        let brief = DailyBriefModel(repositories: world.repositories)86        await brief.load()87        Snapshot.render("brief") { DailyBriefScreen(model: brief) }88        _ = await brief.requestSummary()89        Snapshot.render("brief-summary") { DailyBriefScreen(model: brief) }90        let cold = try await FeatureWorld(samples: false)91        cold.setOffline(true)92        let offline = KnowledgeHealthModel(repositories: cold.repositories)93        await offline.load()94        Snapshot.render("health-offline-empty") { KnowledgeHealthScreen(model: offline) }95    }9697    @Test("semantic zoom: outline, missing synopsis, generated synopsis")98    func zoom() async throws {99        let world = try await FeatureWorld()100        let router = FeatureRouterRecorder()101        let size = CGSize(width: 760, height: 560)102        let outline = SemanticZoomModel(repositories: world.repositories, router: router, pageId: KnowledgeSamples.zoomPageId)103        await outline.load()104        Snapshot.render("zoom-outline", regularSize: size) { PageOutlineView(model: outline) { PageOutlineOpenButton {} } }105        let synopsis = SemanticZoomModel(repositories: world.repositories, router: router, pageId: KnowledgeSamples.synopsisPageId, level: .synopsis)106        await synopsis.load()107        Snapshot.render("zoom-synopsis-missing", regularSize: size) { PageOutlineView(model: synopsis) { PageOutlineOpenButton {} } }108        _ = await synopsis.generateSynopsis()109        Snapshot.render("zoom-synopsis", regularSize: size) { PageOutlineView(model: synopsis) { PageOutlineOpenButton {} } }110    }111}112#endif113
Files main
Menu

Theme