Repository Public
1// SP Notes iOS2// File: UITests/SystemUITests.swift3// Description: System entry points seen from outside: the app is launched with a throw-away seeded store, then opened through4// `spnotes://` links (the path the widgets use) and must come to the foreground and stay alive. Assertions on5// the screens themselves are limited to what exists at the time of writing.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import XCTest1011final class SystemUITests: XCTestCase {12 /// Same value as `SampleData.welcomeNoteID` in the app.13 private let welcomeNoteID = "5eed0000-0000-4000-8000-000000000001"1415 override func setUp() { continueAfterFailure = false }1617 private func launch() -> XCUIApplication {18 let app = XCUIApplication()19 app.launchEnvironment["SPNOTES_STORE"] = "memory"20 app.launchEnvironment["SPNOTES_SESSION"] = "local"21 app.launchEnvironment["SPNOTES_SEED"] = "1"22 app.launch()23 XCTAssertTrue(app.wait(for: .runningForeground, timeout: 20))24 return app25 }2627 private func open(_ link: String, in app: XCUIApplication) {28 app.open(URL(string: link)!)29 XCTAssertTrue(app.wait(for: .runningForeground, timeout: 15), "the app did not come to the foreground for \(link)")30 }3132 private func attach(_ name: String, _ app: XCUIApplication) {33 let attachment = XCTAttachment(screenshot: app.screenshot())34 attachment.name = name35 attachment.lifetime = .keepAlways36 add(attachment)37 }3839 /// True when some element of the interface carries this text.40 private func shows(_ text: String, in app: XCUIApplication, timeout: TimeInterval = 8) -> Bool {41 let predicate = NSPredicate(format: "label CONTAINS[c] %@ OR value CONTAINS[c] %@", text, text)42 return app.descendants(matching: .any).matching(predicate).firstMatch.waitForExistence(timeout: timeout)43 }4445 func testNewNoteLinkBringsTheAppForward() {46 let app = launch()47 XCUIDevice.shared.press(.home)48 open("spnotes://new", in: app)49 attach("deep-link-new", app)50 XCTAssertEqual(app.state, .runningForeground)51 }5253 func testNoteLinkOpensTheSeededNote() throws {54 let app = launch()55 // The sample workspace is seeded asynchronously at launch: wait until the home screen lists it.56 try XCTSkipUnless(shows("Bienvenue dans SP Notes", in: app, timeout: 15), "the home screen does not list the seeded notes")57 // Opened through the system, as a widget does: `XCUIApplication.open` relaunches the app, and with a throw-away store58 // the link would then race with the seeding of the new process.59 XCUIDevice.shared.system.open(URL(string: "spnotes://note/\(welcomeNoteID)")!)60 XCTAssertTrue(app.wait(for: .runningForeground, timeout: 15))61 // « Pour commencer » is a heading inside the note: it is only on screen when the note itself is shown.62 let opened = shows("Pour commencer", in: app)63 attach("deep-link-note", app)64 XCTAssertFalse(shows("Cette note n’existe plus", in: app, timeout: 1), "the seeded note was not found by its id")65 try XCTSkipUnless(opened, "the note screen does not expose its text to the accessibility tree yet")66 }6768 func testMalformedAndUnknownLinksAreIgnored() {69 let app = launch()70 for link in ["spnotes://note/../../etc", "spnotes://unknown", "spnotes://note/", "spnotes://new?kind=bogus"] {71 open(link, in: app)72 }73 XCTAssertEqual(app.state, .runningForeground)74 attach("deep-link-ignored", app)75 }7677 func testTaskListLinkCreatesAndOpensANote() {78 let app = launch()79 open("spnotes://new?kind=tasks", in: app)80 XCTAssertEqual(app.state, .runningForeground)81 attach("deep-link-tasks", app)82 }83}84