|
6 | 6 | @testable import StreamChatSwiftUI
|
7 | 7 | import XCTest
|
8 | 8 |
|
9 |
| -class MessageCachingUtils_Tests: XCTestCase { |
| 9 | +class MessageCachingUtils_Tests: StreamChatTestCase { |
10 | 10 |
|
11 | 11 | let author = ChatUser.mock(
|
12 | 12 | id: "test",
|
@@ -109,4 +109,69 @@ class MessageCachingUtils_Tests: XCTestCase {
|
109 | 109 | XCTAssert(authorIdInitial == "test")
|
110 | 110 | XCTAssert(authorIdInitial == authorIdAfterClear)
|
111 | 111 | }
|
| 112 | + |
| 113 | + func test_messageCachingUtils_userDisplayInfo() { |
| 114 | + // Given |
| 115 | + let id: String = .unique |
| 116 | + let url = URL(string: "https://imageurl.com") |
| 117 | + let author = ChatUser.mock(id: id, name: "Martin", imageURL: url) |
| 118 | + let message = ChatMessage.mock( |
| 119 | + id: .unique, |
| 120 | + cid: .unique, |
| 121 | + text: "Test message", |
| 122 | + author: author |
| 123 | + ) |
| 124 | + let utils = MessageCachingUtils() |
| 125 | + |
| 126 | + // When |
| 127 | + let authorInfo = utils.authorInfo(from: message) |
| 128 | + let userDisplayInfo = message.authorDisplayInfo |
| 129 | + |
| 130 | + // Then |
| 131 | + XCTAssert(authorInfo == userDisplayInfo) |
| 132 | + XCTAssert(userDisplayInfo.id == id) |
| 133 | + XCTAssert(userDisplayInfo.name == author.name) |
| 134 | + XCTAssert(userDisplayInfo.imageURL == url) |
| 135 | + } |
| 136 | + |
| 137 | + func test_messageCachingUtils_userDisplayInfoIdExisting() { |
| 138 | + // Given |
| 139 | + let id: String = .unique |
| 140 | + let url = URL(string: "https://imageurl.com") |
| 141 | + let author = ChatUser.mock(id: id, name: "Martin", imageURL: url) |
| 142 | + let message = ChatMessage.mock( |
| 143 | + id: .unique, |
| 144 | + cid: .unique, |
| 145 | + text: "Test message", |
| 146 | + author: author |
| 147 | + ) |
| 148 | + let utils = MessageCachingUtils() |
| 149 | + |
| 150 | + // When |
| 151 | + let authorInfo = utils.authorInfo(from: message) |
| 152 | + let userDisplayInfo = utils.userDisplayInfo(with: id) |
| 153 | + |
| 154 | + // Then |
| 155 | + XCTAssert(userDisplayInfo != nil) |
| 156 | + XCTAssert(authorInfo == userDisplayInfo) |
| 157 | + XCTAssert(userDisplayInfo!.id == id) |
| 158 | + XCTAssert(userDisplayInfo!.name == author.name) |
| 159 | + XCTAssert(userDisplayInfo!.imageURL == url) |
| 160 | + } |
| 161 | + |
| 162 | + func test_messageCachingUtils_userDisplayInfoIdNonExisting() { |
| 163 | + let utils = MessageCachingUtils() |
| 164 | + |
| 165 | + // When |
| 166 | + let userDisplayInfo = utils.userDisplayInfo(with: "some id") |
| 167 | + |
| 168 | + // Then |
| 169 | + XCTAssert(userDisplayInfo == nil) |
| 170 | + } |
| 171 | +} |
| 172 | + |
| 173 | +extension UserDisplayInfo: Equatable { |
| 174 | + public static func == (lhs: UserDisplayInfo, rhs: UserDisplayInfo) -> Bool { |
| 175 | + lhs.id == rhs.id && lhs.name == rhs.name && lhs.imageURL == rhs.imageURL |
| 176 | + } |
112 | 177 | }
|
0 commit comments