SPB Git

Repository Public BSD-3-Clause

SettingsTests.swift 8.6 KB 209 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Maps9// File             : Apps/ORIXMaps/Tests/ORIXMapsUITests/SettingsTests.swift10// Module           : ORIXMapsUITests11// 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 XCTest8990@MainActor91final class SettingsTests: ORIXUITestCase {92    private var title: XCUIElement { app.staticTexts["panel.title"] }9394    private func choose(_ picker: String, _ option: String) {95        require(app.buttons.containing(NSPredicate(format: "label BEGINSWITH %@", picker)).firstMatch, "picker \(picker)").tap()96        require(app.buttons[option], "option \(option)").tap()97    }9899    func testCoordinateFormatChangesThePlaceCard() {100        launch()101        search("45.5017, -73.5673")102        require(title)103        let decimal = title.label104        XCTAssertTrue(decimal.contains("45.5017"), decimal)105        app.buttons["panel.close"].tap()106107        openMenu(.settings)108        choose("Coordinates", "Degrees, minutes, seconds")109        closeModal()110        search("45.5017, -73.5673")111        require(title)112        let dms = title.label113        XCTAssertNotEqual(dms, decimal)114        XCTAssertTrue(dms.contains("°") && dms.contains("′") || dms.contains("'"), "degrees, minutes and seconds: \(dms)")115        screenshot("settings-coordinates-dms")116        app.buttons["panel.close"].tap()117118        openMenu(.settings)119        choose("Coordinates", "UTM")120        closeModal()121        search("45.5017, -73.5673")122        require(title)123        XCTAssertTrue(title.label.contains("18T"), "Montréal is in UTM zone 18T: \(title.label)")124    }125126    func testUnitsChangeDistances() {127        launch(region: true, extra: ["-ORIXRouteFrom", Place.downtown, "-ORIXRouteTo", Place.olympicStadium])128        let card = require(app.buttons["directions.route.0"], timeout: 60)129        XCTAssertTrue(card.label.contains("km"), "metric by default in en_CA: \(card.label)")130        app.buttons["panel.close"].tap()131132        openMenu(.settings)133        choose("Distances", "Imperial")134        screenshot("settings")135        closeModal()136137        // Search results give the distance in miles or feet.138        app.buttons["category.cafe"].tap()139        let result = require(app.buttons.matching(identifier: "search.result").firstMatch)140        XCTAssertTrue(result.label.hasSuffix(" ft") || result.label.hasSuffix(" mi"), "imperial distances in results: \(result.label)")141        XCTAssertFalse(result.label.hasSuffix(" m") || result.label.hasSuffix(" km"))142    }143144    func testSettingsSurviveARelaunch() {145        launch()146        openMenu(.settings)147        choose("Distances", "Imperial")148        require(app.switches["Avoid tolls"]).switches.firstMatch.tap()149        closeModal()150        app.terminate()151        launch(reset: false)152        openMenu(.settings)153        require(app.buttons.containing(NSPredicate(format: "label CONTAINS %@", "Imperial")).firstMatch, "the units choice is kept")154        XCTAssertEqual(app.switches["Avoid tolls"].value as? String, "1")155    }156157    func testErasingHistoryEmptiesRecents() {158        launch(region: true)159        search("Stade olympique")160        require(app.buttons.matching(identifier: "search.result").firstMatch).tap()161        require(title)162        app.buttons["panel.close"].tap()163        // Back on the results of the search; clearing it shows the resting panel with the recents.164        XCTAssertEqual(require(app.textFields["search.field"]).value as? String, "Stade olympique", "the search is still there after closing the card")165        require(app.buttons["search.clear"]).tap()166        require(app.staticTexts["Recent"], "recent searches and places are listed")167        XCTAssertGreaterThanOrEqual(app.buttons.matching(identifier: "home.recent").count, 1)168        screenshot("home-recents")169170        openMenu(.settings)171        scrollTo(element("settings.privacy")).tap()172        require(app.navigationBars["Privacy"])173        screenshot("privacy")174        require(app.buttons["privacy.erase"]).tap()175        require(text(containing: "Erase recent searches, recent places and the last map position?"))176        require(app.buttons["privacy.erase.confirm"].firstMatch).tap()177        app.navigationBars.buttons.firstMatch.tap()178        closeModal()179        waitGone(app.staticTexts["Recent"])180        XCTAssertEqual(app.buttons.matching(identifier: "home.recent").count, 0)181    }182183    func testTurningHistoryOffRecordsNothing() {184        launch(region: true)185        openMenu(.settings)186        scrollTo(element("settings.privacy")).tap()187        require(app.switches["privacy.history"]).switches.firstMatch.tap()188        app.navigationBars.buttons.firstMatch.tap()189        closeModal()190        search("Stade olympique")191        require(app.buttons.matching(identifier: "search.result").firstMatch).tap()192        require(title)193        app.buttons["panel.close"].tap()194        require(app.buttons["search.clear"]).tap()195        require(app.buttons["category.cafe"])196        XCTAssertFalse(app.staticTexts["Recent"].exists, "nothing is kept while history is off")197    }198199    func testAboutListsTheDataSources() {200        launch(region: true)201        openMenu(.about)202        require(app.navigationBars["About"])203        require(text(containing: "© OpenStreetMap contributors"))204        scrollTo(app.staticTexts["Greater Montréal"])205        require(text(containing: "Map data of"))206        screenshot("about")207    }208}209
Files main
Menu

Theme