SPB Git

Repository Public BSD-3-Clause

ToolsTests.swift 10.0 KB 212 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/ToolsTests.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 CoreLocation89import XCTest9091@MainActor92final class ToolsTests: ORIXUITestCase {93    // MARK: Measure9495    func testMeasureDistanceAndArea() {96        launch(region: true)97        openMenu(.measure)98        require(app.staticTexts["Measure"])99        require(text(containing: "Tap the map to add points"))100        func stat(_ title: String) -> String { app.descendants(matching: .any).matching(NSPredicate(format: "label ENDSWITH %@", ", " + title)).firstMatch.label }101        XCTAssertFalse(app.buttons["Undo"].isEnabled)102        mapPoint(dx: 0.25, dy: 0.2).tap()103        wait("one point is counted, got \(stat("Points"))") { stat("Points").hasPrefix("1") }104        mapPoint(dx: 0.65, dy: 0.2).tap()105        wait("two points are counted, got \(stat("Points"))") { stat("Points").hasPrefix("2") }106        let two = stat("Distance")107        XCTAssertFalse(two.hasPrefix("0 m"), "the distance between two points is measured: \(two)")108        XCTAssertFalse(app.buttons["Close shape"].isEnabled, "a shape needs three points")109        mapPoint(dx: 0.45, dy: 0.4).tap()110        wait("three points are counted") { stat("Points").hasPrefix("3") }111        XCTAssertTrue(stat("Area").hasPrefix("—"), "no area while the shape is open")112        app.buttons["Close shape"].tap()113        wait("the area is measured once the shape is closed") { !stat("Area").hasPrefix("—") }114        XCTAssertNotEqual(stat("Distance"), two, "the perimeter includes the closing side")115        screenshot("measure")116        app.buttons["Undo"].tap()117        wait("undo removes a point and reopens the shape") { stat("Points").hasPrefix("2") && stat("Area").hasPrefix("—") }118        app.buttons["Clear"].tap()119        wait("clear removes everything") { stat("Points").hasPrefix("0") }120        // While measuring, a tap does not open a place card; closing gives the taps back.121        XCTAssertFalse(app.buttons["place.directions"].exists)122        app.buttons["panel.close"].tap()123        require(app.textFields["search.field"])124    }125126    // MARK: Tracks127128    func testRecordATrackSeeItsStatisticsAndExportIt() {129        // The simulated device moves north from downtown, about 11 m every two seconds.130        func move(_ step: Int) { XCUIDevice.shared.location = XCUILocation(location: CLLocation(latitude: 45.5017 + Double(step) * 0.0001, longitude: -73.5673)) }131        move(0)132        launch(region: true)133        openMenu(.tracks)134        require(app.staticTexts["No track yet."])135        require(app.buttons["tracks.record"]).tap()136        _ = answerLocationPrompt(allow: true, timeout: 3)137        require(app.staticTexts["Recording"], "the recording panel is shown")138        for step in 1...8 { move(step); sleep(2) }139        func stat(_ title: String) -> String { app.descendants(matching: .any).matching(NSPredicate(format: "label ENDSWITH %@", ", " + title)).firstMatch.label }140        wait("the distance grows while the position moves", timeout: 20) { !stat("Distance").hasPrefix("0 m") && !stat("Distance").hasPrefix("—") }141        screenshot("track-recording")142143        // Pause, resume, stop.144        app.buttons["track.pause"].tap()145        require(app.staticTexts["Paused"])146        app.buttons["Resume"].tap()147        require(app.staticTexts["Recording"])148        app.buttons["track.stop"].tap()149        require(app.staticTexts["Stop recording?"])150        require(app.buttons["track.stop.confirm"].firstMatch).tap()151        require(text(containing: "Track saved"))152153        // The saved track and its statistics.154        openMenu(.tracks)155        let row = require(app.buttons.containing(NSPredicate(format: "label BEGINSWITH %@", "Track of ")).firstMatch, "the recorded track is listed")156        XCTAssertTrue(row.label.contains(" m") || row.label.contains("km"), row.label)157        row.tap()158        require(app.staticTexts["Statistics"])159        for title in ["Distance", "Duration", "Moving time", "Average speed", "Top speed"] { require(app.staticTexts[title], "statistic \(title)") }160        XCTAssertFalse(stat("Distance").hasPrefix("—"))161        XCTAssertFalse(stat("Duration").hasPrefix("—"))162        screenshot("track-statistics")163164        // Export as GPX: a file is produced and offered to the share sheet.165        scrollTo(element("track.export")).tap()166        require(app.buttons["GPX"]).tap()167        let share = require(app.buttons.containing(NSPredicate(format: "label BEGINSWITH %@ AND label ENDSWITH %@", "Share Track of", ".gpx")).firstMatch, "the exported GPX file is offered for sharing")168        XCTAssertTrue(share.isEnabled)169        screenshot("track-export")170        require(app.buttons["track.replay"], "a recorded track can be replayed")171    }172173    // MARK: Compass174175    func testCompassShowsCoordinatesOfTheSimulatedPosition() {176        XCUIDevice.shared.location = XCUILocation(location: CLLocation(latitude: 45.5017, longitude: -73.5673))177        launch(region: true)178        openMenu(.compass)179        _ = answerLocationPrompt(allow: true, timeout: 3)180        require(text(containing: "45.5017"), "the compass shows the coordinates of the position", timeout: 20)181        require(app.staticTexts["Accuracy"])182        screenshot("compass")183    }184185    // MARK: Explorer and planner186187    func testExplorerListsPlacesAndOpensOne() {188        launch(region: true)189        openMenu(.explorer)190        require(app.navigationBars["Explore"])191        require(app.buttons["Sights"])192        let places = app.buttons.matching(NSPredicate(format: "label CONTAINS %@", " · "))193        require(places.firstMatch, "sights around the map centre are listed", timeout: 20)194        let sight = places.firstMatch.label195        screenshot("explorer")196        app.buttons["Food and drink"].tap()197        wait("the list changes with the theme", timeout: 20) { places.firstMatch.exists && places.firstMatch.label != sight }198        places.firstMatch.tap()199        require(app.staticTexts["panel.title"], "choosing a place opens its card on the map")200    }201202    func testPlannerReportsCoverageOfThePlannedRoute() {203        // The menu belongs to the home panel, which the route planner replaces: the planner is opened by launch argument.204        launch(region: true, extra: ["-ORIXRouteFrom", Place.downtown, "-ORIXRouteTo", Place.olympicStadium, "-ORIXScreen", "planner"])205        require(app.navigationBars["Trip planner"], timeout: 60)206        require(text(containing: "Checking the route currently planned"), timeout: 60)207        require(text(containing: "Every part of this trip is inside an installed map."))208        require(text(containing: "100%"))209        screenshot("planner")210    }211}212
Files main
Menu

Theme