Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Tests/SPGlassNavigationTests/GlassNavigationRenderingTests.swift8// Module : Tests9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041#if os(macOS)42import AppKit43import SwiftUI44import Testing45import SPGlassCore46import SPGlassThemes47@testable import SPGlassNavigation4849/// Builds each view in an off-screen hosting view and lays it out. This catches crashes and views that50/// collapse to nothing; it does not judge what the result looks like.51@Suite("Navigation rendering")52@MainActor53struct GlassNavigationRenderingTests {54 private enum DemoTab: Hashable, Sendable { case one, two }5556 private func layOut(_ view: some View, size: CGSize = CGSize(width: 700, height: 480)) -> CGSize {57 let host = NSHostingView(rootView: view.frame(width: size.width, height: size.height))58 host.frame = CGRect(origin: .zero, size: size)59 host.layoutSubtreeIfNeeded()60 return host.fittingSize61 }6263 private let path = (0..<6).map { GlassBreadcrumbItem(id: $0, title: "Level \($0)") }6465 @Test func breadcrumbLaysOutWithAndWithoutGlass() {66 let host = NSHostingView(rootView: GlassBreadcrumb(path) { _ in })67 host.layoutSubtreeIfNeeded()68 #expect(host.fittingSize.width > 0 && host.fittingSize.height > 0)6970 let opaque = NSHostingView(rootView: GlassBreadcrumb(path, maxVisibleItems: 2) { _ in }.glassSimulatedAccessibility(reduceTransparency: true))71 opaque.layoutSubtreeIfNeeded()72 #expect(opaque.fittingSize.width > 0)73 #expect(opaque.fittingSize.width < host.fittingSize.width)74 }7576 @Test func anEmptyBreadcrumbDrawsNothing() {77 let host = NSHostingView(rootView: GlassBreadcrumb([GlassBreadcrumbItem<Int>]()) { _ in })78 host.layoutSubtreeIfNeeded()79 #expect(host.fittingSize.height == 0)80 }8182 @Test func tabBarBuildsWithDynamicTabs() {83 let tabs = [84 GlassTabItem(id: DemoTab.one, title: "One", systemImage: "1.circle", badge: .count(2)),85 GlassTabItem(id: DemoTab.two, title: "Two", systemImage: "2.circle", isSearch: true),86 ]87 let size = layOut(GlassTabBar(tabs: tabs, state: .constant(GlassTabNavigationState<DemoTab, Int>(selection: .one))) { tab in88 Text(verbatim: "\(tab)")89 } destination: { route in90 Text(verbatim: "\(route)")91 })92 #expect(size.width > 0)93 }9495 @Test func navigationBarToolbarAndSidebarBuild() {96 let action = GlassToolbarAction(id: "add", title: "Add", systemImage: "plus") {}97 #expect(layOut(GlassNavigationBar("Title", subtitle: "Subtitle", titleDisplay: .large, leading: [action], trailing: [action, action, action]) { Text(verbatim: "Body") }).width > 0)98 #expect(layOut(NavigationStack { Text(verbatim: "Body").glassToolbar([GlassToolbarGroup(id: "g", placement: .trailing, capacity: 1, actions: [action, action])]) }).width > 0)99100 let sections = [GlassSidebarSection(id: "s", title: "Section", items: [GlassSidebarItem(id: 1, title: "Row", systemImage: "tray", badge: 3)])]101 #expect(layOut(GlassSidebar("Sidebar", sections: sections, selection: .constant(1)) { id in Text(verbatim: "\(String(describing: id))") }).width > 0)102 }103}104#endif105