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/ORIXMapsUITests/DirectionsTests.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 DirectionsTests: ORIXUITestCase {93 private func route(_ index: Int) -> XCUIElement { app.buttons["directions.route.\(index)"] }94 private let downtownToStadium = ["-ORIXRouteFrom", Place.downtown, "-ORIXRouteTo", Place.olympicStadium]95 /// A few blocks downtown: about 400 m.96 private let shortWalk = ["-ORIXRouteFrom", Place.downtown, "-ORIXRouteTo", "45.5040,-73.5700", "-ORIXMode", "walk"]9798 func testDirectionsInEachModeWithAlternativesAndSteps() {99 launch(region: true, extra: downtownToStadium)100 let first = require(route(0), "a route is computed", timeout: 60)101 let car = first.label102 XCTAssertTrue(car.contains("min") && car.contains("km"), "the route card gives a duration and a distance: \(car)")103 XCTAssertTrue(require(element("directions.note")).label.contains("No traffic, closures or roadworks."), "the limits of an offline route are stated")104 screenshot("directions-car")105106 // Alternatives are offered between two points and can be chosen.107 let alternative = require(route(1), "an alternative is offered")108 XCTAssertTrue(first.isSelected && !alternative.isSelected)109 alternative.tap()110 wait("the alternative becomes the selected route") { self.route(1).isSelected && !self.route(0).isSelected }111 route(0).tap()112 wait("the first route is selected again") { self.route(0).isSelected }113114 // The steps.115 app.swipeUp()116 let steps = require(app.buttons.containing(NSPredicate(format: "label MATCHES %@", "\\d+ steps")).firstMatch, "the number of steps is shown")117 steps.tap()118 require(text(containing: "You have arrived at your destination"), "the list ends with the arrival")119 screenshot("directions-steps")120 app.swipeDown()121122 // Cycling and walking give their own routes, slower than driving.123 var labels: [String: String] = ["Drive": car]124 for mode in ["Cycle", "Walk"] {125 require(app.buttons[mode]).tap()126 wait("a route is computed in mode \(mode)", timeout: 60) { self.route(0).exists && self.route(0).label != labels["Drive"] && !labels.values.contains(self.route(0).label) }127 labels[mode] = route(0).label128 screenshot("directions-\(mode.lowercased())")129 }130 XCTAssertEqual(Set(labels.values).count, 3, "three modes, three different routes: \(labels)")131 XCTAssertTrue(labels["Walk"]!.contains(" h "), "about 7 km on foot takes more than an hour: \(labels["Walk"]!)")132133 // Closing the planner removes the route.134 app.buttons["panel.close"].tap()135 require(app.textFields["search.field"])136 }137138 func testDirectionsFromMyPositionToASearchedPlace() {139 XCUIDevice.shared.location = XCUILocation(location: CLLocation(latitude: 45.5017, longitude: -73.5673))140 launch(region: true)141 search("Stade olympique")142 require(app.buttons.matching(identifier: "search.result").containing(NSPredicate(format: "label CONTAINS[c] %@", "Stade olympique")).firstMatch).tap()143 require(app.buttons["place.directions"]).tap()144 _ = answerLocationPrompt(allow: true, timeout: 3)145 require(app.staticTexts["My position"], "the route starts from the device position")146 // The route is computed as soon as the position arrives: nothing to tap.147 let card = require(route(0), "a route from the simulated position is computed", timeout: 60)148 XCTAssertTrue(card.label.contains("km"), card.label)149 require(app.buttons["directions.start"])150 require(app.buttons["directions.simulate"])151 screenshot("directions-from-my-position")152 }153154 func testSimulatedGuidanceToArrival() {155 launch(region: true, extra: shortWalk + ["-ORIXSimulate", "YES"])156 require(element("navigation.banner"), "guidance shows the next maneuver", timeout: 60)157 require(text(containing: "Simulation: the position shown is replayed"))158 require(app.staticTexts["Arrival"])159 require(app.staticTexts["Remaining"])160 screenshot("guidance-banner")161 require(app.staticTexts["You have arrived"], "the simulated walk reaches the destination", timeout: 180)162 screenshot("guidance-arrived")163 app.buttons["navigation.done"].tap()164 require(app.textFields["search.field"], "guidance ends on the home panel")165 XCTAssertFalse(element("navigation.banner").exists)166 }167168 func testEndingGuidanceEarly() {169 launch(region: true, extra: downtownToStadium + ["-ORIXSimulate", "YES"])170 require(element("navigation.banner"), timeout: 60)171 // The banner advances: the remaining distance changes while the drive is replayed.172 let before = element("navigation.banner").label173 wait("the guidance banner is updated as the position moves", timeout: 30) { self.element("navigation.banner").label != before }174 XCTAssertFalse(app.staticTexts["You have arrived"].exists)175 // Voice can be muted and unmuted from the panel.176 let mute = require(app.buttons["Mute spoken instructions"])177 mute.tap()178 require(app.buttons["Unmute spoken instructions"]).tap()179 require(app.buttons["navigation.end"]).tap()180 require(app.textFields["search.field"], "ending guidance returns to the home panel")181 XCTAssertFalse(element("navigation.banner").exists)182 XCTAssertFalse(route(0).exists)183 }184185 func testStartingSimulationFromThePlanner() {186 launch(region: true, extra: shortWalk)187 require(route(0), timeout: 60)188 app.swipeUp()189 require(app.buttons["directions.simulate"]).tap()190 require(element("navigation.banner"), timeout: 30)191 require(app.buttons["navigation.end"]).tap()192 require(app.textFields["search.field"])193 }194195 func testAPointOutsideTheRegionIsExplained() {196 launch(region: true, extra: ["-ORIXRouteFrom", Place.downtown, "-ORIXRouteTo", "46.8139,-71.2080"])197 require(text(containing: "These points are not all inside one installed region."), timeout: 60)198 XCTAssertFalse(route(0).exists)199 require(app.buttons["Browse maps"])200 }201202 func testDirectionsWithNoRegionAreExplained() {203 launch(camera: nil)204 search("45.5017, -73.5673")205 require(app.buttons["place.directions"]).tap()206 require(text(containing: "No installed region includes directions."))207 }208}209