SPB Git

Repository Public

ShellFeatureSectionsTests.swift 4.3 KB 68 lines swift

1// SP Notes iOS2// File: Tests/ShellFeatureSectionsTests.swift3// Description: The screens of SPNotesFeatures as the shell hosts them: which sections are registered, that none is listed4//              until the server is known to offer what it needs, the router handed to them, and the PencilKit bridge of the canvas.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import Foundation9import SPNotesCore10import SPNotesFeatures11import Testing12@testable import SPNotes1314@MainActor15@Suite("Sections hébergées de SPNotesFeatures") struct ShellFeatureSectionsTests {16    private func app() throws -> AppModel {17        let directory = FileManager.default.temporaryDirectory.appendingPathComponent("spnotes-features-\(UUID().uuidString)", isDirectory: true)18        return try AppModel(configuration: AppConfiguration(api: .production(appVersion: "tests"), dataDirectory: directory, inMemoryStore: true))19    }2021    @Test func nothingIsListedUntilTheServerIsKnownAndThenOnlyWhatItOffers() throws {22        let registry = HostedSectionRegistry()23        FeatureSections.install(in: registry, app: try app())24        #expect(registry.sections.count == 10)25        #expect(registry.available.isEmpty, "features never read: no section anywhere")26        registry.update(features: ServerMeta(api: 2, version: "2.4.0", features: []))27        #expect(registry.available.isEmpty, "a 2.x server has none of them")28        registry.update(features: ServerMeta(api: 3, version: "3.0.0", features: [ServerFeature.brief, ServerFeature.canvas]))29        #expect(registry.available.map(\.id) == [FeatureSectionID.brief, HostedSectionID.canvas])30        #expect(!registry.showsDatabases)31        let all = [ServerFeature.entities, ServerFeature.brief, ServerFeature.canvas, ServerFeature.graphV2, ServerFeature.events, ServerFeature.health, ServerFeature.nodesV3]32        registry.update(features: ServerMeta(api: 3, version: "3.0.0", features: all))33        #expect(registry.available.map(\.id) == [FeatureSectionID.brief, FeatureSectionID.ask, FeatureSectionID.search, HostedSectionID.databases, HostedSectionID.canvas,34                                                 FeatureSectionID.graph, FeatureSectionID.constellation, FeatureSectionID.timeline, FeatureSectionID.health, FeatureSectionID.research])35        #expect(registry.showsDatabases)36    }3738    @Test func theShellKeepsOneRouterAliveAndItIsAFeatureRouter() throws {39        let model = try app()40        let shell = ShellState(sections: HostedSectionRegistry())41        let router = shell.featureRouter(app: model)42        #expect(router === shell.featureRouter(app: model), "the screens hold it weakly: the shell owns it")43        let features: any FeatureRouter = router44        features.openPage(id: "0b7f6c0e-3f0a-4d5e-9b0a-111111111111", blockId: "blk1")45        #expect(shell.currentNote == "0b7f6c0e-3f0a-4d5e-9b0a-111111111111")46        #expect(shell.reveal(for: "0b7f6c0e-3f0a-4d5e-9b0a-111111111111")?.blockId == "blk1")47    }4849    @Test func theCanvasGetsTheInkAttachmentThePencilEditorSaved() {50        #expect(CanvasPencilBridge.result(for: nil) == nil)51        #expect(CanvasPencilBridge.result(for: DrawingBlock(background: "white").node()) == nil, "nothing drawn: the canvas keeps its card as it is")52        var block = DrawingBlock(background: "white")53        block.setInk(attachmentId: "11111111-1111-4111-8111-111111111111", preview: "22222222-2222-4222-8222-222222222222", width: 300, height: 200, pk: nil)54        #expect(CanvasPencilBridge.result(for: block.node())?.inkAttachmentId == "11111111-1111-4111-8111-111111111111")55        #expect(CanvasPencilBridge.result(for: MermaidBlock(code: "a").node()) == nil)56    }57}5859@Suite("Écrans SPNotesFeatures d’une note") struct NoteFeatureSheetTests {60    @Test func theyAreOfferedOnlyWhenTheServerHasThem() {61        #expect(!NoteFeatureSheet.offers(.ask, nil) && !NoteFeatureSheet.offers(.outline, nil) && !NoteFeatureSheet.offers(.timeline, nil))62        let legacy = ServerMeta(api: 2, version: "2.4.0", features: [])63        #expect(!NoteFeatureSheet.offers(.ask, legacy) && !NoteFeatureSheet.offers(.outline, legacy))64        let next = ServerMeta(api: 3, version: "3.0.0", features: [ServerFeature.zoom, ServerFeature.events])65        #expect(NoteFeatureSheet.offers(.outline, next) && NoteFeatureSheet.offers(.timeline, next) && !NoteFeatureSheet.offers(.ask, next))66    }67}68
Files main
Menu

Theme