|
| 1 | +// SPDX-FileCopyrightText: Nextcloud GmbH |
| 2 | +// SPDX-FileCopyrightText: 2025 Iva Horn |
| 3 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + |
| 5 | +import XCTest |
| 6 | + |
| 7 | +/// |
| 8 | +/// User interface tests for the download limits management on shares. |
| 9 | +/// |
| 10 | +@MainActor |
| 11 | +final class AssistantUITests: BaseUIXCTestCase { |
| 12 | + let taskInputCreated = "TestTaskCreated" + UUID().uuidString |
| 13 | + let taskInputRetried = "TestTaskRetried" + UUID().uuidString |
| 14 | + let taskInputToEdit = "TestTaskToEdit" + UUID().uuidString |
| 15 | + let taskInputDeleted = "TestTaskDeleted" + UUID().uuidString |
| 16 | + |
| 17 | + // MARK: - Lifecycle |
| 18 | + |
| 19 | + override func setUp() async throws { |
| 20 | + try await super.setUp() |
| 21 | + continueAfterFailure = false |
| 22 | + |
| 23 | + // Handle alerts presented by the system. |
| 24 | + addUIInterruptionMonitor(withDescription: "Allow Notifications", for: "Allow") |
| 25 | + addUIInterruptionMonitor(withDescription: "Save Password", for: "Not Now") |
| 26 | + |
| 27 | + // Launch the app. |
| 28 | + app = XCUIApplication() |
| 29 | + app.launchArguments = ["UI_TESTING"] |
| 30 | + app.launch() |
| 31 | + |
| 32 | + try await logIn() |
| 33 | + |
| 34 | + // Set up test backend communication. |
| 35 | + backend = UITestBackend() |
| 36 | + |
| 37 | + try await backend.assertCapability(true, capability: \.assistant) |
| 38 | + } |
| 39 | + |
| 40 | + /// |
| 41 | + /// Leads to the Assistant screen. |
| 42 | + /// |
| 43 | + private func goToAssistant() { |
| 44 | + let button = app.tabBars["Tab Bar"].buttons["More"] |
| 45 | + guard button.await() else { return } |
| 46 | + button.tap() |
| 47 | + |
| 48 | + let talkStaticText = app.tables.staticTexts["Assistant"] |
| 49 | + talkStaticText.tap() |
| 50 | + } |
| 51 | + |
| 52 | + private func createTask(input: String) { |
| 53 | + app.navigationBars["Assistant"].buttons["CreateButton"].tap() |
| 54 | + |
| 55 | + let inputTextEditor = app.textViews["InputTextEditor"] |
| 56 | + inputTextEditor.await() |
| 57 | + inputTextEditor.typeText(input) |
| 58 | + app.navigationBars["New Free text to text prompt task"].buttons["Create"].tap() |
| 59 | + } |
| 60 | + |
| 61 | + private func retryTask() { |
| 62 | + let cell = app.collectionViews.children(matching: .cell).element(boundBy: 0) |
| 63 | + cell.staticTexts[taskInputRetried].press(forDuration: 2); |
| 64 | + |
| 65 | + let retryButton = app.buttons["TaskRetryContextMenu"] |
| 66 | + XCTAssertTrue(retryButton.waitForExistence(timeout: 2), "Edit button not found in context menu") |
| 67 | + retryButton.tap() |
| 68 | + } |
| 69 | + |
| 70 | + private func editTask() { |
| 71 | + let cell = app.collectionViews.children(matching: .cell).element(boundBy: 0) |
| 72 | + cell.staticTexts[taskInputToEdit].press(forDuration: 2); |
| 73 | + |
| 74 | + let editButton = app.buttons["TaskEditContextMenu"] |
| 75 | + XCTAssertTrue(editButton.waitForExistence(timeout: 2), "Edit button not found in context menu") |
| 76 | + editButton.tap() |
| 77 | + |
| 78 | + app.textViews["InputTextEditor"].typeText("Edited") |
| 79 | + app.navigationBars["Edit Free text to text prompt task"].buttons["Edit"].tap() |
| 80 | + } |
| 81 | + |
| 82 | + private func deleteTask() { |
| 83 | + let cell = app.collectionViews.children(matching: .cell).element(boundBy: 0) |
| 84 | + cell.staticTexts[taskInputDeleted].press(forDuration: 2); |
| 85 | + |
| 86 | + let deleteButton = app.buttons["TaskDeleteContextMenu"] |
| 87 | + XCTAssertTrue(deleteButton.waitForExistence(timeout: 2), "Edit button not found in context menu") |
| 88 | + deleteButton.tap() |
| 89 | + |
| 90 | + app.sheets.scrollViews.otherElements.buttons["Delete"].tap() |
| 91 | + } |
| 92 | + |
| 93 | + // MARK: - Tests |
| 94 | + |
| 95 | + func testCreateAssistantTask() async throws { |
| 96 | + goToAssistant() |
| 97 | + |
| 98 | + createTask(input: taskInputCreated) |
| 99 | + |
| 100 | + pullToRefresh() |
| 101 | + |
| 102 | + try await aMoment() |
| 103 | + |
| 104 | + let cell = app.collectionViews.children(matching: .cell).element(boundBy: 0) |
| 105 | + XCTAssert(cell.staticTexts[taskInputCreated].exists) |
| 106 | + } |
| 107 | + |
| 108 | + func testRetryAssistantTask() async throws { |
| 109 | + goToAssistant() |
| 110 | + |
| 111 | + createTask(input: taskInputRetried) |
| 112 | + |
| 113 | + retryTask() |
| 114 | + |
| 115 | + pullToRefresh() |
| 116 | + |
| 117 | + try await aMoment() |
| 118 | + |
| 119 | + let matchingElements = app.collectionViews.cells.staticTexts.matching(identifier: taskInputRetried) |
| 120 | + print(app.collectionViews.staticTexts.debugDescription) |
| 121 | + XCTAssertEqual(matchingElements.count, 2, "Expected 2 elements") |
| 122 | + } |
| 123 | + |
| 124 | + func testEditAssistantTask() async throws { |
| 125 | + goToAssistant() |
| 126 | + |
| 127 | + createTask(input: taskInputToEdit) |
| 128 | + |
| 129 | + editTask() |
| 130 | + |
| 131 | + pullToRefresh() |
| 132 | + |
| 133 | + try await aMoment() |
| 134 | + |
| 135 | + let cell = app.collectionViews.children(matching: .cell).element(boundBy: 0) |
| 136 | + XCTAssert(cell.staticTexts[taskInputToEdit + "Edited"].exists) |
| 137 | + } |
| 138 | + |
| 139 | + func testDeleteAssistantTask() async throws { |
| 140 | + goToAssistant() |
| 141 | + |
| 142 | + createTask(input: taskInputDeleted) |
| 143 | + |
| 144 | + deleteTask() |
| 145 | + |
| 146 | + pullToRefresh() |
| 147 | + |
| 148 | + try await aMoment() |
| 149 | + |
| 150 | + let cell = app.collectionViews.children(matching: .cell).element(boundBy: 0) |
| 151 | + XCTAssert(!cell.staticTexts[taskInputDeleted].exists) |
| 152 | + } |
| 153 | +} |
0 commit comments