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/DownloadsTests.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 DownloadsTests: ORIXUITestCase {92 private var getButton: XCUIElement { app.buttons["downloads.get.\(Place.region)"] }93 private var installedRow: XCUIElement { element("downloads.installed.\(Place.region)") }94 private var deleteButton: XCUIElement { app.buttons["downloads.delete.\(Place.region)"] }95 private var pauseButton: XCUIElement { app.buttons["downloads.pause.\(Place.region)"] }96 private var resumeButton: XCUIElement { app.buttons["downloads.resume.\(Place.region)"] }9798 func testWithNoRegionTheMapAppearsAndTheEmptyStateExplains() {99 launch(camera: nil)100 require(map)101 require(app.staticTexts["No map downloaded yet"])102 require(text(containing: "The world map is built in. Download a region"))103 XCTAssertFalse(app.buttons["category.restaurant"].exists, "no category shortcut without a search index")104 screenshot("empty-state")105 // The explanation leads to the list of maps.106 app.buttons["home.browse"].tap()107 require(app.navigationBars["Maps"])108 require(text(containing: "No region installed. The built-in world map shows countries"))109 }110111 func testCatalogDownloadInstallAndRegionVisible() {112 launch()113 openMenu(.downloads)114 require(element("downloads.catalog.\(Place.region)"), "the catalog lists the test region")115 require(app.staticTexts["Greater Montréal"])116 XCTAssertFalse(installedRow.exists)117 require(getButton).tap()118 // Progress, verification, installation: the installed row appears when everything succeeded.119 require(installedRow, "the region was not installed", timeout: 180)120 require(app.staticTexts["Installed and up to date"])121 require(text(containing: "Maps use"))122 XCTAssertFalse(getButton.exists)123 screenshot("downloads-installed")124 // "Show on map" closes the sheet; the region is usable: its search index and categories are there.125 app.buttons["Show on map"].tap()126 waitForRegion(timeout: 30)127 XCTAssertFalse(app.staticTexts["No map downloaded yet"].exists)128 screenshot("region-visible")129 }130131 func testDownloadProgressPauseAndResume() {132 launch(catalog: TestServer.throttledCatalog)133 openMenu(.downloads)134 require(getButton).tap()135 require(text(containing: "Downloading"), "progress is shown while downloading", timeout: 20)136 screenshot("downloads-progress")137 require(pauseButton).tap()138 require(app.staticTexts["Paused"])139 require(resumeButton)140 XCTAssertFalse(installedRow.exists)141 screenshot("downloads-paused")142 resumeButton.tap()143 require(text(containing: "Downloading"), "the download continues after Resume", timeout: 20)144 require(installedRow, "the resumed download was not installed", timeout: 240)145 require(app.staticTexts["Installed and up to date"])146 }147148 func testCancelADownload() {149 launch(catalog: TestServer.throttledCatalog)150 openMenu(.downloads)151 require(getButton).tap()152 require(text(containing: "Downloading"), timeout: 20)153 app.buttons["Cancel"].firstMatch.tap()154 require(getButton, "after Cancel the region is offered again")155 XCTAssertFalse(installedRow.exists)156 }157158 func testStoppedServerShowsTheOfflineMessage() {159 launch(catalog: TestServer.stoppedCatalog)160 openMenu(.downloads)161 require(text(containing: "The map catalog could not be loaded. Check the connection and try again."), timeout: 30)162 require(app.buttons["Try again"])163 XCTAssertFalse(getButton.exists)164 screenshot("downloads-offline")165 // Still usable: retrying fails the same way and nothing crashes.166 app.buttons["Try again"].tap()167 require(text(containing: "The map catalog could not be loaded."), timeout: 30)168 }169170 func testDeletingTheRegionReturnsToTheEmptyState() {171 launch(region: true)172 openMenu(.downloads)173 require(installedRow)174 require(deleteButton).tap()175 require(app.staticTexts["Delete this map?"])176 screenshot("downloads-delete-confirm")177 require(app.buttons["downloads.delete.confirm"].firstMatch).tap()178 waitGone(installedRow)179 require(getButton, "the region is offered for download again")180 require(text(containing: "No region installed."))181 closeModal()182 require(app.staticTexts["No map downloaded yet"])183 XCTAssertFalse(app.buttons["category.restaurant"].exists)184 }185186 func testRelaunchAfterForceQuitDuringADownloadOffersResume() {187 launch(catalog: TestServer.throttledCatalog)188 openMenu(.downloads)189 require(getButton).tap()190 require(text(containing: "Downloading"), timeout: 20)191 sleep(3) // let some of the file arrive192 app.terminate()193194 launch(reset: false, catalog: TestServer.throttledCatalog)195 openMenu(.downloads)196 require(app.staticTexts["Paused"], "the interrupted download is offered again after relaunch")197 require(resumeButton)198 screenshot("downloads-resume-after-relaunch")199 resumeButton.tap()200 require(installedRow, "the download resumed after relaunch was not installed", timeout: 240)201 }202}203