From 92d5edea68730a011547bf52b0f58d54864a7437 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 16 Oct 2024 18:14:55 +0300 Subject: [PATCH] Fix unit tests --- ElementX/Sources/Mocks/SDK/ClientSDKMock.swift | 2 +- UnitTests/Sources/LoggingTests.swift | 12 ++++++------ UnitTests/Sources/RoomScreenViewModelTests.swift | 16 ++++++++-------- UnitTests/Sources/TimelineItemFactoryTests.swift | 2 +- UnitTests/Sources/TimelineViewModelTests.swift | 7 ++++--- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/ElementX/Sources/Mocks/SDK/ClientSDKMock.swift b/ElementX/Sources/Mocks/SDK/ClientSDKMock.swift index 61738a095f..29e80bd3dc 100644 --- a/ElementX/Sources/Mocks/SDK/ClientSDKMock.swift +++ b/ElementX/Sources/Mocks/SDK/ClientSDKMock.swift @@ -42,7 +42,7 @@ extension ClientSDKMock { userIdServerNameThrowableError = MockError.generic serverReturnValue = "https://\(configuration.serverAddress)" getUrlUrlReturnValue = configuration.elementWellKnown - urlForOidcLoginOidcConfigurationReturnValue = OidcAuthorizationDataSDKMock(configuration: configuration) + urlForOidcOidcConfigurationPromptReturnValue = OidcAuthorizationDataSDKMock(configuration: configuration) loginUsernamePasswordInitialDeviceNameDeviceIdClosure = { username, password, _, _ in guard username == configuration.validCredentials.username, password == configuration.validCredentials.password else { diff --git a/UnitTests/Sources/LoggingTests.swift b/UnitTests/Sources/LoggingTests.swift index 6887809a5a..20205e5209 100644 --- a/UnitTests/Sources/LoggingTests.swift +++ b/UnitTests/Sources/LoggingTests.swift @@ -195,25 +195,25 @@ class LoggingTests: XCTestCase { } let content = try String(contentsOf: logFile) - XCTAssertTrue(content.contains(textMessage.id.uniqueID)) + XCTAssertTrue(content.contains(textMessage.id.uniqueID.id)) XCTAssertFalse(content.contains(textMessage.body)) XCTAssertFalse(content.contains(textAttributedString)) - XCTAssertTrue(content.contains(noticeMessage.id.uniqueID)) + XCTAssertTrue(content.contains(noticeMessage.id.uniqueID.id)) XCTAssertFalse(content.contains(noticeMessage.body)) XCTAssertFalse(content.contains(noticeAttributedString)) - XCTAssertTrue(content.contains(emoteMessage.id.uniqueID)) + XCTAssertTrue(content.contains(emoteMessage.id.uniqueID.id)) XCTAssertFalse(content.contains(emoteMessage.body)) XCTAssertFalse(content.contains(emoteAttributedString)) - XCTAssertTrue(content.contains(imageMessage.id.uniqueID)) + XCTAssertTrue(content.contains(imageMessage.id.uniqueID.id)) XCTAssertFalse(content.contains(imageMessage.body)) - XCTAssertTrue(content.contains(videoMessage.id.uniqueID)) + XCTAssertTrue(content.contains(videoMessage.id.uniqueID.id)) XCTAssertFalse(content.contains(videoMessage.body)) - XCTAssertTrue(content.contains(fileMessage.id.uniqueID)) + XCTAssertTrue(content.contains(fileMessage.id.uniqueID.id)) XCTAssertFalse(content.contains(fileMessage.body)) } diff --git a/UnitTests/Sources/RoomScreenViewModelTests.swift b/UnitTests/Sources/RoomScreenViewModelTests.swift index 43b8cf10c9..e21891bb43 100644 --- a/UnitTests/Sources/RoomScreenViewModelTests.swift +++ b/UnitTests/Sources/RoomScreenViewModelTests.swift @@ -69,8 +69,8 @@ class RoomScreenViewModelTests: XCTestCase { let providerUpdateSubject = PassthroughSubject<([TimelineItemProxy], PaginationState), Never>() pinnedTimelineProviderMock.underlyingUpdatePublisher = providerUpdateSubject.eraseToAnyPublisher() pinnedTimelineMock.timelineProvider = pinnedTimelineProviderMock - pinnedTimelineProviderMock.itemProxies = [.event(.init(item: EventTimelineItem(configuration: .init(eventID: "test1")), uniqueID: "1")), - .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test2")), uniqueID: "2"))] + pinnedTimelineProviderMock.itemProxies = [.event(.init(item: EventTimelineItem(configuration: .init(eventID: "test1")), uniqueID: .init(id: "1"))), + .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test2")), uniqueID: .init(id: "2")))] // check if the banner is now in a loaded state and is showing the counter deferred = deferFulfillment(viewModel.context.$viewState) { viewState in @@ -86,9 +86,9 @@ class RoomScreenViewModelTests: XCTestCase { deferred = deferFulfillment(viewModel.context.$viewState) { viewState in viewState.pinnedEventsBannerState.count == 3 } - providerUpdateSubject.send(([.event(.init(item: EventTimelineItem(configuration: .init(eventID: "test1")), uniqueID: "1")), - .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test2")), uniqueID: "2")), - .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test3")), uniqueID: "3"))], .initial)) + providerUpdateSubject.send(([.event(.init(item: EventTimelineItem(configuration: .init(eventID: "test1")), uniqueID: .init(id: "1"))), + .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test2")), uniqueID: .init(id: "2"))), + .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test3")), uniqueID: .init(id: "3")))], .initial)) try await deferred.fulfill() XCTAssertFalse(viewModel.context.viewState.pinnedEventsBannerState.isLoading) XCTAssertTrue(viewModel.context.viewState.shouldShowPinnedEventsBanner) @@ -109,9 +109,9 @@ class RoomScreenViewModelTests: XCTestCase { let pinnedTimelineProviderMock = RoomTimelineProviderMock() pinnedTimelineMock.timelineProvider = pinnedTimelineProviderMock pinnedTimelineProviderMock.underlyingUpdatePublisher = Empty<([TimelineItemProxy], PaginationState), Never>().eraseToAnyPublisher() - pinnedTimelineProviderMock.itemProxies = [.event(.init(item: EventTimelineItem(configuration: .init(eventID: "test1")), uniqueID: "1")), - .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test2")), uniqueID: "2")), - .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test3")), uniqueID: "3"))] + pinnedTimelineProviderMock.itemProxies = [.event(.init(item: EventTimelineItem(configuration: .init(eventID: "test1")), uniqueID: .init(id: "1"))), + .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test2")), uniqueID: .init(id: "2"))), + .event(.init(item: EventTimelineItem(configuration: .init(eventID: "test3")), uniqueID: .init(id: "3")))] roomProxyMock.underlyingPinnedEventsTimeline = pinnedTimelineMock let viewModel = RoomScreenViewModel(clientProxy: ClientProxyMock(), roomProxy: roomProxyMock, diff --git a/UnitTests/Sources/TimelineItemFactoryTests.swift b/UnitTests/Sources/TimelineItemFactoryTests.swift index 0ca14f8fac..9033adda4e 100644 --- a/UnitTests/Sources/TimelineItemFactoryTests.swift +++ b/UnitTests/Sources/TimelineItemFactoryTests.swift @@ -22,7 +22,7 @@ class TimelineItemFactoryTests: XCTestCase { let eventTimelineItem = EventTimelineItem.mockCallInvite(sender: senderUserID) - let eventTimelineItemProxy = EventTimelineItemProxy(item: eventTimelineItem, uniqueID: "0") + let eventTimelineItemProxy = EventTimelineItemProxy(item: eventTimelineItem, uniqueID: .init(id: "0")) let item = factory.buildTimelineItem(for: eventTimelineItemProxy, isDM: false) diff --git a/UnitTests/Sources/TimelineViewModelTests.swift b/UnitTests/Sources/TimelineViewModelTests.swift index f0b4765544..d0a95e8131 100644 --- a/UnitTests/Sources/TimelineViewModelTests.swift +++ b/UnitTests/Sources/TimelineViewModelTests.swift @@ -8,6 +8,7 @@ @testable import ElementX import Combine +import MatrixRustSDK import XCTest @MainActor @@ -275,7 +276,7 @@ class TimelineViewModelTests: XCTestCase { // Given a room where the last event is a virtual item. let items: [RoomTimelineItemProtocol] = [TextRoomTimelineItem(eventID: "t1"), TextRoomTimelineItem(eventID: "t2"), - SeparatorRoomTimelineItem(uniqueID: "v3")] + SeparatorRoomTimelineItem(uniqueID: .init(id: "v3"))] let (viewModel, _, _, _) = readReceiptsConfiguration(with: items) // When sending a read receipt for the last item. @@ -436,14 +437,14 @@ private extension TextRoomTimelineItem { } private extension SeparatorRoomTimelineItem { - init(uniqueID: String) { + init(uniqueID: TimelineUniqueId) { self.init(id: .virtual(uniqueID: uniqueID), text: "") } } private extension TextRoomTimelineItem { init(eventID: String) { - self.init(id: .event(uniqueID: UUID().uuidString, eventOrTransactionID: .eventId(eventId: eventID)), + self.init(id: .event(uniqueID: .init(id: UUID().uuidString), eventOrTransactionID: .eventId(eventId: eventID)), timestamp: "", isOutgoing: false, isEditable: false,