Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Tests/SPGlassNavigationTests/GlassSidebarTests.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 Foundation42import Testing43@testable import SPGlassNavigation4445@Suite("GlassSidebar and GlassBreadcrumb")46struct GlassSidebarTests {47 private let sections: [GlassSidebarSection<String>] = [48 GlassSidebarSection(id: "mail", title: "Courrier", items: [49 GlassSidebarItem(id: "inbox", title: "Boîte de réception", systemImage: "tray", badge: 4, keywords: ["inbox"]),50 GlassSidebarItem(id: "sent", title: "Éléments envoyés"),51 GlassSidebarItem(id: "events", title: "Événements à venir"),52 ]),53 GlassSidebarSection(id: "tags", title: "Étiquettes", items: [54 GlassSidebarItem(id: "travel", title: "Voyages ✈️"),55 GlassSidebarItem(id: "tokyo", title: "東京"),56 ]),57 GlassSidebarSection(id: "other", items: [58 GlassSidebarItem(id: "trash", title: "Corbeille"),59 ]),60 ]6162 private func ids(_ query: String) -> [String] {63 GlassSidebarFilter.filter(sections, query: query).flatMap { $0.items.map(\.id) }64 }6566 @Test func emptyOrBlankQueryKeepsEverything() {67 #expect(GlassSidebarFilter.filter(sections, query: "") == sections)68 #expect(GlassSidebarFilter.filter(sections, query: " \n ") == sections)69 }7071 @Test func searchIgnoresCaseAndDiacritics() {72 #expect(ids("evenements") == ["events"])73 #expect(ids("ÉVÉNEMENTS") == ["events"])74 #expect(ids("boite") == ["inbox"])75 #expect(ids("Elements ENVOYES") == ["sent"])76 }7778 @Test func searchMatchesKeywordsAndEveryWord() {79 #expect(ids("inbox") == ["inbox"])80 #expect(ids("venir evenements") == ["events"])81 #expect(ids("evenements absent").isEmpty)82 }8384 @Test func searchHandlesOtherScriptsAndEmoji() {85 #expect(ids("東京") == ["tokyo"])86 #expect(ids("✈️") == ["travel"])87 #expect(ids("voyages") == ["travel"])88 }8990 @Test func emptySectionsAreDroppedAndOrderIsKept() {91 let result = GlassSidebarFilter.filter(sections, query: "e")92 #expect(result.map(\.id) == ["mail", "tags", "other"])93 let narrow = GlassSidebarFilter.filter(sections, query: "corbeille")94 #expect(narrow.map(\.id) == ["other"])95 #expect(narrow.first?.title == nil)96 #expect(GlassSidebarFilter.filter(sections, query: "zzz").isEmpty)97 }9899 @Test func aMatchingSectionTitleKeepsAllItsItems() {100 #expect(ids("etiquettes") == ["travel", "tokyo"])101 }102103 @Test func normalizeTrimsAndFolds() {104 #expect(GlassSidebarFilter.normalize(" Événements ") == "evenements")105 #expect(GlassSidebarFilter.normalize("ÀÉÎÕÜ ç ñ") == "aeiou c n")106 }107108 @Test func breadcrumbShowsEverythingWhenItFits() {109 let layout = GlassBreadcrumbLayout(count: 3, maxVisible: 4)110 #expect(layout.visible == [0, 1, 2])111 #expect(layout.hidden.isEmpty)112 #expect(GlassBreadcrumbLayout(count: 4, maxVisible: 4).hidden.isEmpty)113 }114115 @Test func breadcrumbKeepsRootAndTheLastLevels() {116 let layout = GlassBreadcrumbLayout(count: 7, maxVisible: 4)117 #expect(Array(layout.leading) == [0])118 #expect(Array(layout.hidden) == [1, 2, 3])119 #expect(Array(layout.trailing) == [4, 5, 6])120121 let two = GlassBreadcrumbLayout(count: 5, maxVisible: 2)122 #expect(two.visible == [0, 4])123 #expect(Array(two.hidden) == [1, 2, 3])124 }125126 @Test("With one visible level only the current location stays", arguments: [1, 0, -2])127 func breadcrumbSingleLevel(maxVisible: Int) {128 let layout = GlassBreadcrumbLayout(count: 5, maxVisible: maxVisible)129 #expect(layout.leading.isEmpty)130 #expect(Array(layout.hidden) == [0, 1, 2, 3])131 #expect(Array(layout.trailing) == [4])132 }133134 @Test("Visible and hidden levels partition the path and keep the current location", arguments: 0...9, 1...6)135 func breadcrumbPartition(count: Int, maxVisible: Int) {136 let layout = GlassBreadcrumbLayout(count: count, maxVisible: maxVisible)137 #expect(Array(layout.leading) + Array(layout.hidden) + Array(layout.trailing) == Array(0..<count))138 #expect(layout.visible.count <= max(maxVisible, 0) || count <= maxVisible)139 if count > 0 { #expect(layout.visible.last == count - 1) }140 }141142 @Test func breadcrumbEmptyPath() {143 let layout = GlassBreadcrumbLayout(count: 0, maxVisible: 3)144 #expect(layout.visible.isEmpty && layout.hidden.isEmpty)145 #expect(GlassBreadcrumbLayout(count: -3, maxVisible: 3) == layout)146 }147148 @MainActor149 @Test func breadcrumbTriesFewerLevelsDownToOne() {150 #expect(GlassBreadcrumb<Int>.candidates(count: 6, maxVisible: 4) == [4, 3, 2, 1])151 #expect(GlassBreadcrumb<Int>.candidates(count: 2, maxVisible: 4) == [2, 1])152 #expect(GlassBreadcrumb<Int>.candidates(count: 5, maxVisible: 0) == [1])153 }154}155