Files
letro-ios/UnitTests/Sources/HomeScreenRoomTests.swift
Stefan Ceriu bc7c76cf3a Use local room list sorting from Rust. (#2978)
* Switch to the new local room list sorting API

* Get rid of the RoomSummary enum, replace it by the inner RoomSummaryDetails

* And finally, rename RoomSummaryDetails to RoomSummary

* Fix a bunch of warnings

* Small tidy up post rebase/review.

- Remove unused invalidated property.
- Rename some RoomSummary instances to summary instead of details.
- Fix tests with missing roomListItem's.

* Update snapshots

---------

Co-authored-by: Doug <douglase@element.io>
2024-07-05 10:10:53 +01:00

242 lines
9.7 KiB
Swift

//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Combine
import XCTest
@testable import ElementX
@MainActor
class HomeScreenRoomTests: XCTestCase {
var roomSummary: RoomSummary!
// swiftlint:disable:next function_parameter_count
func setupRoomSummary(isMarkedUnread: Bool,
unreadMessagesCount: UInt,
unreadMentionsCount: UInt,
unreadNotificationsCount: UInt,
notificationMode: RoomNotificationModeProxy,
hasOngoingCall: Bool) {
roomSummary = RoomSummary(roomListItem: .init(noPointer: .init()),
id: "Test room",
isInvite: false,
inviter: nil,
name: "Test room",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: unreadMessagesCount,
unreadMentionsCount: unreadMentionsCount,
unreadNotificationsCount: unreadNotificationsCount,
notificationMode: notificationMode,
canonicalAlias: nil,
hasOngoingCall: hasOngoingCall,
isMarkedUnread: isMarkedUnread,
isFavourite: false)
}
func testNoBadge() {
setupRoomSummary(isMarkedUnread: false,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
hasOngoingCall: false)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertFalse(room.isHighlighted)
XCTAssertFalse(room.badges.isDotShown)
XCTAssertFalse(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertFalse(room.badges.isMentionShown)
}
func testAllBadgesExceptMute() {
setupRoomSummary(isMarkedUnread: true,
unreadMessagesCount: 5,
unreadMentionsCount: 5,
unreadNotificationsCount: 5,
notificationMode: .allMessages,
hasOngoingCall: true)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
XCTAssertTrue(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertTrue(room.badges.isMentionShown)
}
func testUnhighlightedDot() {
setupRoomSummary(isMarkedUnread: false,
unreadMessagesCount: 5,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
hasOngoingCall: false)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertFalse(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
XCTAssertFalse(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertFalse(room.badges.isMentionShown)
}
func testHighlightedDot() {
setupRoomSummary(isMarkedUnread: false,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 5,
notificationMode: .allMessages,
hasOngoingCall: false)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
XCTAssertFalse(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertFalse(room.badges.isMentionShown)
}
func testHighlightedMentionAndDot() {
setupRoomSummary(isMarkedUnread: false,
unreadMessagesCount: 0,
unreadMentionsCount: 5,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
hasOngoingCall: false)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
XCTAssertFalse(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertTrue(room.badges.isMentionShown)
}
func testUnhighlightedCall() {
setupRoomSummary(isMarkedUnread: false,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
hasOngoingCall: true)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertFalse(room.isHighlighted)
XCTAssertFalse(room.badges.isDotShown)
XCTAssertTrue(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertFalse(room.badges.isMentionShown)
}
func testMentionAndKeywordsUnhighlightedDot() {
setupRoomSummary(isMarkedUnread: false,
unreadMessagesCount: 10,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .mentionsAndKeywordsOnly,
hasOngoingCall: false)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertFalse(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
XCTAssertFalse(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertFalse(room.badges.isMentionShown)
}
func testMentionAndKeywordsUnhighlightedDotHidden() {
setupRoomSummary(isMarkedUnread: false,
unreadMessagesCount: 10,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .mentionsAndKeywordsOnly,
hasOngoingCall: false)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: true)
XCTAssertFalse(room.isHighlighted)
XCTAssertFalse(room.badges.isDotShown)
XCTAssertFalse(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertFalse(room.badges.isMentionShown)
}
// MARK: - Mark unread
func testMarkedUnreadDot() {
setupRoomSummary(isMarkedUnread: true,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
hasOngoingCall: false)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
XCTAssertFalse(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertFalse(room.badges.isMentionShown)
}
func testMarkedUnreadDotAndMention() {
setupRoomSummary(isMarkedUnread: true,
unreadMessagesCount: 0,
unreadMentionsCount: 5,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
hasOngoingCall: false)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
XCTAssertFalse(room.badges.isCallShown)
XCTAssertFalse(room.badges.isMuteShown)
XCTAssertTrue(room.badges.isMentionShown)
}
func testMarkedUnreadMuteDotAndCall() {
setupRoomSummary(isMarkedUnread: true,
unreadMessagesCount: 5,
unreadMentionsCount: 5,
unreadNotificationsCount: 5,
notificationMode: .mute,
hasOngoingCall: true)
let room = HomeScreenRoom(summary: roomSummary, hideUnreadMessagesBadge: false)
XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
XCTAssertTrue(room.badges.isCallShown)
XCTAssertTrue(room.badges.isMuteShown)
XCTAssertFalse(room.badges.isMentionShown)
}
}