SPB Git

Repository Public BSD-3-Clause

AppModelTests.swift 7.7 KB 181 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Maps9// File             : Apps/ORIXMaps/Tests/ORIXMapsTests/AppModelTests.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 ORIXGeoCore90import ORIXMapRenderer91import Testing92@testable import ORIXMaps9394/// The composition root on isolated data (the same isolation the UI tests use: one preferences domain and one95/// temporary directory, reset by each test — hence one test at a time).96@Suite(.serialized)97struct AppModelTests {98    private func makeApp(_ extra: [String: Any] = [:]) -> (AppModel, SpyBackend, ScratchDefaults) {99        let scratch = ScratchDefaults()100        scratch.defaults.set(true, forKey: "ORIXUITest")101        scratch.defaults.set(true, forKey: "ORIXReset")102        scratch.defaults.set(true, forKey: "ORIXSkipOnboarding")103        for (k, v) in extra { scratch.defaults.set(v, forKey: k) }104        let app = AppModel(options: LaunchOptions(defaults: scratch.defaults))105        let spy = SpyBackend()106        app.map.attach(spy)107        return (app, spy, scratch)108    }109110    private let place = PlaceSelection(title: "Stade olympique", subtitle: nil, coordinate: olympicStadium, origin: .search)111112    @Test func launchArgumentsShapeTheFirstState() {113        let (app, _, _) = makeApp(["ORIXTheme": "orix.midnight", "ORIXCamera": "45.5,-73.6,12"])114        #expect(app.settings.hasCompletedOnboarding)115        #expect(app.settings.themeID == "orix.midnight" && !app.settings.nightThemeAutomatic)116        #expect(app.effectiveTheme.id == "orix.midnight")117        #expect(app.map.camera.zoom == 12 && app.map.camera.center.latitude == 45.5)118        #expect(app.route == .home && app.modal == nil)119    }120121    @Test func selectingAPlaceOpensItsCardAndMovesTheCamera() {122        let (app, spy, _) = makeApp()123        app.select(place, moveCamera: true)124        #expect(app.route == .place(place))125        let move = spy.cameras.last126        #expect(move?.camera.center == olympicStadium)127        #expect((move?.camera.zoom ?? 0) >= 15)128        #expect((move?.duration ?? 0) > 0, "the camera glides to the place")129        app.clearSelection()130        #expect(app.route == .home)131    }132133    @Test func withReduceMotionCameraMovesAreImmediate() {134        let (app, spy, _) = makeApp()135        app.reduceMotion = true136        app.select(place, moveCamera: true)137        #expect(spy.cameras.last?.duration == 0)138        app.toggle3D(reduceMotion: true)139        #expect(spy.cameras.last?.duration == 0 && (spy.cameras.last?.camera.pitch ?? 0) > 5)140        app.resetNorth(reduceMotion: true)141        #expect(spy.cameras.last?.duration == 0 && spy.cameras.last?.camera.pitch == 0)142    }143144    @Test func theAutomaticNightThemeAppliesToBuiltInLightThemesOnly() {145        let (app, _, _) = makeApp()146        #expect(app.effectiveTheme.id == "orix.day")147        app.isDarkInterface = true148        #expect(app.effectiveTheme.id == "orix.midnight")149        app.settings.nightThemeAutomatic = false150        #expect(app.effectiveTheme.id == "orix.day")151        app.settings.nightThemeAutomatic = true152        app.selectTheme("orix.terrain")153        #expect(app.effectiveTheme.id == "orix.midnight", "a light built-in theme gives way to Midnight in the dark")154        let own = try? app.themes.duplicate(app.themes.theme(id: "orix.day")!, name: "Mine")155        if let own {156            app.selectTheme(own.id)157            #expect(app.effectiveTheme.id == own.id, "a theme the user made is never replaced")158            app.themes.delete(id: own.id)159        }160    }161162    @Test func droppingAPinUsesTheCoordinateFormatOfTheSettings() {163        let (app, _, _) = makeApp()164        app.settings.coordinateStyle = .utm165        app.dropPin(at: downtownMontreal)166        guard case .place(let p) = app.route else { Issue.record("no place card"); return }167        #expect(p.origin == .droppedPin && p.title.hasPrefix("18T"))168        app.dropPin(at: Coordinate(latitude: 123, longitude: 0))169        guard case .place(let q) = app.route else { Issue.record("no place card"); return }170        #expect(q.id == p.id, "an invalid coordinate is ignored")171    }172173    @Test func erasingHistoryForgetsTheLastViewpoint() {174        let (app, _, _) = makeApp()175        app.settings.lastCamera = MapCamera(center: downtownMontreal, zoom: 14, bearing: 0, pitch: 0)176        app.eraseHistory()177        #expect(app.settings.lastCamera == nil)178        #expect(app.toast == String(localized: "History erased"))179    }180}181
Files main
Menu

Theme