SPB Git

Repository Public

StudioUITests.swift 3.8 KB 65 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Tests/UITests/StudioUITests.swift3// Description: Click-through of the Research Studio on the TEST backend (5058): sidebar, a new project named mac-test-…, opening it by click, a note typed in the native editor with its preview, then deletion of the note and the project.4import XCTest56final class StudioUITests: XCTestCase {7    private func el(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch }8    private func waitGone(_ e: XCUIElement, timeout: TimeInterval = 10) -> Bool {9        let deadline = Date().addingTimeInterval(timeout)10        while e.exists, Date() < deadline { usleep(200_000) }11        return !e.exists12    }1314    func testProjectNoteAndPreview() throws {15        let env = ProcessInfo.processInfo.environment16        guard let token = env["VQ_DEV_TOKEN"], let server = env["VQ_SERVER"] else { throw XCTSkip("needs a development session (Scripts/ui-test.sh)") }17        let app = XCUIApplication()18        app.launchArguments = ["-VQUITest", "-VQInMemory", "-ApplePersistenceIgnoreState", "YES"]19        app.launchEnvironment = ["VQ_DEV_TOKEN": token, "VQ_SERVER": server]20        app.launch()21        XCTAssertTrue(app.windows.firstMatch.waitForExistence(timeout: 20))22        el(app, "sidebar.studio").click()23        let new = el(app, "studio.new")24        XCTAssertTrue(new.waitForExistence(timeout: 15))25        new.click()26        let title = el(app, "project.title")27        XCTAssertTrue(title.waitForExistence(timeout: 10), "the new project opens on its page")28        // under -VQUITest a new project is titled "mac-test-ui project"29        let row = app.descendants(matching: .any).matching(NSPredicate(format: "identifier BEGINSWITH 'studio.project.mac-test-ui'")).firstMatch30        XCTAssertTrue(row.waitForExistence(timeout: 10), "the list shows the new project")31        // open another section and come back: the project opens by click on its row32        el(app, "sidebar.portfolio").click()33        el(app, "sidebar.studio").click()34        XCTAssertTrue(row.waitForExistence(timeout: 10))35        row.click()36        XCTAssertTrue(el(app, "project.composer").waitForExistence(timeout: 10))37        // a note: created from the page, typed in the editor, rendered in the preview38        el(app, "project.note.new").click()39        let editor = el(app, "note.editor")40        XCTAssertTrue(editor.waitForExistence(timeout: 10), "the note editor opens")41        app.activate(); editor.click(); usleep(300_000)42        app.typeText("# Thesis mactest\n\nMargins expand.")43        let preview = el(app, "note.preview")44        XCTAssertTrue(preview.waitForExistence(timeout: 5))45        let heading = preview.staticTexts.matching(NSPredicate(format: "value == 'Thesis mactest' OR label == 'Thesis mactest'")).firstMatch46        XCTAssertTrue(heading.waitForExistence(timeout: 5), "the preview renders the heading without its markdown mark")47        // autosave: the state line leaves "Editing…"48        let state = el(app, "note.state")49        let deadline = Date().addingTimeInterval(10)50        func text() -> String { (state.value as? String).flatMap { $0.isEmpty ? nil : $0 } ?? state.label }51        while !text().hasPrefix("Saved"), Date() < deadline { usleep(200_000) }52        XCTAssertTrue(text().hasPrefix("Saved"), "the note is autosaved (state: \(text()))")53        // clean up: the note, then the project54        let noteRow = el(app, "notes.row.Untitled note")55        noteRow.rightClick()56        app.menuItems["Delete Note…"].firstMatch.click()57        app.buttons["Delete Note"].firstMatch.click()58        row.rightClick()59        app.menuItems["Delete…"].firstMatch.click()60        app.buttons["Delete Project"].firstMatch.click()61        XCTAssertTrue(waitGone(row), "it disappears")62        sleep(2)63    }64}65
Files main
Menu

Theme