Skip to content

Commit

Permalink
Add tests for joining with an empty room object
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Sep 22, 2024
1 parent 5062096 commit b43d72c
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion NextcloudTalkTests/Unit/Chat/UnitChatViewControllerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import XCTest

final class UnitChatViewControllerTest: TestBaseRealm {

func testLocalMention() throws {
func testExpireMessages() throws {
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
let roomName = "Expire Messages Test Room"
let roomToken = "expToken"
Expand Down Expand Up @@ -69,6 +69,50 @@ final class UnitChatViewControllerTest: TestBaseRealm {
XCTAssertEqual(NCChatMessage.allObjects().count, 0)
}

func testJoinRoomWithEmptyRoomObject() throws {
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
let roomName = "EmptyRoomObject"
let roomToken = "emptyRoomObject"

let room = NCRoom()
room.token = roomToken
room.name = roomName
room.accountId = activeAccount.accountId

try? realm.transaction {
realm.add(room)
}

let chatViewController = ChatViewController(for: room)!

expectation(forNotification: .NCRoomsManagerDidJoinRoom, object: nil) { notification -> Bool in
XCTAssertNil(notification.userInfo?["error"])

// swiftlint:disable:next force_cast
XCTAssertEqual(notification.userInfo?["token"] as! String, roomToken)

return true
}

let userInfo: [String: Any] = [
"token": roomToken,
"room": NCRoom()
]

NotificationCenter.default.post(name: .NCRoomsManagerDidJoinRoom, object: self, userInfo: userInfo)

waitForExpectations(timeout: TestConstants.timeoutShort, handler: nil)

let exp = expectation(description: "\(#function)\(#line)")

DispatchQueue.main.async {
XCTAssertNotNil(chatViewController.room.token)
exp.fulfill()
}

waitForExpectations(timeout: TestConstants.timeoutShort, handler: nil)
}

func testFrequentlyEmojis() throws {
var activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
XCTAssertEqual(activeAccount.frequentlyUsedEmojis, ["👍", "❤️", "😂", "😅"])
Expand Down

0 comments on commit b43d72c

Please sign in to comment.