Generate mocks for all SDK classes and introduce a simple TimelineItemFactory test to try them out

This commit is contained in:
Stefan Ceriu
2024-06-05 15:27:04 +03:00
parent c51593476c
commit 53fc5df55b
7 changed files with 18608 additions and 1768 deletions
@@ -20,7 +20,7 @@ import XCTest
final class MediaLoaderTests: XCTestCase {
func testMediaRequestCoalescing() async {
let mediaLoadingClient = SDKClientMock()
let mediaLoadingClient = ClientSDKMock()
mediaLoadingClient.getMediaContentMediaSourceReturnValue = Data()
let mediaLoader = MediaLoader(client: mediaLoadingClient)
@@ -38,7 +38,7 @@ final class MediaLoaderTests: XCTestCase {
}
func testMediaThumbnailRequestCoalescing() async {
let mediaLoadingClient = SDKClientMock()
let mediaLoadingClient = ClientSDKMock()
mediaLoadingClient.getMediaThumbnailMediaSourceWidthHeightReturnValue = Data()
let mediaLoader = MediaLoader(client: mediaLoadingClient)
@@ -0,0 +1,59 @@
//
// 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.
//
@testable import ElementX
import XCTest
@MainActor
class TimelineItemFactoryTests: XCTestCase {
func testCallInvite() async {
let ownUserID = "@alice:matrix.org"
let senderUserID = "@bob:matrix.org"
let factory = RoomTimelineItemFactory(userID: ownUserID,
attributedStringBuilder: AttributedStringBuilder(mentionBuilder: MentionBuilder()),
stateEventStringBuilder: RoomStateEventStringBuilder(userID: ownUserID))
let eventTimelineItem = EventTimelineItemSDKMock()
eventTimelineItem.isOwnReturnValue = true
eventTimelineItem.timestampReturnValue = 0
eventTimelineItem.isEditableReturnValue = false
eventTimelineItem.canBeRepliedToReturnValue = false
eventTimelineItem.senderReturnValue = senderUserID
eventTimelineItem.senderProfileReturnValue = .pending
let timelineItemContent = TimelineItemContentSDKMock()
timelineItemContent.kindReturnValue = .callInvite
eventTimelineItem.contentReturnValue = timelineItemContent
let eventTimelineItemProxy = EventTimelineItemProxy(item: eventTimelineItem, id: "0")
let item = factory.buildTimelineItem(for: eventTimelineItemProxy, isDM: false)
guard let item = item as? CallInviteRoomTimelineItem else {
XCTFail("Incorrect item type")
return
}
XCTAssertEqual(item.isReactable, false)
XCTAssertEqual(item.canBeRepliedTo, false)
XCTAssertEqual(item.isEditable, false)
XCTAssertEqual(item.sender, TimelineItemSender(id: senderUserID))
XCTAssertEqual(item.properties.isEdited, false)
XCTAssertEqual(item.properties.reactions, [])
XCTAssertEqual(item.properties.deliveryStatus, nil)
}
}