SPB Git

Repository Public MIT

GlassExamplesTests.swift 3.8 KB 90 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Tests/SPGlassExamplesTests/GlassExamplesTests.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// =============================================================================4041import SwiftUI42import Testing43import SPGlassKit44@testable import SPGlassExamples4546@Suite("Compiled examples")47@MainActor48struct GlassExamplesTests {49    @Test func everyCatalogueComponentHasExactlyOneExample() {50        let ids = GlassExampleCatalog.all.map(\.id)51        #expect(Set(ids).count == ids.count)52        #expect(Set(ids) == Set(GlassComponentCatalog.all.map(\.id)))53        for entry in GlassExampleCatalog.all {54            let name = GlassComponentCatalog.component(id: entry.id)?.name ?? ""55            #expect(entry.typeName == "\(name)Example")56        }57    }5859    #if os(macOS)60    /// Builds each example in an off-screen window-less hosting view and lays it out. This proves that the61    /// view body can be evaluated and sized in every theme and appearance; it does not check how it looks.62    @Test("Every example lays out in every built-in theme, light and dark", arguments: GlassTheme.builtIn.map(\.id.rawValue))63    func layout(themeID: String) throws {64        let theme = try #require(GlassTheme.named(GlassThemeID(themeID)))65        for entry in GlassExampleCatalog.all {66            for scheme in [ColorScheme.light, .dark] {67                let host = NSHostingView(rootView: entry.make().glassTheme(theme).environment(\.colorScheme, scheme).frame(width: 420, height: 640))68                host.frame = NSRect(x: 0, y: 0, width: 420, height: 640)69                host.layoutSubtreeIfNeeded()70                #expect(host.fittingSize.width > 0, "\(entry.id) in \(themeID)")71            }72        }73    }7475    @Test func examplesLayOutWithSimulatedAccessibilitySettingsAndLargeText() {76        for entry in GlassExampleCatalog.all {77            let view = entry.make()78                .glassSimulatedAccessibility(reduceTransparency: true, reduceMotion: true)79                .environment(\.dynamicTypeSize, .accessibility3)80                .environment(\.layoutDirection, .rightToLeft)81                .frame(width: 320, height: 640)82            let host = NSHostingView(rootView: view)83            host.frame = NSRect(x: 0, y: 0, width: 320, height: 640)84            host.layoutSubtreeIfNeeded()85            #expect(host.fittingSize.width > 0, "\(entry.id)")86        }87    }88    #endif89}90
Files main
Menu

Theme