diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 2653baa5e..929c041fc 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -143,7 +143,6 @@ 21F29351EDD7B2A5534EE862 /* SecureBackupKeyBackupScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD558A898847C179E4B7A237 /* SecureBackupKeyBackupScreen.swift */; }; 22882C710BC99EC34A5024A0 /* UITestsScreenIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEBE5EA91E8691EDF364EC2 /* UITestsScreenIdentifier.swift */; }; 234E2C782981003971ABE96E /* PermalinkBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F754E66A8970963B15B2A41E /* PermalinkBuilder.swift */; }; - 2352C541AF857241489756FF /* MockRoomSummaryProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F7D42E66E939B709C1EC390 /* MockRoomSummaryProvider.swift */; }; 23701DE32ACD6FD40AA992C3 /* MediaUploadingPreprocessorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE203026B9AD3DB412439866 /* MediaUploadingPreprocessorTests.swift */; }; 237FC70AA257B935F53316BA /* SessionVerificationControllerProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55D7E514F9DE4E3D72FDCAD /* SessionVerificationControllerProxy.swift */; }; 245F7FE5961BD10C145A26E0 /* UITimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EA689E792E679F5E3956F21 /* UITimelineView.swift */; }; @@ -733,6 +732,7 @@ B53D292A5CA61E371C4CD785 /* GenericCallLinkCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 514923AA9640C34F39E0500A /* GenericCallLinkCoordinator.swift */; }; B5479997ECC516C121E6625E /* LocationMarkerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFECCE59967018204876D0A5 /* LocationMarkerView.swift */; }; B5618E3C948584E5C1F67033 /* DTHTMLElement+AttributedStringBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E508AB0EDEE017FF4F6F8D1 /* DTHTMLElement+AttributedStringBuilder.swift */; }; + B5899F18AD6C56CE08FE532B /* RoomSummaryProviderMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC83F47D2173B7538AA72E0E /* RoomSummaryProviderMock.swift */; }; B5903E48CF43259836BF2DBF /* EncryptedRoomTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C1BCB9E83B09A45387FCA2 /* EncryptedRoomTimelineView.swift */; }; B5E455C9689EA600EDB3E9E0 /* NavigationRootCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA28F29C9F93E93CC3C2C715 /* NavigationRootCoordinator.swift */; }; B6048166B4AA4CEFEA9B77A6 /* InfoPlistReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A580295A56B55A856CC4084 /* InfoPlistReader.swift */; }; @@ -1619,7 +1619,6 @@ 8F21ED7205048668BEB44A38 /* AppActivityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppActivityView.swift; sourceTree = ""; }; 8F421E51DF00377DE1A01354 /* CompletionSuggestionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompletionSuggestionView.swift; sourceTree = ""; }; 8F61A0DD8243B395499C99A2 /* InvitesScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvitesScreenUITests.swift; sourceTree = ""; }; - 8F7D42E66E939B709C1EC390 /* MockRoomSummaryProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockRoomSummaryProvider.swift; sourceTree = ""; }; 8FC803282F9268D49F4ABF14 /* AppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinator.swift; sourceTree = ""; }; 90791B9C739C716A40E1B230 /* target.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = target.yml; sourceTree = ""; }; 907FA4DE17DEA1A3738EFB83 /* AudioRecorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRecorder.swift; sourceTree = ""; }; @@ -2044,6 +2043,7 @@ FBB0328F2887BF0A65BC5D49 /* NotificationSettingsEditScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSettingsEditScreen.swift; sourceTree = ""; }; FBC776F301D374A3298C69DA /* AppCoordinatorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinatorProtocol.swift; sourceTree = ""; }; FC2D505742FDA21FCDC4C18A /* AudioRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRoomTimelineView.swift; sourceTree = ""; }; + FC83F47D2173B7538AA72E0E /* RoomSummaryProviderMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomSummaryProviderMock.swift; sourceTree = ""; }; FC853F9B4FBE039D2C16EC6B /* RoomMembersListManageMemberSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMembersListManageMemberSheet.swift; sourceTree = ""; }; FCE93F0CBF0D96B77111C413 /* AppLockFlowCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLockFlowCoordinator.swift; sourceTree = ""; }; FD1275D9CE0FFBA6E8E85426 /* UserIndicatorController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserIndicatorController.swift; sourceTree = ""; }; @@ -2587,6 +2587,7 @@ 36FD673E24FBFCFDF398716A /* RoomMemberProxyMock.swift */, F5D1BAA90F3A073D91B4F16B /* RoomNotificationSettingsProxyMock.swift */, 1ABDE6F66532CBEB0E016F94 /* RoomProxyMock.swift */, + FC83F47D2173B7538AA72E0E /* RoomSummaryProviderMock.swift */, 248649EBA5BC33DB93698734 /* SessionVerificationControllerProxyMock.swift */, 7893780A1FD6E3F38B3E9049 /* UserIndicatorControllerMock.swift */, AAD01F7FC2BBAC7351948595 /* UserProfile+Mock.swift */, @@ -3342,7 +3343,6 @@ 70DABA39C844CA931B829395 /* RoomSummary */ = { isa = PBXGroup; children = ( - 8F7D42E66E939B709C1EC390 /* MockRoomSummaryProvider.swift */, B0A307A44F952CD73E63AE31 /* RoomEventStringBuilder.swift */, 80E815FF3CC5E5A355E3A25E /* RoomMessageEventStringBuilder.swift */, 142808B69851451AC32A2CEA /* RoomSummaryDetails.swift */, @@ -5849,7 +5849,6 @@ C97325EFDCCEE457432A9E82 /* MessageText.swift in Sources */, 152AE2B8650FB23AFD2E28B9 /* MockAuthenticationServiceProxy.swift in Sources */, B659E3A49889E749E3239EA7 /* MockMediaProvider.swift in Sources */, - 2352C541AF857241489756FF /* MockRoomSummaryProvider.swift in Sources */, 09C83DDDB07C28364F325209 /* MockRoomTimelineController.swift in Sources */, 158A2D528CC78C4E7A8ED608 /* MockRoomTimelineControllerFactory.swift in Sources */, B721125D17A0BA86794F29FB /* MockServerSelectionScreenState.swift in Sources */, @@ -6015,6 +6014,7 @@ 6C34237AFB808E38FC8776B9 /* RoomStateEventStringBuilder.swift in Sources */, A7FD7B992E6EE6E5A8429197 /* RoomSummaryDetails.swift in Sources */, 983896D611ABF52A5C37498D /* RoomSummaryProvider.swift in Sources */, + B5899F18AD6C56CE08FE532B /* RoomSummaryProviderMock.swift in Sources */, AA050DF4AEE54A641BA7CA22 /* RoomSummaryProviderProtocol.swift in Sources */, 2ABF11717C64054CEF2819A3 /* RoomTimelineController.swift in Sources */, 38896D54D6D675534E606195 /* RoomTimelineControllerFactory.swift in Sources */, diff --git a/ElementX/Sources/Mocks/ClientProxyMock.swift b/ElementX/Sources/Mocks/ClientProxyMock.swift index fbd97d410..c0365e787 100644 --- a/ElementX/Sources/Mocks/ClientProxyMock.swift +++ b/ElementX/Sources/Mocks/ClientProxyMock.swift @@ -20,7 +20,7 @@ import Foundation struct ClientProxyMockConfiguration { let userID: String var deviceID: String? - var roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider() + var roomSummaryProvider: RoomSummaryProviderProtocol? = RoomSummaryProviderMock(.init()) } extension ClientProxyMock { @@ -33,8 +33,8 @@ extension ClientProxyMock { homeserver = "" roomSummaryProvider = configuration.roomSummaryProvider - alternateRoomSummaryProvider = MockRoomSummaryProvider() - inviteSummaryProvider = MockRoomSummaryProvider() + alternateRoomSummaryProvider = RoomSummaryProviderMock(.init()) + inviteSummaryProvider = RoomSummaryProviderMock(.init()) actionsPublisher = PassthroughSubject().eraseToAnyPublisher() loadingStatePublisher = CurrentValuePublisher(.notLoading) diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index ef6518a44..509ccf76a 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -2973,6 +2973,67 @@ class RoomProxyMock: RoomProxyProtocol { } } } +class RoomSummaryProviderMock: RoomSummaryProviderProtocol { + var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> { + get { return underlyingRoomListPublisher } + set(value) { underlyingRoomListPublisher = value } + } + var underlyingRoomListPublisher: CurrentValuePublisher<[RoomSummary], Never>! + var statePublisher: CurrentValuePublisher { + get { return underlyingStatePublisher } + set(value) { underlyingStatePublisher = value } + } + var underlyingStatePublisher: CurrentValuePublisher! + + //MARK: - setRoomList + + var setRoomListCallsCount = 0 + var setRoomListCalled: Bool { + return setRoomListCallsCount > 0 + } + var setRoomListReceivedRoomList: RoomList? + var setRoomListReceivedInvocations: [RoomList] = [] + var setRoomListClosure: ((RoomList) -> Void)? + + func setRoomList(_ roomList: RoomList) { + setRoomListCallsCount += 1 + setRoomListReceivedRoomList = roomList + setRoomListReceivedInvocations.append(roomList) + setRoomListClosure?(roomList) + } + //MARK: - updateVisibleRange + + var updateVisibleRangeCallsCount = 0 + var updateVisibleRangeCalled: Bool { + return updateVisibleRangeCallsCount > 0 + } + var updateVisibleRangeReceivedRange: Range? + var updateVisibleRangeReceivedInvocations: [Range] = [] + var updateVisibleRangeClosure: ((Range) -> Void)? + + func updateVisibleRange(_ range: Range) { + updateVisibleRangeCallsCount += 1 + updateVisibleRangeReceivedRange = range + updateVisibleRangeReceivedInvocations.append(range) + updateVisibleRangeClosure?(range) + } + //MARK: - setFilter + + var setFilterCallsCount = 0 + var setFilterCalled: Bool { + return setFilterCallsCount > 0 + } + var setFilterReceivedFilter: RoomSummaryProviderFilter? + var setFilterReceivedInvocations: [RoomSummaryProviderFilter] = [] + var setFilterClosure: ((RoomSummaryProviderFilter) -> Void)? + + func setFilter(_ filter: RoomSummaryProviderFilter) { + setFilterCallsCount += 1 + setFilterReceivedFilter = filter + setFilterReceivedInvocations.append(filter) + setFilterClosure?(filter) + } +} class RoomTimelineProviderMock: RoomTimelineProviderProtocol { var updatePublisher: AnyPublisher { get { return underlyingUpdatePublisher } diff --git a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift b/ElementX/Sources/Mocks/RoomSummaryProviderMock.swift similarity index 86% rename from ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift rename to ElementX/Sources/Mocks/RoomSummaryProviderMock.swift index 80d592c5b..2531e9752 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift +++ b/ElementX/Sources/Mocks/RoomSummaryProviderMock.swift @@ -1,5 +1,5 @@ // -// Copyright 2022 New Vector Ltd +// 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. @@ -16,61 +16,55 @@ import Combine import Foundation -import MatrixRustSDK -enum MockRoomSummaryProviderState { +enum RoomSummaryProviderMockConfigurationState { case loading case loaded([RoomSummary]) } -class MockRoomSummaryProvider: RoomSummaryProviderProtocol { - private let initialRooms: [RoomSummary] - private(set) var currentFilter: RoomSummaryProviderFilter? - - private let roomListSubject: CurrentValueSubject<[RoomSummary], Never> - var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> { - roomListSubject.asCurrentValuePublisher() - } - - private let stateSuject: CurrentValueSubject - var statePublisher: CurrentValuePublisher { - stateSuject.asCurrentValuePublisher() - } - - convenience init() { - self.init(state: .loading) - } - - init(state: MockRoomSummaryProviderState) { - switch state { +struct RoomSummaryProviderMockConfiguration { + var state: RoomSummaryProviderMockConfigurationState = .loading +} + +extension RoomSummaryProviderMock { + convenience init(_ configuration: RoomSummaryProviderMockConfiguration) { + self.init() + + let initialRooms: [RoomSummary] + let roomListSubject: CurrentValueSubject<[RoomSummary], Never> + let stateSubject: CurrentValueSubject + + switch configuration.state { case .loading: initialRooms = [] roomListSubject = .init(initialRooms) - roomListSubject.send(initialRooms) - stateSuject = .init(.notLoaded) + stateSubject = .init(.notLoaded) case .loaded(let rooms): initialRooms = rooms roomListSubject = .init(initialRooms) - roomListSubject.send(initialRooms) - stateSuject = .init(.loaded(totalNumberOfRooms: UInt(initialRooms.count))) + stateSubject = .init(.loaded(totalNumberOfRooms: UInt(rooms.count))) } - } - - func setRoomList(_ roomList: RoomList) { } - - func updateVisibleRange(_ range: Range) { } - - func setFilter(_ filter: RoomSummaryProviderFilter) { - currentFilter = filter - switch filter { - case let .include(predicate): - if let query = predicate.query, !query.isEmpty { - roomListSubject.send(initialRooms.filter { $0.name?.localizedCaseInsensitiveContains(query) ?? false }) - } else { - roomListSubject.send(initialRooms) + + roomListPublisher = roomListSubject.asCurrentValuePublisher() + statePublisher = stateSubject.asCurrentValuePublisher() + + setFilterClosure = { [initialRooms, roomListSubject] filter in + switch filter { + case let .include(predicate): + var rooms = initialRooms + + if let filter = predicate.filters.first { + rooms = rooms.filter { filter == .people ? $0.isDirect : !$0.isDirect } + } + + if let query = predicate.query, !query.isEmpty { + rooms = rooms.filter { $0.name?.localizedCaseInsensitiveContains(query) ?? false } + } + + roomListSubject.send(rooms) + case .excludeAll: + roomListSubject.send([]) } - case .excludeAll: - roomListSubject.send([]) } } } @@ -79,7 +73,7 @@ extension Array where Element == RoomSummary { static let mockRooms: [Element] = [ .filled(details: RoomSummaryDetails(id: "1", name: "Foundation 🔭🪐🌌", - isDirect: true, + isDirect: false, avatarURL: nil, lastMessage: AttributedString("I do not wish to take the trouble to understand mysticism"), lastMessageFormattedTimestamp: "14:56", @@ -94,7 +88,7 @@ extension Array where Element == RoomSummary { isFavourite: false)), .filled(details: RoomSummaryDetails(id: "2", name: "Foundation and Empire", - isDirect: true, + isDirect: false, avatarURL: URL.picturesDirectory, lastMessage: AttributedString("How do you see the Emperor then? You think he keeps office hours?"), lastMessageFormattedTimestamp: "2:56 PM", @@ -109,7 +103,7 @@ extension Array where Element == RoomSummary { isFavourite: false)), .filled(details: RoomSummaryDetails(id: "3", name: "Second Foundation", - isDirect: true, + isDirect: false, avatarURL: nil, lastMessage: try? AttributedString(markdown: "He certainly seemed no *mental genius* to me"), lastMessageFormattedTimestamp: "Some time ago", @@ -124,7 +118,7 @@ extension Array where Element == RoomSummary { isFavourite: false)), .filled(details: RoomSummaryDetails(id: "4", name: "Foundation's Edge", - isDirect: true, + isDirect: false, avatarURL: nil, lastMessage: AttributedString("There's an archaic measure of time that's called the month"), lastMessageFormattedTimestamp: "Just now", diff --git a/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreen.swift b/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreen.swift index 23be0e2e1..a045956f9 100644 --- a/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreen.swift +++ b/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreen.swift @@ -210,7 +210,7 @@ private class GlobalSearchTextField: UITextField { // MARK: - Previews struct GlobalSearchScreen_Previews: PreviewProvider, TestablePreview { - static let viewModel = GlobalSearchScreenViewModel(roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)), + static let viewModel = GlobalSearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))), imageProvider: MockMediaProvider()) static var previews: some View { diff --git a/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreenCell.swift b/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreenCell.swift index 26e180f0c..1bb47c656 100644 --- a/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreenCell.swift +++ b/ElementX/Sources/Screens/GlobalSearchScreen/View/GlobalSearchScreenCell.swift @@ -47,7 +47,7 @@ struct GlobalSearchScreenListRow: View { } struct GlobalSearchScreenListRow_Previews: PreviewProvider, TestablePreview { - static let viewModel = GlobalSearchScreenViewModel(roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)), + static let viewModel = GlobalSearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))), imageProvider: MockMediaProvider()) static var previews: some View { diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift index 36a899507..bedbacb36 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift @@ -231,7 +231,7 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview { let appSettings = AppSettings() // This uses shared storage under the hood appSettings.migratedAccounts[userID] = mode != .migration - let roomSummaryProviderState: MockRoomSummaryProviderState = switch mode { + let roomSummaryProviderState: RoomSummaryProviderMockConfigurationState = switch mode { case .migration: .loading case .skeletons: @@ -243,7 +243,7 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview { } let clientProxy = ClientProxyMock(.init(userID: userID, - roomSummaryProvider: MockRoomSummaryProvider(state: roomSummaryProviderState))) + roomSummaryProvider: RoomSummaryProviderMock(.init(state: roomSummaryProviderState)))) let userSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift index 284b8ad52..e724f8a64 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenEmptyStateView.swift @@ -150,7 +150,7 @@ struct HomeScreenEmptyStateView_Previews: PreviewProvider, TestablePreview { static let viewModel = { let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@user:example.com", - roomSummaryProvider: MockRoomSummaryProvider(state: .loaded([])))), + roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded([]))))), mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock()) diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift index f4e09cb14..fc5f5df26 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRecoveryKeyConfirmationBanner.swift @@ -66,7 +66,7 @@ struct HomeScreenRecoveryKeyConfirmationBanner_Previews: PreviewProvider, Testab static func buildViewModel() -> HomeScreenViewModel { let clientProxy = ClientProxyMock(.init(userID: "@alice:example.com", - roomSummaryProvider: MockRoomSummaryProvider(state: .loading))) + roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loading)))) let userSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift index 5f0c2645b..f756c9cc3 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift @@ -174,7 +174,7 @@ private extension View { } struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview { - static let summaryProviderGeneric = MockRoomSummaryProvider(state: .loaded(.mockRooms)) + static let summaryProviderGeneric = RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))) static let viewModelGeneric = { let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: summaryProviderGeneric)), mediaProvider: MockMediaProvider(), @@ -187,7 +187,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview { userIndicatorController: ServiceLocator.shared.userIndicatorController) }() - static let summaryProviderForNotificationsState = MockRoomSummaryProvider(state: .loaded(.mockRoomsWithNotificationsState)) + static let summaryProviderForNotificationsState = RoomSummaryProviderMock(.init(state: .loaded(.mockRoomsWithNotificationsState))) static let viewModelForNotificationsState = { let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: summaryProviderForNotificationsState)), mediaProvider: MockMediaProvider(), diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenSessionVerificationBanner.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenSessionVerificationBanner.swift index de1dfa9ce..681cade60 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenSessionVerificationBanner.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenSessionVerificationBanner.swift @@ -66,7 +66,7 @@ struct HomeScreenSessionVerificationBanner_Previews: PreviewProvider, TestablePr static func buildViewModel() -> HomeScreenViewModel { let clientProxy = ClientProxyMock(.init(userID: "@alice:example.com", - roomSummaryProvider: MockRoomSummaryProvider(state: .loading))) + roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loading)))) let userSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), diff --git a/ElementX/Sources/Screens/InvitesScreen/View/InvitesScreen.swift b/ElementX/Sources/Screens/InvitesScreen/View/InvitesScreen.swift index 410853534..84a1a22d3 100644 --- a/ElementX/Sources/Screens/InvitesScreen/View/InvitesScreen.swift +++ b/ElementX/Sources/Screens/InvitesScreen/View/InvitesScreen.swift @@ -92,8 +92,8 @@ private extension InvitesScreenViewModel { static let someInvite: InvitesScreenViewModel = { let clientProxy = ClientProxyMock(.init(userID: "@userid:example.com")) - clientProxy.inviteSummaryProvider = MockRoomSummaryProvider(state: .loaded(.mockInvites)) - clientProxy.roomSummaryProvider = MockRoomSummaryProvider(state: .loaded(.mockInvites)) + clientProxy.inviteSummaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockInvites))) + clientProxy.roomSummaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockInvites))) let userSession = MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock()) diff --git a/ElementX/Sources/Screens/MessageForwardingScreen/View/MessageForwardingScreen.swift b/ElementX/Sources/Screens/MessageForwardingScreen/View/MessageForwardingScreen.swift index e71495be2..c594a930b 100644 --- a/ElementX/Sources/Screens/MessageForwardingScreen/View/MessageForwardingScreen.swift +++ b/ElementX/Sources/Screens/MessageForwardingScreen/View/MessageForwardingScreen.swift @@ -103,7 +103,7 @@ private struct MessageForwardingListRow: View { struct MessageForwardingScreen_Previews: PreviewProvider, TestablePreview { static var previews: some View { - let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockRooms)) + let summaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))) let viewModel = MessageForwardingScreenViewModel(roomSummaryProvider: summaryProvider, mediaProvider: MockMediaProvider(), sourceRoomID: "") diff --git a/ElementX/Sources/Screens/Settings/NotificationSettingsEditScreen/View/NotificationSettingsEditScreen.swift b/ElementX/Sources/Screens/Settings/NotificationSettingsEditScreen/View/NotificationSettingsEditScreen.swift index 8ba7d8d62..e5bdb2bb7 100644 --- a/ElementX/Sources/Screens/Settings/NotificationSettingsEditScreen/View/NotificationSettingsEditScreen.swift +++ b/ElementX/Sources/Screens/Settings/NotificationSettingsEditScreen/View/NotificationSettingsEditScreen.swift @@ -74,7 +74,7 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.compactMap(\.id) let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com", - roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))), + roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))))), mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock()) var viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat, @@ -89,7 +89,7 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .mentionsAndKeywordsOnly notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [] let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com", - roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))), + roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))))), mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock()) var viewModel = NotificationSettingsEditScreenViewModel(chatType: .oneToOneChat, @@ -121,7 +121,7 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.compactMap(\.id) let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com", - roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))), + roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))))), mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock()) var viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat, diff --git a/ElementX/Sources/Screens/Settings/NotificationSettingsEditScreen/View/NotificationSettingsEditScreenRoomCell.swift b/ElementX/Sources/Screens/Settings/NotificationSettingsEditScreen/View/NotificationSettingsEditScreenRoomCell.swift index 9ea5c6b19..20eda253a 100644 --- a/ElementX/Sources/Screens/Settings/NotificationSettingsEditScreen/View/NotificationSettingsEditScreenRoomCell.swift +++ b/ElementX/Sources/Screens/Settings/NotificationSettingsEditScreen/View/NotificationSettingsEditScreenRoomCell.swift @@ -59,7 +59,7 @@ struct NotificationSettingsEditScreenRoomCell: View { struct NotificationSettingsEditScreenRoomCell_Previews: PreviewProvider, TestablePreview { static var previews: some View { - let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockRooms)) + let summaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))) let userSession = MockUserSession(clientProxy: ClientProxyMock(.init(userID: "John Doe", roomSummaryProvider: summaryProvider)), mediaProvider: MockMediaProvider(), diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift index f8a335050..1354d0ee1 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift @@ -64,6 +64,15 @@ enum RoomSummary: CustomStringConvertible, Equatable { } } + var isDirect: Bool { + switch self { + case .empty: + return false + case .invalidated(let details), .filled(let details): + return details.isDirect + } + } + var description: String { switch self { case .empty: @@ -111,6 +120,7 @@ enum RoomSummaryProviderFilter: Equatable { case include(Predicate) } +// sourcery: AutoMockable protocol RoomSummaryProviderProtocol { /// Publishes the currently available room summaries var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> { get } diff --git a/ElementX/Sources/UITests/UITestsAppCoordinator.swift b/ElementX/Sources/UITests/UITestsAppCoordinator.swift index 3299705a4..a8daea857 100644 --- a/ElementX/Sources/UITests/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITests/UITestsAppCoordinator.swift @@ -560,7 +560,7 @@ class MockScreen: Identifiable { appSettings.richTextEditorEnabled = id == .userSessionScreenRTE let navigationSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: PlaceholderScreenCoordinator()) - let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com", roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))) + let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))))) ServiceLocator.shared.settings.migratedAccounts[clientProxy.userID] = true ServiceLocator.shared.settings.hasShownWelcomeScreen = true @@ -820,7 +820,7 @@ class MockScreen: Identifiable { } } - let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockInvites)) + let summaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockInvites))) clientProxy.inviteSummaryProvider = summaryProvider let coordinator = InvitesScreenCoordinator(parameters: .init(userSession: MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock()))) @@ -842,7 +842,7 @@ class MockScreen: Identifiable { } } - let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockInvites)) + let summaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockInvites))) clientProxy.inviteSummaryProvider = summaryProvider let coordinator = InvitesScreenCoordinator(parameters: .init(userSession: MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock()))) diff --git a/UnitTests/Sources/GlobalSearchScreenViewModelTests.swift b/UnitTests/Sources/GlobalSearchScreenViewModelTests.swift index e77a173ba..3f796a25f 100644 --- a/UnitTests/Sources/GlobalSearchScreenViewModelTests.swift +++ b/UnitTests/Sources/GlobalSearchScreenViewModelTests.swift @@ -27,7 +27,7 @@ class GlobalSearchScreenViewModelTests: XCTestCase { override func setUpWithError() throws { cancellables.removeAll() - viewModel = GlobalSearchScreenViewModel(roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)), + viewModel = GlobalSearchScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))), imageProvider: MockMediaProvider()) context = viewModel.context } diff --git a/UnitTests/Sources/HomeScreenViewModelTests.swift b/UnitTests/Sources/HomeScreenViewModelTests.swift index 510298143..84707e850 100644 --- a/UnitTests/Sources/HomeScreenViewModelTests.swift +++ b/UnitTests/Sources/HomeScreenViewModelTests.swift @@ -25,12 +25,12 @@ class HomeScreenViewModelTests: XCTestCase { var clientProxy: ClientProxyMock! var context: HomeScreenViewModelType.Context! { viewModel.context } var cancellables = Set() - var roomSummaryProvider: MockRoomSummaryProvider! + var roomSummaryProvider: RoomSummaryProviderMock! override func setUpWithError() throws { ServiceLocator.shared.settings.roomListFiltersEnabled = true cancellables.removeAll() - roomSummaryProvider = MockRoomSummaryProvider(state: .loaded(.mockRooms)) + roomSummaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))) clientProxy = ClientProxyMock(.init(userID: "@mock:client.com", roomSummaryProvider: roomSummaryProvider)) viewModel = HomeScreenViewModel(userSession: MockUserSession(clientProxy: clientProxy, mediaProvider: MockMediaProvider(), @@ -169,10 +169,13 @@ class HomeScreenViewModelTests: XCTestCase { func testFilters() async throws { context.filtersState.activateFilter(.people) try await Task.sleep(for: .milliseconds(100)) - XCTAssertEqual(roomSummaryProvider.currentFilter, RoomSummaryProviderFilter.include(.init(filters: [.people]))) + XCTAssertEqual(roomSummaryProvider.roomListPublisher.value.count, 2) + XCTAssertEqual(roomSummaryProvider.roomListPublisher.value.first?.name, "Foundation and Earth") + context.isSearchFieldFocused = true - context.searchQuery = "Test" + context.searchQuery = "lude to Found" try await Task.sleep(for: .milliseconds(100)) - XCTAssertEqual(roomSummaryProvider.currentFilter, RoomSummaryProviderFilter.include(.init(query: "Test", filters: [.people]))) + XCTAssertEqual(roomSummaryProvider.roomListPublisher.value.first?.name, "Prelude to Foundation") + XCTAssertEqual(roomSummaryProvider.roomListPublisher.value.count, 1) } } diff --git a/UnitTests/Sources/InvitesScreenViewModelTests.swift b/UnitTests/Sources/InvitesScreenViewModelTests.swift index 4b4ddbaff..4a73e5ec7 100644 --- a/UnitTests/Sources/InvitesScreenViewModelTests.swift +++ b/UnitTests/Sources/InvitesScreenViewModelTests.swift @@ -98,7 +98,7 @@ class InvitesScreenViewModelTests: XCTestCase { private func setupViewModel(roomSummaries: [RoomSummary]? = nil) { if let roomSummaries { - let summaryProvider = MockRoomSummaryProvider(state: .loaded(roomSummaries)) + let summaryProvider = RoomSummaryProviderMock(.init(state: .loaded(roomSummaries))) clientProxy.inviteSummaryProvider = summaryProvider clientProxy.roomSummaryProvider = summaryProvider } diff --git a/UnitTests/Sources/MessageForwardingScreenViewModelTests.swift b/UnitTests/Sources/MessageForwardingScreenViewModelTests.swift index 76ee52cd1..6372b8ad0 100644 --- a/UnitTests/Sources/MessageForwardingScreenViewModelTests.swift +++ b/UnitTests/Sources/MessageForwardingScreenViewModelTests.swift @@ -27,7 +27,7 @@ class MessageForwardingScreenViewModelTests: XCTestCase { override func setUpWithError() throws { cancellables.removeAll() - viewModel = MessageForwardingScreenViewModel(roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)), + viewModel = MessageForwardingScreenViewModel(roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))), mediaProvider: MockMediaProvider(), sourceRoomID: "1") context = viewModel.context diff --git a/UnitTests/Sources/RoomFlowCoordinatorTests.swift b/UnitTests/Sources/RoomFlowCoordinatorTests.swift index f55587062..81dcb70f1 100644 --- a/UnitTests/Sources/RoomFlowCoordinatorTests.swift +++ b/UnitTests/Sources/RoomFlowCoordinatorTests.swift @@ -27,7 +27,7 @@ class RoomFlowCoordinatorTests: XCTestCase { override func setUp() async throws { cancellables.removeAll() - let clientProxy = ClientProxyMock(.init(userID: "hi@bob", roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms)))) + let clientProxy = ClientProxyMock(.init(userID: "hi@bob", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms))))) let mediaProvider = MockMediaProvider() let voiceMessageMediaManager = VoiceMessageMediaManagerMock() let userSession = MockUserSession(clientProxy: clientProxy,