Beam/UnitTests/Sources/RoomSummaryTests.swift
Mauro a2242c63e2
Render Room and Message Pills (#3809)
* added a way to render the room and the message

pills, but is WIP

* permalinks now get converted into pills!

* fixed an issue where room address mentions

were not adding a URL properly but a string

* updated tests

* c

* Revert "c"

This reverts commit 5c80252fa23dba7e4d44f2a07fbf1e9500e37c82.

* updated tests

* more tests

* created APIs to get a specific RoomSummary

given the id or the alias

* small mention builder improvement

* pr suggestions
2025-02-25 13:46:01 +00:00

77 lines
2.7 KiB
Swift

//
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import XCTest
@testable import ElementX
class RoomSummaryTests: XCTestCase {
// swiftlint:disable:next large_tuple
let roomDetails: (id: String, name: String, avatarURL: URL) = ("room_id", "Room Name", "mxc://hs.tld/room/avatar")
let heroes = [UserProfileProxy(userID: "hero_1", displayName: "Hero 1", avatarURL: "mxc://hs.tld/user/avatar")]
func testRoomAvatar() {
let details = makeSummary(isDirect: false, hasRoomAvatar: true)
switch details.avatar {
case .room(let id, let name, let avatarURL):
XCTAssertEqual(id, roomDetails.id)
XCTAssertEqual(name, roomDetails.name)
XCTAssertEqual(avatarURL, roomDetails.avatarURL)
case .heroes:
XCTFail("A room shouldn't use the heroes for its avatar.")
}
}
func testDMAvatarSet() {
let details = makeSummary(isDirect: true, hasRoomAvatar: true)
switch details.avatar {
case .room(let id, let name, let avatarURL):
XCTAssertEqual(id, roomDetails.id)
XCTAssertEqual(name, roomDetails.name)
XCTAssertEqual(avatarURL, roomDetails.avatarURL)
case .heroes:
XCTFail("A DM with an avatar set shouldn't use the heroes instead.")
}
}
func testDMAvatarNotSet() {
let details = makeSummary(isDirect: true, hasRoomAvatar: false)
switch details.avatar {
case .room:
XCTFail("A DM without an avatar should defer to the hero for the correct placeholder tint colour.")
case .heroes(let heroes):
XCTAssertEqual(heroes, self.heroes)
}
}
// MARK: - Helpers
func makeSummary(isDirect: Bool, hasRoomAvatar: Bool) -> RoomSummary {
RoomSummary(roomListItem: .init(noPointer: .init()),
id: roomDetails.id,
joinRequestType: nil,
name: roomDetails.name,
isDirect: isDirect,
avatarURL: hasRoomAvatar ? roomDetails.avatarURL : nil,
heroes: heroes,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)
}
}