Repository Public BSD-3-Clause
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Maps9// File : Apps/ORIXMaps/Tests/ORIXMapsTests/AppSettingsTests.swift10// Module : ORIXMapsTests11// Repository : https://git.spboucher.ai/orix-maps12// Created : 2026-11-2513// Last Modified : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation89import ORIXDesignSystem90import ORIXGeoCore91import ORIXMapRenderer92import Testing93@testable import ORIXMaps9495struct AppSettingsTests {96 @Test func defaultsOfAFreshInstall() {97 let scratch = ScratchDefaults()98 let s = AppSettings(defaults: scratch.defaults)99 #expect(s.themeID == "orix.day")100 #expect(s.nightThemeAutomatic)101 #expect(s.appearance == .system)102 #expect(s.units == (Locale.current.measurementSystem == .metric ? .metric : .imperial))103 #expect(s.coordinateStyle == .decimalDegrees)104 #expect(s.labelLanguage == .automatic)105 #expect(s.historyEnabled)106 #expect(s.voiceGuidance && s.voiceVolume == 1 && s.voiceIdentifier == nil)107 #expect(s.keepScreenOnDuringNavigation)108 #expect(!s.highFrameRate)109 #expect(!s.hasCompletedOnboarding)110 #expect(!s.avoidTolls && !s.avoidFerries && !s.avoidMotorways && !s.avoidUnpaved)111 #expect(s.lastCamera == nil)112 }113114 @Test func everyValueSurvivesARelaunch() {115 let scratch = ScratchDefaults()116 let a = AppSettings(defaults: scratch.defaults)117 a.themeID = "orix.terrain"; a.nightThemeAutomatic = false; a.appearance = .dark118 a.units = .imperial; a.coordinateStyle = .utm; a.labelLanguage = .french119 a.historyEnabled = false; a.voiceGuidance = false; a.voiceIdentifier = "voice.x"; a.voiceVolume = 0.4120 a.keepScreenOnDuringNavigation = false; a.highFrameRate = true; a.hasCompletedOnboarding = true121 a.avoidTolls = true; a.avoidFerries = true; a.avoidMotorways = true; a.avoidUnpaved = true122 let b = AppSettings(defaults: scratch.defaults)123 #expect(b.themeID == "orix.terrain" && !b.nightThemeAutomatic && b.appearance == .dark)124 #expect(b.units == .imperial && b.coordinateStyle == .utm && b.labelLanguage == .french)125 #expect(!b.historyEnabled && !b.voiceGuidance && b.voiceIdentifier == "voice.x" && b.voiceVolume == 0.4)126 #expect(!b.keepScreenOnDuringNavigation && b.highFrameRate && b.hasCompletedOnboarding)127 #expect(b.avoidTolls && b.avoidFerries && b.avoidMotorways && b.avoidUnpaved)128 }129130 @Test func unknownStoredValuesFallBackToDefaults() {131 let scratch = ScratchDefaults()132 scratch.defaults.set("sepia", forKey: "appearance")133 scratch.defaults.set("furlongs", forKey: "units")134 scratch.defaults.set("what3words", forKey: "coordinateStyle")135 scratch.defaults.set("klingon", forKey: "labelLanguage")136 let s = AppSettings(defaults: scratch.defaults)137 #expect(s.appearance == .system && s.coordinateStyle == .decimalDegrees && s.labelLanguage == .automatic)138 #expect(MeasureFormatter.System.allCases.contains(s.units))139 }140141 @Test func lastCameraIsStoredAndErased() {142 let scratch = ScratchDefaults()143 let s = AppSettings(defaults: scratch.defaults)144 let camera = MapCamera(center: Coordinate(latitude: 45.5, longitude: -73.6), zoom: 13, bearing: 20, pitch: 30)145 s.lastCamera = camera146 #expect(AppSettings(defaults: scratch.defaults).lastCamera == camera)147 s.lastCamera = nil148 #expect(AppSettings(defaults: scratch.defaults).lastCamera == nil)149 }150151 @Test func corruptedLastCameraIsIgnored() {152 let scratch = ScratchDefaults()153 scratch.defaults.set(Data("not json".utf8), forKey: "lastCamera")154 #expect(AppSettings(defaults: scratch.defaults).lastCamera == nil)155 }156157 @Test func labelLanguageRules() {158 let scratch = ScratchDefaults()159 let s = AppSettings(defaults: scratch.defaults)160 s.labelLanguage = .local161 #expect(s.labelLanguageCode == "")162 s.labelLanguage = .english163 #expect(s.labelLanguageCode == "en")164 s.labelLanguage = .french165 #expect(s.labelLanguageCode == "fr")166 // Automatic follows the interface language when the maps have labels in it (French, English), English otherwise.167 s.labelLanguage = .automatic168 let interface = Locale.current.language.languageCode?.identifier ?? "en"169 #expect(s.labelLanguageCode == (interface == "fr" ? "fr" : "en"))170 #expect(s.interfaceLanguageCode == (interface == "fr" ? "fr" : "en"))171 }172173 @Test func formatterFollowsUnits() {174 let scratch = ScratchDefaults()175 let s = AppSettings(defaults: scratch.defaults)176 s.units = .metric177 #expect(s.formatter.distance(1500).hasSuffix("km"))178 s.units = .imperial179 #expect(s.formatter.distance(1500).hasSuffix("mi"))180 }181}182