Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Tests/SPGlassComponentsTests/GlassAccordionTests.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 Testing43@testable import SPGlassComponents4445@Suite("GlassAccordion")46struct GlassAccordionTests {47 @Test func multipleModeAccumulatesSections() {48 var expanded: Set<String> = []49 expanded = GlassAccordionReducer.setting("a", expanded: true, in: expanded, mode: .multiple)50 expanded = GlassAccordionReducer.setting("b", expanded: true, in: expanded, mode: .multiple)51 #expect(expanded == ["a", "b"])52 expanded = GlassAccordionReducer.setting("a", expanded: false, in: expanded, mode: .multiple)53 #expect(expanded == ["b"])54 }5556 @Test func singleModeReplacesTheOpenSection() {57 let expanded = GlassAccordionReducer.setting("b", expanded: true, in: ["a"], mode: .single)58 #expect(expanded == ["b"])59 #expect(GlassAccordionReducer.setting("b", expanded: false, in: expanded, mode: .single).isEmpty)60 }6162 @Test func singleModeCollapsesAnInheritedMultipleSet() {63 #expect(GlassAccordionReducer.setting("c", expanded: true, in: ["a", "b"], mode: .single) == ["c"])64 }6566 @Test func redundantChangesKeepTheSet() {67 #expect(GlassAccordionReducer.setting("z", expanded: false, in: ["a"], mode: .single) == ["a"])68 #expect(GlassAccordionReducer.setting("a", expanded: true, in: ["a"], mode: .multiple) == ["a"])69 }7071 @Test func togglingFlipsOneSection() {72 #expect(GlassAccordionReducer.toggling(1, in: [1, 2], mode: .multiple) == [2])73 #expect(GlassAccordionReducer.toggling(3, in: [1, 2], mode: .multiple) == [1, 2, 3])74 #expect(GlassAccordionReducer.toggling(3, in: [1, 2], mode: .single) == [3])75 #expect(GlassAccordionReducer.toggling(1, in: [1], mode: .single).isEmpty)76 }7778 @Test func displayedSetIgnoresUnknownIdentifiers() {79 #expect(GlassAccordionReducer.displayed(["a", "gone"], order: ["a", "b"], mode: .multiple) == ["a"])80 }8182 @Test func displayedSetKeepsTheFirstSectionInSingleMode() {83 #expect(GlassAccordionReducer.displayed(["c", "b"], order: ["a", "b", "c"], mode: .single) == ["b"])84 #expect(GlassAccordionReducer.displayed([], order: ["a"], mode: .single).isEmpty)85 }86}87