@@ -50,8 +50,10 @@ import io.element.android.libraries.matrix.test.room.aRoomPreviewInfo
50
50
import io.element.android.libraries.matrix.test.room.join.FakeJoinRoom
51
51
import io.element.android.libraries.matrix.test.spaces.FakeSpaceRoomList
52
52
import io.element.android.libraries.matrix.test.spaces.FakeSpaceService
53
+ import io.element.android.libraries.matrix.ui.components.aMatrixUser
53
54
import io.element.android.libraries.matrix.ui.model.InviteSender
54
55
import io.element.android.libraries.matrix.ui.model.toInviteSender
56
+ import io.element.android.libraries.previewutils.room.aSpaceRoom
55
57
import io.element.android.tests.testutils.WarmUpRule
56
58
import io.element.android.tests.testutils.lambda.any
57
59
import io.element.android.tests.testutils.lambda.assert
@@ -189,6 +191,137 @@ class JoinRoomPresenterTest {
189
191
}
190
192
}
191
193
194
+ @Test
195
+ fun `present - when space is invited then join authorization is equal to invited, an inviter is provided` () = runTest {
196
+ val inviter = aRoomMember(userId = A_USER_ID_2 , displayName = " Bob" )
197
+ val expectedInviteSender = inviter.toInviteSender()
198
+ val spaceHero = aMatrixUser()
199
+ val roomInfo = aRoomInfo(
200
+ isSpace = true ,
201
+ currentUserMembership = CurrentUserMembership .INVITED ,
202
+ joinedMembersCount = 5 ,
203
+ inviter = inviter,
204
+ heroes = listOf (spaceHero),
205
+ )
206
+ val inviteData = roomInfo.toInviteData()
207
+ val matrixClient = FakeMatrixClient (
208
+ getNotJoinedRoomResult = { _, _ ->
209
+ Result .success(
210
+ aRoomPreview(
211
+ info = aRoomPreviewInfo(
212
+ numberOfJoinedMembers = 5 ,
213
+ ),
214
+ roomMembershipDetails = {
215
+ Result .success(aRoomMembershipDetails())
216
+ },
217
+ )
218
+ )
219
+ },
220
+ spaceService = FakeSpaceService (
221
+ spaceRoomListResult = {
222
+ FakeSpaceRoomList (
223
+ initialSpaceFlowValue = aSpaceRoom(
224
+ childrenCount = 3 ,
225
+ )
226
+ )
227
+ },
228
+ ),
229
+ ).apply {
230
+ getRoomInfoFlowLambda = { _ ->
231
+ flowOf(Optional .of(roomInfo))
232
+ }
233
+ }
234
+ val presenter = createJoinRoomPresenter(
235
+ matrixClient = matrixClient
236
+ )
237
+ presenter.test {
238
+ skipItems(2 )
239
+ awaitItem().also { state ->
240
+ assertThat(state.joinAuthorisationStatus).isEqualTo(JoinAuthorisationStatus .IsInvited (inviteData, expectedInviteSender))
241
+ assertThat((state.contentState as ContentState .Loaded ).numberOfMembers).isEqualTo(5 )
242
+ // Space details are provided
243
+ assertThat(state.contentState.details).isEqualTo(
244
+ LoadedDetails .Space (
245
+ childrenCount = 3 ,
246
+ heroes = persistentListOf(spaceHero),
247
+ )
248
+ )
249
+ }
250
+ }
251
+ }
252
+
253
+ @Test
254
+ fun `present - space is invited - no room info` () = runTest {
255
+ val spaceHero = aMatrixUser()
256
+ val spaceRoom = aSpaceRoom(
257
+ childrenCount = 3 ,
258
+ heroes = listOf (spaceHero),
259
+ )
260
+ val matrixClient = FakeMatrixClient (
261
+ getNotJoinedRoomResult = { _, _ ->
262
+ Result .failure(Exception (" Error" ))
263
+ },
264
+ spaceService = FakeSpaceService (
265
+ spaceRoomListResult = {
266
+ FakeSpaceRoomList (
267
+ initialSpaceFlowValue = spaceRoom,
268
+ )
269
+ },
270
+ ),
271
+ ).apply {
272
+ getRoomInfoFlowLambda = { _ ->
273
+ flowOf(Optional .ofNullable(null ))
274
+ }
275
+ }
276
+ val presenter = createJoinRoomPresenter(
277
+ matrixClient = matrixClient
278
+ )
279
+ presenter.test {
280
+ skipItems(1 )
281
+ awaitItem().also { state ->
282
+ // Space details are provided
283
+ assertThat((state.contentState as ContentState .Loaded ).details).isEqualTo(
284
+ LoadedDetails .Space (
285
+ childrenCount = 3 ,
286
+ heroes = persistentListOf(spaceHero),
287
+ )
288
+ )
289
+ }
290
+ }
291
+ }
292
+
293
+ @Test
294
+ fun `present - space is invited - no room info - space room state set` () = runTest {
295
+ val spaceRoom = aSpaceRoom(
296
+ state = CurrentUserMembership .INVITED ,
297
+ )
298
+ val matrixClient = FakeMatrixClient (
299
+ getNotJoinedRoomResult = { _, _ ->
300
+ Result .failure(Exception (" Error" ))
301
+ },
302
+ spaceService = FakeSpaceService (
303
+ spaceRoomListResult = {
304
+ FakeSpaceRoomList (
305
+ initialSpaceFlowValue = spaceRoom,
306
+ )
307
+ },
308
+ ),
309
+ ).apply {
310
+ getRoomInfoFlowLambda = { _ ->
311
+ flowOf(Optional .ofNullable(null ))
312
+ }
313
+ }
314
+ val presenter = createJoinRoomPresenter(
315
+ matrixClient = matrixClient
316
+ )
317
+ presenter.test {
318
+ awaitItem().also { state ->
319
+ // Space details are provided
320
+ assertThat(state.contentState).isInstanceOf(ContentState .Loading ::class .java)
321
+ }
322
+ }
323
+ }
324
+
192
325
@Test
193
326
fun `present - when room is invited read the number of member from the room preview` () = runTest {
194
327
val roomInfo = aRoomInfo(
0 commit comments