Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Oct 16, 2024
1 parent 320d4e9 commit 92d5ede
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/SDK/ClientSDKMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions UnitTests/Sources/LoggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
16 changes: 8 additions & 8 deletions UnitTests/Sources/RoomScreenViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/Sources/TimelineItemFactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions UnitTests/Sources/TimelineViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@testable import ElementX

import Combine
import MatrixRustSDK
import XCTest

@MainActor
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 92d5ede

Please sign in to comment.