Files
element-x-ios/UnitTests/Sources/RoomSummaryTests.swift
Copilot c41a38159b Only offer joined rooms in the forward and share pickers (#6255)
* Initial plan

* Offer only joined rooms in destination pickers

Co-authored-by: Velin92 <34335419+Velin92@users.noreply.github.com>

* Clean whitespace in share picker test

Co-authored-by: Velin92 <34335419+Velin92@users.noreply.github.com>

* Restrict the shared picker room list to joined rooms

The alternate room summary provider, which backs the forward, share and
Add rooms pickers and global search, now always includes the SDK's
joined filter in its base filter. This replaces the per-call joinedOnly
flags, so Add rooms no longer offers invited rooms or spaces and no
screen can forget the flag.

A filter set before the provider has its room list is now applied once
the list is set, instead of being reset to the default. The share picker
hit this on a cold launch from the share extension.

The forward and share pickers also hide upgraded rooms, matching the
Suggestions section. The SDK has no filter for these.

Also registers the share picker's test file in the project, fixes the
blank-line indentation SwiftFormat flagged, and re-records the picker
snapshots without the upgraded room.

* Check room membership for forwarding suggestions and search breadcrumbs

RoomSummary now has isJoined, built from the room's membership. The
forwarding suggestions and the search breadcrumbs used a missing
joinRequestType to mean joined, which is also the case for rooms that
have been left or banned from. It only worked because the room list's
base filter already drops those.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Velin92 <34335419+Velin92@users.noreply.github.com>
Co-authored-by: Mauro Romito <mauro.romito@element.io>
2026-10-02 12:44:33 +00:00

126 lines
4.6 KiB
Swift

//
// Copyright 2025 Element Creations Ltd.
// Copyright 2024-2025 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.
//
@testable import ElementX
import Foundation
import MatrixRustSDKMocks
import Testing
@MainActor
struct RoomSummaryTests {
// swiftlint:disable:next large_tuple
let roomDetails: (id: String, name: String, avatarURL: URL) = ("room_id", "Room Name", "mxc://hs.tld/room/avatar")
let heroes = [UserProfile(userID: "hero_1", displayName: "Hero 1", avatarURL: "mxc://hs.tld/user/avatar")]
@Test
func roomAvatar() {
let details = makeSummary(isDirect: false, isSpace: false, hasRoomAvatar: true, isTombstoned: false)
switch details.avatar {
case .room(let id, let name, let avatarURL):
#expect(id == roomDetails.id)
#expect(name == roomDetails.name)
#expect(avatarURL == roomDetails.avatarURL)
case .heroes:
Issue.record("A room shouldn't use the heroes for its avatar.")
case .space:
Issue.record("A room shouldn't use a space avatar.")
case .tombstoned:
Issue.record("A room shouldn't use the tombstone for its avatar.")
}
}
@Test
func dmAvatarSet() {
let details = makeSummary(isDirect: true, isSpace: false, hasRoomAvatar: true, isTombstoned: false)
switch details.avatar {
case .room(let id, let name, let avatarURL):
#expect(id == roomDetails.id)
#expect(name == roomDetails.name)
#expect(avatarURL == roomDetails.avatarURL)
case .heroes:
Issue.record("A DM with an avatar set shouldn't use the heroes instead.")
case .space:
Issue.record("A DM shouldn't use a space avatar.")
case .tombstoned:
Issue.record("A room shouldn't use the tombstone for its avatar.")
}
}
@Test
func dmAvatarNotSet() {
let details = makeSummary(isDirect: true, isSpace: false, hasRoomAvatar: false, isTombstoned: false)
switch details.avatar {
case .room:
Issue.record("A DM without an avatar should defer to the hero for the correct placeholder tint colour.")
case .heroes(let heroes):
#expect(heroes == self.heroes)
case .space:
Issue.record("A DM shouldn't use a space avatar.")
case .tombstoned:
Issue.record("A room shouldn't use the tombstone for its avatar.")
}
}
@Test
func spaceAvatar() {
let details = makeSummary(isDirect: false, isSpace: true, hasRoomAvatar: true, isTombstoned: false)
switch details.avatar {
case .room:
Issue.record("A space shouldn't use a room avatar.")
case .heroes:
Issue.record("A room shouldn't use the heroes for its avatar.")
case .space(let id, let name, let avatarURL):
#expect(id == roomDetails.id)
#expect(name == roomDetails.name)
#expect(avatarURL == roomDetails.avatarURL)
case .tombstoned:
Issue.record("A room shouldn't use the tombstone for its avatar.")
}
}
@Test
func tombstonedAvatar() {
let details = makeSummary(isDirect: false, isSpace: false, hasRoomAvatar: true, isTombstoned: true)
#expect(details.avatar == .tombstoned)
}
// MARK: - Helpers
func makeSummary(isDirect: Bool, isSpace: Bool, hasRoomAvatar: Bool, isTombstoned: Bool) -> RoomSummary {
RoomSummary(room: RoomSDKMock(),
id: roomDetails.id,
joinRequestType: nil,
isJoined: true,
name: roomDetails.name,
isDirect: isDirect,
isSpace: isSpace,
avatarURL: hasRoomAvatar ? roomDetails.avatarURL : nil,
heroes: heroes,
activeMembersCount: 0,
lastMessage: nil,
lastMessageDate: nil,
lastMessageState: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: isTombstoned)
}
}