123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
- // SPDX-License-Identifier: GPL-3.0-or-later
- //
- import XCTest
- final class UIRoomTest: XCTestCase {
- override func setUpWithError() throws {
- // In UI tests it is usually best to stop immediately when a failure occurs.
- continueAfterFailure = false
- }
- func testCreateConversation() {
- let app = launchAndLogin()
- let newConversationName = "Test conversation"
- self.createConversation(for: app, with: newConversationName)
- let chatNavBar = app.navigationBars["NextcloudTalk.ChatView"]
- // Wait for navigationBar
- XCTAssert(chatNavBar.waitForExistence(timeout: TestConstants.timeoutLong))
- // Wait for titleView
- let chatTitleView = chatNavBar.textViews[newConversationName]
- XCTAssert(chatTitleView.waitForExistence(timeout: TestConstants.timeoutShort))
- // Wait until we joined the room and the call buttons get active
- let voiceCallButton = chatNavBar.buttons["Voice call"]
- XCTAssert(voiceCallButton.waitForExistence(timeout: TestConstants.timeoutShort))
- waitForEnabled(object: voiceCallButton)
- waitForHittable(object: voiceCallButton)
- // Open conversation settings
- chatTitleView.tap()
- // Check if if the name of the conversation is shown
- XCTAssert(app.textFields[newConversationName].waitForExistence(timeout: TestConstants.timeoutLong))
- // Go back to conversation list
- app.navigationBars["Conversation settings"].buttons["Back"].tap()
- chatNavBar.buttons["Back"].tap()
- // Check if the conversation appears in the conversation list
- XCTAssert(app.tables.cells.staticTexts[newConversationName].waitForExistence(timeout: TestConstants.timeoutLong))
- }
- func testDeallocation() {
- let app = launchAndLogin()
- let newConversationName = "DeAllocTest"
- // Create a new test conversion
- self.createConversation(for: app, with: newConversationName)
- // Check if we have one chat view controller allocated
- let predicate = NSPredicate(format: "label CONTAINS[c] %@", "ChatViewController\":1")
- XCTAssert(app.staticTexts.containing(predicate).firstMatch.waitForExistence(timeout: TestConstants.timeoutShort))
- // Send a test message
- let testMessage = "TestMessage"
- let toolbar = app.toolbars["Toolbar"]
- let textView = toolbar.textViews["Write message, @ to mention someone …"]
- XCTAssert(textView.waitForExistence(timeout: TestConstants.timeoutShort))
- textView.tap()
- app.typeText(testMessage)
- let sendMessageButton = toolbar.buttons["Send message"]
- sendMessageButton.tap()
- // Wait for temporary message to be replaced
- XCTAssert(app.images["MessageSent"].waitForExistence(timeout: TestConstants.timeoutShort))
- // Open context menu
- let tables = app.tables
- XCTAssert(tables.staticTexts[TestConstants.username].waitForExistence(timeout: TestConstants.timeoutShort))
- let message = tables.staticTexts[TestConstants.username]
- message.press(forDuration: 2.0)
- // Add a reaction to close the context menu
- let reactionExists = app.staticTexts["👍"].waitForExistence(timeout: TestConstants.timeoutShort)
- if reactionExists {
- app.staticTexts["👍"].tap()
- } else {
- // In case we are testing against a nextcloud version that does not support reactions (<= NC 23)
- // we simply tap the "Reply" button from the context menu
- XCTAssert(app.buttons["Reply"].waitForExistence(timeout: TestConstants.timeoutShort))
- app.buttons["Reply"].tap()
- }
- // Start a call
- let chatNavBar = app.navigationBars["NextcloudTalk.ChatView"]
- let voiceCallButton = chatNavBar.buttons["Voice call"]
- XCTAssert(voiceCallButton.waitForExistence(timeout: TestConstants.timeoutShort))
- waitForEnabled(object: voiceCallButton)
- waitForHittable(object: voiceCallButton)
- voiceCallButton.tap()
- let hangupCallButton = app.buttons["Hang up"]
- XCTAssert(hangupCallButton.waitForExistence(timeout: TestConstants.timeoutShort))
- waitForEnabled(object: hangupCallButton)
- waitForHittable(object: hangupCallButton)
- hangupCallButton.tap()
- // Go back to the main view controller
- XCTAssert(voiceCallButton.waitForExistence(timeout: TestConstants.timeoutShort))
- chatNavBar.buttons["Back"].tap()
- // Check if all chat view controllers are deallocated
- XCTAssert(app.staticTexts["{}"].waitForExistence(timeout: TestConstants.timeoutShort))
- }
- func testChatViewControllerMentions() {
- let app = launchAndLogin()
- let newConversationName = "MentionTest 🇨🇨"
- // Create a new test conversion
- self.createConversation(for: app, with: newConversationName)
- // Select a mention
- let toolbar = app.toolbars["Toolbar"]
- let textView = toolbar.textViews["Write message, @ to mention someone …"]
- XCTAssert(textView.waitForExistence(timeout: TestConstants.timeoutShort))
- textView.tap()
- textView.typeText("@")
- textView.typeText("M")
- textView.typeText("e")
- let predicate = NSPredicate(format: "label CONTAINS[c] %@", newConversationName)
- let autoCompleteCell = app.tables.cells["AutoCompletionCellIdentifier"].staticTexts.containing(predicate).firstMatch
- XCTAssert(autoCompleteCell.waitForExistence(timeout: TestConstants.timeoutShort))
- autoCompleteCell.tap()
- // Check if the mention was correctly inserted in the textView
- XCTAssertEqual(textView.value as? String ?? "", "@\(newConversationName) ")
- // Remove the mention again
- textView.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 2))
- // Check if the input field is now empty
- XCTAssertEqual(textView.value as? String ?? "", "")
- }
- func testLobbyView() {
- let app = launchAndLogin()
- let lobbyCell = app.tables.cells.staticTexts["LobbyTest"]
- XCTAssert(lobbyCell.waitForExistence(timeout: TestConstants.timeoutShort))
- lobbyCell.tap()
- // Seems we can't access the backgroundView of a UITableView from the UITests
- // let lobbyText = app.staticTexts["You are currently waiting in the lobby"]
- // Check that the table has no rows
- let tables = app.tables.firstMatch
- XCTAssert(tables.waitForExistence(timeout: TestConstants.timeoutShort))
- XCTAssertEqual(tables.tableRows.count, 0)
- // Check that there's no activity indicator
- XCTAssertEqual(app.activityIndicators.count, 0)
- let shareButton = app.buttons["Share a file from your Nextcloud"]
- XCTAssert(!shareButton.exists)
- // Check that there's no inputbar
- let toolbar = app.toolbars["Toolbar"]
- let textView = toolbar.textViews["Write message, @ to mention someone …"]
- XCTAssert(!textView.exists)
- }
- }
|