UIRoomTest.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. // SPDX-License-Identifier: GPL-3.0-or-later
  4. //
  5. import XCTest
  6. final class UIRoomTest: XCTestCase {
  7. override func setUpWithError() throws {
  8. // In UI tests it is usually best to stop immediately when a failure occurs.
  9. continueAfterFailure = false
  10. }
  11. func testCreateConversation() {
  12. let app = launchAndLogin()
  13. let newConversationName = "Test conversation"
  14. self.createConversation(for: app, with: newConversationName)
  15. let chatNavBar = app.navigationBars["NextcloudTalk.ChatView"]
  16. // Wait for navigationBar
  17. XCTAssert(chatNavBar.waitForExistence(timeout: TestConstants.timeoutLong))
  18. // Wait for titleView
  19. let chatTitleView = chatNavBar.textViews[newConversationName]
  20. XCTAssert(chatTitleView.waitForExistence(timeout: TestConstants.timeoutShort))
  21. // Wait until we joined the room and the call buttons get active
  22. let voiceCallButton = chatNavBar.buttons["Voice call"]
  23. XCTAssert(voiceCallButton.waitForExistence(timeout: TestConstants.timeoutShort))
  24. waitForEnabled(object: voiceCallButton)
  25. waitForHittable(object: voiceCallButton)
  26. // Open conversation settings
  27. chatTitleView.tap()
  28. // Check if if the name of the conversation is shown
  29. XCTAssert(app.textFields[newConversationName].waitForExistence(timeout: TestConstants.timeoutLong))
  30. // Go back to conversation list
  31. app.navigationBars["Conversation settings"].buttons["Back"].tap()
  32. chatNavBar.buttons["Back"].tap()
  33. // Check if the conversation appears in the conversation list
  34. XCTAssert(app.tables.cells.staticTexts[newConversationName].waitForExistence(timeout: TestConstants.timeoutLong))
  35. }
  36. func testDeallocation() {
  37. let app = launchAndLogin()
  38. let newConversationName = "DeAllocTest"
  39. // Create a new test conversion
  40. self.createConversation(for: app, with: newConversationName)
  41. // Check if we have one chat view controller allocated
  42. let predicate = NSPredicate(format: "label CONTAINS[c] %@", "ChatViewController\":1")
  43. XCTAssert(app.staticTexts.containing(predicate).firstMatch.waitForExistence(timeout: TestConstants.timeoutShort))
  44. // Send a test message
  45. let testMessage = "TestMessage"
  46. let toolbar = app.toolbars["Toolbar"]
  47. let textView = toolbar.textViews["Write message, @ to mention someone …"]
  48. XCTAssert(textView.waitForExistence(timeout: TestConstants.timeoutShort))
  49. textView.tap()
  50. app.typeText(testMessage)
  51. let sendMessageButton = toolbar.buttons["Send message"]
  52. sendMessageButton.tap()
  53. // Wait for temporary message to be replaced
  54. XCTAssert(app.images["MessageSent"].waitForExistence(timeout: TestConstants.timeoutShort))
  55. // Open context menu
  56. let tables = app.tables
  57. XCTAssert(tables.staticTexts[TestConstants.username].waitForExistence(timeout: TestConstants.timeoutShort))
  58. let message = tables.staticTexts[TestConstants.username]
  59. message.press(forDuration: 2.0)
  60. // Add a reaction to close the context menu
  61. let reactionExists = app.staticTexts["👍"].waitForExistence(timeout: TestConstants.timeoutShort)
  62. if reactionExists {
  63. app.staticTexts["👍"].tap()
  64. } else {
  65. // In case we are testing against a nextcloud version that does not support reactions (<= NC 23)
  66. // we simply tap the "Reply" button from the context menu
  67. XCTAssert(app.buttons["Reply"].waitForExistence(timeout: TestConstants.timeoutShort))
  68. app.buttons["Reply"].tap()
  69. }
  70. // Start a call
  71. let chatNavBar = app.navigationBars["NextcloudTalk.ChatView"]
  72. let voiceCallButton = chatNavBar.buttons["Voice call"]
  73. XCTAssert(voiceCallButton.waitForExistence(timeout: TestConstants.timeoutShort))
  74. waitForEnabled(object: voiceCallButton)
  75. waitForHittable(object: voiceCallButton)
  76. voiceCallButton.tap()
  77. let hangupCallButton = app.buttons["Hang up"]
  78. XCTAssert(hangupCallButton.waitForExistence(timeout: TestConstants.timeoutShort))
  79. waitForEnabled(object: hangupCallButton)
  80. waitForHittable(object: hangupCallButton)
  81. hangupCallButton.tap()
  82. // Go back to the main view controller
  83. XCTAssert(voiceCallButton.waitForExistence(timeout: TestConstants.timeoutShort))
  84. chatNavBar.buttons["Back"].tap()
  85. // Check if all chat view controllers are deallocated
  86. XCTAssert(app.staticTexts["{}"].waitForExistence(timeout: TestConstants.timeoutShort))
  87. }
  88. func testChatViewControllerMentions() {
  89. let app = launchAndLogin()
  90. let newConversationName = "MentionTest 🇨🇨"
  91. // Create a new test conversion
  92. self.createConversation(for: app, with: newConversationName)
  93. // Select a mention
  94. let toolbar = app.toolbars["Toolbar"]
  95. let textView = toolbar.textViews["Write message, @ to mention someone …"]
  96. XCTAssert(textView.waitForExistence(timeout: TestConstants.timeoutShort))
  97. textView.tap()
  98. textView.typeText("@")
  99. textView.typeText("M")
  100. textView.typeText("e")
  101. let predicate = NSPredicate(format: "label CONTAINS[c] %@", newConversationName)
  102. let autoCompleteCell = app.tables.cells["AutoCompletionCellIdentifier"].staticTexts.containing(predicate).firstMatch
  103. XCTAssert(autoCompleteCell.waitForExistence(timeout: TestConstants.timeoutShort))
  104. autoCompleteCell.tap()
  105. // Check if the mention was correctly inserted in the textView
  106. XCTAssertEqual(textView.value as? String ?? "", "@\(newConversationName) ")
  107. // Remove the mention again
  108. textView.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 2))
  109. // Check if the input field is now empty
  110. XCTAssertEqual(textView.value as? String ?? "", "")
  111. }
  112. func testLobbyView() {
  113. let app = launchAndLogin()
  114. let lobbyCell = app.tables.cells.staticTexts["LobbyTest"]
  115. XCTAssert(lobbyCell.waitForExistence(timeout: TestConstants.timeoutShort))
  116. lobbyCell.tap()
  117. // Seems we can't access the backgroundView of a UITableView from the UITests
  118. // let lobbyText = app.staticTexts["You are currently waiting in the lobby"]
  119. // Check that the table has no rows
  120. let tables = app.tables.firstMatch
  121. XCTAssert(tables.waitForExistence(timeout: TestConstants.timeoutShort))
  122. XCTAssertEqual(tables.tableRows.count, 0)
  123. // Check that there's no activity indicator
  124. XCTAssertEqual(app.activityIndicators.count, 0)
  125. let shareButton = app.buttons["Share a file from your Nextcloud"]
  126. XCTAssert(!shareButton.exists)
  127. // Check that there's no inputbar
  128. let toolbar = app.toolbars["Toolbar"]
  129. let textView = toolbar.textViews["Write message, @ to mention someone …"]
  130. XCTAssert(!textView.exists)
  131. }
  132. }