Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Tests/SPGlassComponentsTests/GlassBadgeTests.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 SPGlassCore44@testable import SPGlassComponents4546@Suite("GlassBadge")47struct GlassBadgeTests {48 private let english = Locale(identifier: "en_US")4950 @Test func countsUpToTheCapAreShownAsIs() {51 #expect(GlassBadgeFormatter.countText(1, locale: english) == "1")52 #expect(GlassBadgeFormatter.countText(42, locale: english) == "42")53 #expect(GlassBadgeFormatter.countText(99, locale: english) == "99")54 }5556 @Test func countsAboveTheCapShowTheCapAndAPlus() {57 #expect(GlassBadgeFormatter.countText(100, locale: english) == "99+")58 #expect(GlassBadgeFormatter.countText(Int.max, locale: english) == "99+")59 #expect(GlassBadgeFormatter.countText(10, cap: 9, locale: english) == "9+")60 #expect(GlassBadgeFormatter.countText(1_500, cap: 999, locale: english) == "999+")61 }6263 @Test func zeroIsHiddenUnlessRequested() {64 #expect(GlassBadgeFormatter.countText(0, locale: english) == nil)65 #expect(GlassBadgeFormatter.countText(0, showsZero: true, locale: english) == "0")66 }6768 @Test func negativeCountsAreTreatedAsZero() {69 #expect(GlassBadgeFormatter.countText(-5, locale: english) == nil)70 #expect(GlassBadgeFormatter.countText(Int.min, showsZero: true, locale: english) == "0")71 }7273 @Test func aCapBelowOneCountsAsOne() {74 #expect(GlassBadgeFormatter.countText(1, cap: 0, locale: english) == "1")75 #expect(GlassBadgeFormatter.countText(2, cap: -3, locale: english) == "1+")76 }7778 @Test func digitsFollowTheLocale() {79 #expect(GlassBadgeFormatter.countText(12, locale: Locale(identifier: "ar_EG@numbers=arab")) == "١٢")80 #expect(GlassBadgeFormatter.countText(1_200, cap: 9_999, locale: Locale(identifier: "fr_FR"))?.contains("1") == true)81 }8283 @Test func accessibilityLabelSaysMoreThanAboveTheCap() {84 let exact = GlassBadgeFormatter.countAccessibilityLabel(7)85 let capped = GlassBadgeFormatter.countAccessibilityLabel(250)86 #expect(exact.contains("7"))87 #expect(capped.contains("99"))88 #expect(exact != capped)89 #expect(GlassBadgeFormatter.countAccessibilityLabel(-4).contains("0"))90 }9192 @Test func everyToneHasADistinctStatusSymbol() {93 #expect(Set(GlassBadgeTone.allCases.map(\.statusSystemImage)).count == GlassBadgeTone.allCases.count)94 }9596 @Test func tonesMapToThemeRoles() {97 #expect(GlassBadgeTone.neutral.colorToken == nil)98 #expect(GlassBadgeTone.accent.colorToken == .accent)99 #expect(GlassBadgeTone.success.colorToken == .success)100 #expect(GlassBadgeTone.warning.colorToken == .warning)101 #expect(GlassBadgeTone.critical.colorToken == .destructive)102 }103}104