Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Tests/SPGlassFormsTests/GlassFormsRenderingTests.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 SPGlassForms4849/// 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("Forms and selection rendering")52@MainActor53struct GlassFormsRenderingTests {54 private func fittingSize(_ view: some View, width: CGFloat = 320) -> CGSize {55 let host = NSHostingView(rootView: view.frame(width: width).glassTheme(.aurora))56 host.layoutSubtreeIfNeeded()57 return host.fittingSize58 }5960 @Test func textFieldsLayOut() {61 let plain = fittingSize(GlassTextField("Name", text: .constant("")))62 let withError = fittingSize(GlassTextField("Name", text: .constant(""), validation: GlassFieldValidation(.required()), validateOn: .always))63 #expect(plain.height > 0)64 #expect(withError.height > plain.height)65 #expect(fittingSize(GlassSecureField("Password", text: .constant("secret"), allowsReveal: true)).height > 0)66 #expect(fittingSize(GlassSearchField(text: .constant("query"))).height > 0)67 }6869 @Test func textAreaIsAtLeastItsMinimumHeight() {70 let size = fittingSize(GlassTextArea("Notes", text: .constant(""), placeholder: "Placeholder", limit: 100, minHeight: 120))71 #expect(size.height >= 120)72 }7374 @Test func otpFieldLaysOutItsBoxes() {75 #expect(fittingSize(GlassOTPField(code: .constant("123"), length: 6)).height >= 40)76 #expect(fittingSize(GlassOTPField(code: .constant(""), length: 4, hasError: true), width: 160).height >= 40)77 }7879 @Test func selectionControlsLayOut() {80 #expect(fittingSize(GlassToggle("Notifications", description: "A longer description that wraps on two lines at this width.", isOn: .constant(true))).height > 0)81 #expect(fittingSize(GlassSlider("Volume", value: .constant(0.4), showsBoundLabels: true)).height > 0)82 #expect(fittingSize(GlassStepper("Guests", value: .constant(2), in: 1...8)).height > 0)83 #expect(fittingSize(GlassPicker("Currency", selection: .constant("CAD"), options: ["CAD", "EUR"])).height > 0)84 #expect(fittingSize(GlassPicker("Priority", selection: .constant("Low"), options: ["Low", "High"], presentation: .inline)).height > 0)85 #expect(fittingSize(GlassSegmentedControl("View", selection: .constant("List"), options: ["List", "Grid", "Map"]) { $0 }).height > 0)86 #expect(fittingSize(GlassSegmentedControl("Day", selection: .constant("Mon"), options: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) { $0 }).height > 0)87 }8889 @Test func reducedTransparencySimulationStillLaysOut() {90 let view = GlassTextField("Name", text: .constant("Ada")).glassSimulatedAccessibility(reduceTransparency: true, reduceMotion: true)91 #expect(fittingSize(view).height > 0)92 }93}94#endif95