@ -56,6 +56,7 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode
import io.element.android.libraries.matrix.api.roomlist.RoomList
import io.element.android.libraries.matrix.api.roomlist.RoomList
import io.element.android.libraries.matrix.api.sync.SyncState
import io.element.android.libraries.matrix.api.sync.SyncState
import io.element.android.libraries.matrix.api.timeline.ReceiptType
import io.element.android.libraries.matrix.api.timeline.ReceiptType
import io.element.android.libraries.matrix.api.user.MatrixUser
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
import io.element.android.libraries.matrix.test.AN_EXCEPTION
import io.element.android.libraries.matrix.test.AN_EXCEPTION
import io.element.android.libraries.matrix.test.A_ROOM_ID
import io.element.android.libraries.matrix.test.A_ROOM_ID
@ -93,17 +94,24 @@ class RoomListPresenterTests {
@Test
@Test
fun `present - should start with no user and then load user with success` ( ) = runTest {
fun `present - should start with no user and then load user with success` ( ) = runTest {
val scope = CoroutineScope ( coroutineContext + SupervisorJob ( ) )
val scope = CoroutineScope ( coroutineContext + SupervisorJob ( ) )
val presenter = createRoomListPresenter ( coroutineScope = scope )
val matrixClient = FakeMatrixClient (
userDisplayName = null ,
userAvatarUrl = null ,
)
matrixClient . givenGetProfileResult ( matrixClient . sessionId , Result . success ( MatrixUser ( matrixClient . sessionId , A _USER _NAME , AN _AVATAR _URL ) ) )
val presenter = createRoomListPresenter (
client = matrixClient ,
coroutineScope = scope ,
)
moleculeFlow ( RecompositionMode . Immediate ) {
moleculeFlow ( RecompositionMode . Immediate ) {
presenter . present ( )
presenter . present ( )
} . test {
} . test {
val initialState = awaitItem ( )
val initialState = awaitItem ( )
assertThat ( initialState . matrixUser ) . isNull ( )
assertThat ( initialState . matrixUser ) . isEqualTo ( MatrixUser ( A _USER _ID ) )
val withUserState = awaitItem ( )
val withUserState = awaitItem ( )
assertThat ( withUserState . matrixUser ) . isNotNull ( )
assertThat ( withUserState . matrixUser . userId ) . isEqualTo ( A _USER _ID )
assertThat ( withUserState . matrixUser !! . userId ) . isEqualTo ( A _USER _ID )
assertThat ( withUserState . matrixUser . displayName ) . isEqualTo ( A _USER _NAME )
assertThat ( withUserState . matrixUser !! . displayName ) . isEqualTo ( A _USER _NAME )
assertThat ( withUserState . matrixUser . avatarUrl ) . isEqualTo ( AN _AVATAR _URL )
assertThat ( withUserState . matrixUser !! . avatarUrl ) . isEqualTo ( AN _AVATAR _URL )
assertThat ( withUserState . showAvatarIndicator ) . isTrue ( )
assertThat ( withUserState . showAvatarIndicator ) . isTrue ( )
scope . cancel ( )
scope . cancel ( )
}
}
@ -128,7 +136,6 @@ class RoomListPresenterTests {
val initialState = awaitItem ( )
val initialState = awaitItem ( )
assertThat ( initialState . showAvatarIndicator ) . isTrue ( )
assertThat ( initialState . showAvatarIndicator ) . isTrue ( )
sessionVerificationService . givenCanVerifySession ( false )
sessionVerificationService . givenCanVerifySession ( false )
assertThat ( awaitItem ( ) . showAvatarIndicator ) . isTrue ( )
encryptionService . emitBackupState ( BackupState . ENABLED )
encryptionService . emitBackupState ( BackupState . ENABLED )
val finalState = awaitItem ( )
val finalState = awaitItem ( )
assertThat ( finalState . showAvatarIndicator ) . isFalse ( )
assertThat ( finalState . showAvatarIndicator ) . isFalse ( )
@ -139,19 +146,18 @@ class RoomListPresenterTests {
@Test
@Test
fun `present - should start with no user and then load user with error` ( ) = runTest {
fun `present - should start with no user and then load user with error` ( ) = runTest {
val matrixClient = FakeMatrixClient (
val matrixClient = FakeMatrixClient (
userDisplayName = Result . failure ( AN _EXCEPTION ) ,
userDisplayName = null ,
userAvatarUrl = Result . failure ( AN _EXCEPTION ) ,
userAvatarUrl = null ,
)
)
matrixClient . givenGetProfileResult ( matrixClient . sessionId , Result . failure ( AN _EXCEPTION ) )
val scope = CoroutineScope ( coroutineContext + SupervisorJob ( ) )
val scope = CoroutineScope ( coroutineContext + SupervisorJob ( ) )
val presenter = createRoomListPresenter ( client = matrixClient , coroutineScope = scope )
val presenter = createRoomListPresenter ( client = matrixClient , coroutineScope = scope )
moleculeFlow ( RecompositionMode . Immediate ) {
moleculeFlow ( RecompositionMode . Immediate ) {
presenter . present ( )
presenter . present ( )
} . test {
} . test {
val initialState = awaitItem ( )
val initialState = awaitItem ( )
assertThat ( initialState . matrixUser ) . isNull ( )
assertThat ( initialState . matrixUser ) . isEqualTo ( MatrixUser ( matrixClient . sessionId ) )
val withUserState = awaitItem ( )
// No new state is coming
assertThat ( withUserState . matrixUser ) . isNotNull ( )
scope . cancel ( )
}
}
}
}
@ -364,7 +370,6 @@ class RoomListPresenterTests {
moleculeFlow ( RecompositionMode . Immediate ) {
moleculeFlow ( RecompositionMode . Immediate ) {
presenter . present ( )
presenter . present ( )
} . test {
} . test {
skipItems ( 1 )
val initialState = awaitItem ( )
val initialState = awaitItem ( )
val summary = createRoomListRoomSummary ( )
val summary = createRoomListRoomSummary ( )
initialState . eventSink ( RoomListEvents . ShowContextMenu ( summary ) )
initialState . eventSink ( RoomListEvents . ShowContextMenu ( summary ) )
@ -414,8 +419,6 @@ class RoomListPresenterTests {
moleculeFlow ( RecompositionMode . Immediate ) {
moleculeFlow ( RecompositionMode . Immediate ) {
presenter . present ( )
presenter . present ( )
} . test {
} . test {
skipItems ( 1 )
val initialState = awaitItem ( )
val initialState = awaitItem ( )
val summary = createRoomListRoomSummary ( )
val summary = createRoomListRoomSummary ( )
initialState . eventSink ( RoomListEvents . ShowContextMenu ( summary ) )
initialState . eventSink ( RoomListEvents . ShowContextMenu ( summary ) )
@ -473,7 +476,6 @@ class RoomListPresenterTests {
moleculeFlow ( RecompositionMode . Immediate ) {
moleculeFlow ( RecompositionMode . Immediate ) {
presenter . present ( )
presenter . present ( )
} . test {
} . test {
skipItems ( 1 )
val initialState = awaitItem ( )
val initialState = awaitItem ( )
eventRecorder . assertEmpty ( )
eventRecorder . assertEmpty ( )
initialState . eventSink ( RoomListEvents . ToggleSearchResults )
initialState . eventSink ( RoomListEvents . ToggleSearchResults )
@ -558,7 +560,6 @@ class RoomListPresenterTests {
moleculeFlow ( RecompositionMode . Immediate ) {
moleculeFlow ( RecompositionMode . Immediate ) {
presenter . present ( )
presenter . present ( )
} . test {
} . test {
skipItems ( 1 )
val initialState = awaitItem ( )
val initialState = awaitItem ( )
// The migration screen is shown if the migration screen has not been shown before
// The migration screen is shown if the migration screen has not been shown before
assertThat ( initialState . contentState ) . isInstanceOf ( RoomListContentState . Migration :: class . java )
assertThat ( initialState . contentState ) . isInstanceOf ( RoomListContentState . Migration :: class . java )
@ -585,7 +586,6 @@ class RoomListPresenterTests {
moleculeFlow ( RecompositionMode . Immediate ) {
moleculeFlow ( RecompositionMode . Immediate ) {
presenter . present ( )
presenter . present ( )
} . test {
} . test {
skipItems ( 1 )
assertThat ( awaitItem ( ) . contentState ) . isInstanceOf ( RoomListContentState . Empty :: class . java )
assertThat ( awaitItem ( ) . contentState ) . isInstanceOf ( RoomListContentState . Empty :: class . java )
scope . cancel ( )
scope . cancel ( )
}
}