Add test for RoomListEvents.DismissRecoveryKeyPrompt.
Also get the encryptionService from the matrixClient, instead of injecting it separately.
This commit is contained in:
parent
b48aa45d51
commit
bedf3b9e3e
4 changed files with 43 additions and 10 deletions
|
|
@ -75,13 +75,14 @@ class RoomListPresenter @Inject constructor(
|
||||||
private val inviteStateDataSource: InviteStateDataSource,
|
private val inviteStateDataSource: InviteStateDataSource,
|
||||||
private val leaveRoomPresenter: LeaveRoomPresenter,
|
private val leaveRoomPresenter: LeaveRoomPresenter,
|
||||||
private val roomListDataSource: RoomListDataSource,
|
private val roomListDataSource: RoomListDataSource,
|
||||||
private val encryptionService: EncryptionService,
|
|
||||||
private val featureFlagService: FeatureFlagService,
|
private val featureFlagService: FeatureFlagService,
|
||||||
private val indicatorService: IndicatorService,
|
private val indicatorService: IndicatorService,
|
||||||
private val searchPresenter: Presenter<RoomListSearchState>,
|
private val searchPresenter: Presenter<RoomListSearchState>,
|
||||||
private val migrationScreenPresenter: MigrationScreenPresenter,
|
private val migrationScreenPresenter: MigrationScreenPresenter,
|
||||||
private val sessionPreferencesStore: SessionPreferencesStore,
|
private val sessionPreferencesStore: SessionPreferencesStore,
|
||||||
) : Presenter<RoomListState> {
|
) : Presenter<RoomListState> {
|
||||||
|
private val encryptionService: EncryptionService = client.encryptionService()
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun present(): RoomListState {
|
override fun present(): RoomListState {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
@ -139,7 +140,6 @@ class RoomListPresenter @Inject constructor(
|
||||||
contextMenu.value = RoomListState.ContextMenu.Hidden
|
contextMenu.value = RoomListState.ContextMenu.Hidden
|
||||||
}
|
}
|
||||||
is RoomListEvents.LeaveRoom -> leaveRoomState.eventSink(LeaveRoomEvent.ShowConfirmation(event.roomId))
|
is RoomListEvents.LeaveRoom -> leaveRoomState.eventSink(LeaveRoomEvent.ShowConfirmation(event.roomId))
|
||||||
|
|
||||||
is RoomListEvents.SetRoomIsFavorite -> coroutineScope.launch {
|
is RoomListEvents.SetRoomIsFavorite -> coroutineScope.launch {
|
||||||
client.getRoom(event.roomId)?.use { room ->
|
client.getRoom(event.roomId)?.use { room ->
|
||||||
room.setIsFavorite(event.isFavorite)
|
room.setIsFavorite(event.isFavorite)
|
||||||
|
|
|
||||||
|
|
@ -42,13 +42,14 @@ import io.element.android.libraries.dateformatter.test.FakeLastMessageTimestampF
|
||||||
import io.element.android.libraries.designsystem.utils.snackbar.SnackbarDispatcher
|
import io.element.android.libraries.designsystem.utils.snackbar.SnackbarDispatcher
|
||||||
import io.element.android.libraries.eventformatter.api.RoomLastMessageFormatter
|
import io.element.android.libraries.eventformatter.api.RoomLastMessageFormatter
|
||||||
import io.element.android.libraries.eventformatter.test.FakeRoomLastMessageFormatter
|
import io.element.android.libraries.eventformatter.test.FakeRoomLastMessageFormatter
|
||||||
|
import io.element.android.libraries.featureflag.api.FeatureFlagService
|
||||||
import io.element.android.libraries.featureflag.api.FeatureFlags
|
import io.element.android.libraries.featureflag.api.FeatureFlags
|
||||||
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
|
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
|
||||||
import io.element.android.libraries.featureflag.test.InMemorySessionPreferencesStore
|
import io.element.android.libraries.featureflag.test.InMemorySessionPreferencesStore
|
||||||
import io.element.android.libraries.indicator.impl.DefaultIndicatorService
|
import io.element.android.libraries.indicator.impl.DefaultIndicatorService
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
import io.element.android.libraries.matrix.api.encryption.BackupState
|
import io.element.android.libraries.matrix.api.encryption.BackupState
|
||||||
import io.element.android.libraries.matrix.api.encryption.EncryptionService
|
import io.element.android.libraries.matrix.api.encryption.RecoveryState
|
||||||
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
|
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
|
||||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||||
import io.element.android.libraries.matrix.api.timeline.ReceiptType
|
import io.element.android.libraries.matrix.api.timeline.ReceiptType
|
||||||
|
|
@ -108,9 +109,12 @@ class RoomListPresenterTests {
|
||||||
fun `present - show avatar indicator`() = runTest {
|
fun `present - show avatar indicator`() = runTest {
|
||||||
val scope = CoroutineScope(coroutineContext + SupervisorJob())
|
val scope = CoroutineScope(coroutineContext + SupervisorJob())
|
||||||
val encryptionService = FakeEncryptionService()
|
val encryptionService = FakeEncryptionService()
|
||||||
|
val matrixClient = FakeMatrixClient(
|
||||||
|
encryptionService = encryptionService,
|
||||||
|
)
|
||||||
val sessionVerificationService = FakeSessionVerificationService()
|
val sessionVerificationService = FakeSessionVerificationService()
|
||||||
val presenter = createRoomListPresenter(
|
val presenter = createRoomListPresenter(
|
||||||
encryptionService = encryptionService,
|
client = matrixClient,
|
||||||
sessionVerificationService = sessionVerificationService,
|
sessionVerificationService = sessionVerificationService,
|
||||||
coroutineScope = scope
|
coroutineScope = scope
|
||||||
)
|
)
|
||||||
|
|
@ -255,6 +259,33 @@ class RoomListPresenterTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - handle DismissRecoveryKeyPrompt`() = runTest {
|
||||||
|
val encryptionService = FakeEncryptionService()
|
||||||
|
val matrixClient = FakeMatrixClient(
|
||||||
|
encryptionService = encryptionService,
|
||||||
|
)
|
||||||
|
val scope = CoroutineScope(context = coroutineContext + SupervisorJob())
|
||||||
|
val presenter = createRoomListPresenter(
|
||||||
|
client = matrixClient,
|
||||||
|
coroutineScope = scope,
|
||||||
|
)
|
||||||
|
moleculeFlow(RecompositionMode.Immediate) {
|
||||||
|
presenter.present()
|
||||||
|
}.test {
|
||||||
|
skipItems(1)
|
||||||
|
val initialState = awaitItem()
|
||||||
|
assertThat(initialState.displayRecoveryKeyPrompt).isFalse()
|
||||||
|
encryptionService.emitRecoveryState(RecoveryState.INCOMPLETE)
|
||||||
|
val nextState = awaitItem()
|
||||||
|
assertThat(nextState.displayRecoveryKeyPrompt).isTrue()
|
||||||
|
nextState.eventSink(RoomListEvents.DismissRecoveryKeyPrompt)
|
||||||
|
val finalState = awaitItem()
|
||||||
|
assertThat(finalState.displayRecoveryKeyPrompt).isFalse()
|
||||||
|
scope.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - sets invite state`() = runTest {
|
fun `present - sets invite state`() = runTest {
|
||||||
val inviteStateFlow = MutableStateFlow(InvitesState.NoInvites)
|
val inviteStateFlow = MutableStateFlow(InvitesState.NoInvites)
|
||||||
|
|
@ -506,8 +537,8 @@ class RoomListPresenterTests {
|
||||||
givenFormat(A_FORMATTED_DATE)
|
givenFormat(A_FORMATTED_DATE)
|
||||||
},
|
},
|
||||||
roomLastMessageFormatter: RoomLastMessageFormatter = FakeRoomLastMessageFormatter(),
|
roomLastMessageFormatter: RoomLastMessageFormatter = FakeRoomLastMessageFormatter(),
|
||||||
encryptionService: EncryptionService = FakeEncryptionService(),
|
|
||||||
sessionPreferencesStore: SessionPreferencesStore = InMemorySessionPreferencesStore(),
|
sessionPreferencesStore: SessionPreferencesStore = InMemorySessionPreferencesStore(),
|
||||||
|
featureFlagService: FeatureFlagService = FakeFeatureFlagService(mapOf(FeatureFlags.SecureStorage.key to true)),
|
||||||
coroutineScope: CoroutineScope,
|
coroutineScope: CoroutineScope,
|
||||||
migrationScreenPresenter: MigrationScreenPresenter = MigrationScreenPresenter(
|
migrationScreenPresenter: MigrationScreenPresenter = MigrationScreenPresenter(
|
||||||
matrixClient = client,
|
matrixClient = client,
|
||||||
|
|
@ -531,12 +562,11 @@ class RoomListPresenterTests {
|
||||||
notificationSettingsService = client.notificationSettingsService(),
|
notificationSettingsService = client.notificationSettingsService(),
|
||||||
appScope = coroutineScope
|
appScope = coroutineScope
|
||||||
),
|
),
|
||||||
encryptionService = encryptionService,
|
featureFlagService = featureFlagService,
|
||||||
featureFlagService = FakeFeatureFlagService(mapOf(FeatureFlags.SecureStorage.key to true)),
|
|
||||||
indicatorService = DefaultIndicatorService(
|
indicatorService = DefaultIndicatorService(
|
||||||
sessionVerificationService = sessionVerificationService,
|
sessionVerificationService = sessionVerificationService,
|
||||||
encryptionService = encryptionService,
|
encryptionService = client.encryptionService(),
|
||||||
featureFlagService = FakeFeatureFlagService(mapOf(FeatureFlags.SecureStorage.key to true)),
|
featureFlagService = featureFlagService,
|
||||||
),
|
),
|
||||||
migrationScreenPresenter = migrationScreenPresenter,
|
migrationScreenPresenter = migrationScreenPresenter,
|
||||||
searchPresenter = searchPresenter,
|
searchPresenter = searchPresenter,
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,10 @@ class FakeEncryptionService : EncryptionService {
|
||||||
backupStateStateFlow.emit(state)
|
backupStateStateFlow.emit(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun emitRecoveryState(state: RecoveryState) {
|
||||||
|
recoveryStateStateFlow.emit(state)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun emitEnableRecoveryProgress(state: EnableRecoveryProgress) {
|
suspend fun emitEnableRecoveryProgress(state: EnableRecoveryProgress) {
|
||||||
enableRecoveryProgressStateFlow.emit(state)
|
enableRecoveryProgressStateFlow.emit(state)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,6 @@ class RoomListScreen(
|
||||||
notificationSettingsService = matrixClient.notificationSettingsService(),
|
notificationSettingsService = matrixClient.notificationSettingsService(),
|
||||||
appScope = Singleton.appScope
|
appScope = Singleton.appScope
|
||||||
),
|
),
|
||||||
encryptionService = encryptionService,
|
|
||||||
indicatorService = DefaultIndicatorService(
|
indicatorService = DefaultIndicatorService(
|
||||||
sessionVerificationService = sessionVerificationService,
|
sessionVerificationService = sessionVerificationService,
|
||||||
encryptionService = encryptionService,
|
encryptionService = encryptionService,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue