// // OnboardPathEnvironmentKeyTests.swift // // Copyright 2026 Brendan Szymanski // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // SPDX-License-Identifier: GPL-3.0-or-later // @_spi(SGTKInternal) import Gtk import LuminateCore @_spi(Portico) import Portico import Testing @testable import LuminateOnboarding /// Captures the binding a mounted page resolves, so a test can push through it after mount. @MainActor private final class PathCapture { var path: Portico.Binding<[OnboardDestination]>? } /// Stands in for an onboarding page that pushes through the injected path. private struct PathProbe: View { @Environment(\.onboardPath) private var onboardPath let capture: PathCapture var body: some View { capture.path = onboardPath return Label(str: "probe") } } /// Covers `OnboardPathEnvironmentKey`/`EnvironmentValues.onboardPath`: the default-empty binding, /// writes routing through the environment subscript, and a mounted page resolving an injected /// binding after mount. @Suite(.serialized) @MainActor struct OnboardPathEnvironmentKeyTests { @Test("An unresolved slot reads an empty path") func defaultIsEmpty() { #expect(EnvironmentValues().onboardPath.wrappedValue.isEmpty) } @Test("The key path routes through the environment subscript") func keyPathResolvesToABox() { #expect(EnvironmentValues()._box(for: \.onboardPath) != nil) } @Test("A push through the injected slot reaches the owning state") func injectedBindingWritesThrough() { @State var path: [OnboardDestination] = [] var values = EnvironmentValues() values.onboardPath = $path values.onboardPath.wrappedValue.append(.login) #expect(path == [.login]) } @Test("A page mounted under the injection pushes onto the window's path") func mountedPageResolvesInjectedBinding() { guard Gtk.initCheck() else { return } @State var path: [OnboardDestination] = [] let capture = PathCapture() let context = MountContext() _ = AnyView(PathProbe(capture: capture).environment(\.onboardPath, $path)).makeWidget(context) defer { context.registry.teardown() } capture.path?.wrappedValue.append(.manualLogin) #expect(path == [.manualLogin]) } }