SecureBackupSetupEvents -> SecureBackupSetupEvent

This commit is contained in:
Benoit Marty
2026-08-25 10:22:22 +02:00
parent 28c19e38ce
commit b8b6dc1df6
5 changed files with 27 additions and 27 deletions
@@ -8,9 +8,9 @@
package io.element.android.features.securebackup.impl.setup
sealed interface SecureBackupSetupEvents {
data object CreateRecoveryKey : SecureBackupSetupEvents
data object RecoveryKeyHasBeenSaved : SecureBackupSetupEvents
data object Done : SecureBackupSetupEvents
data object DismissDialog : SecureBackupSetupEvents
sealed interface SecureBackupSetupEvent {
data object CreateRecoveryKey : SecureBackupSetupEvent
data object RecoveryKeyHasBeenSaved : SecureBackupSetupEvent
data object Done : SecureBackupSetupEvent
data object DismissDialog : SecureBackupSetupEvent
}
@@ -53,18 +53,18 @@ class SecureBackupSetupPresenter(
}
var showSaveConfirmationDialog by remember { mutableStateOf(false) }
fun handleEvent(event: SecureBackupSetupEvents) {
fun handleEvent(event: SecureBackupSetupEvent) {
when (event) {
SecureBackupSetupEvents.CreateRecoveryKey -> {
SecureBackupSetupEvent.CreateRecoveryKey -> {
coroutineScope.createOrChangeRecoveryKey(stateAndDispatch)
}
SecureBackupSetupEvents.RecoveryKeyHasBeenSaved ->
SecureBackupSetupEvent.RecoveryKeyHasBeenSaved ->
stateAndDispatch.dispatchAction(SecureBackupSetupStateMachine.Event.UserSavedKey)
SecureBackupSetupEvents.DismissDialog -> {
SecureBackupSetupEvent.DismissDialog -> {
showSaveConfirmationDialog = false
stateAndDispatch.dispatchAction(SecureBackupSetupStateMachine.Event.ClearError)
}
SecureBackupSetupEvents.Done -> {
SecureBackupSetupEvent.Done -> {
showSaveConfirmationDialog = true
}
}
@@ -15,7 +15,7 @@ data class SecureBackupSetupState(
val recoveryKeyViewState: RecoveryKeyViewState,
val showSaveConfirmationDialog: Boolean,
val setupState: SetupState,
val eventSink: (SecureBackupSetupEvents) -> Unit
val eventSink: (SecureBackupSetupEvent) -> Unit
)
sealed interface SetupState {
@@ -56,7 +56,7 @@ fun SecureBackupSetupView(
title = stringResource(id = CommonStrings.common_something_went_wrong),
content = stringResource(id = CommonStrings.common_something_went_wrong_message),
onSubmit = {
state.eventSink.invoke(SecureBackupSetupEvents.DismissDialog)
state.eventSink.invoke(SecureBackupSetupEvent.DismissDialog)
},
)
}
@@ -68,7 +68,7 @@ fun SecureBackupSetupView(
submitText = stringResource(id = CommonStrings.action_continue),
onSubmitClick = onSuccess,
onDismiss = {
state.eventSink.invoke(SecureBackupSetupEvents.DismissDialog)
state.eventSink.invoke(SecureBackupSetupEvent.DismissDialog)
}
)
}
@@ -123,12 +123,12 @@ private fun Content(
text = formattedRecoveryKey,
toastMessage = toastMessage,
)
state.eventSink.invoke(SecureBackupSetupEvents.RecoveryKeyHasBeenSaved)
state.eventSink.invoke(SecureBackupSetupEvent.RecoveryKeyHasBeenSaved)
}
} else {
if (!state.recoveryKeyViewState.inProgress) {
{
state.eventSink.invoke(SecureBackupSetupEvents.CreateRecoveryKey)
state.eventSink.invoke(SecureBackupSetupEvent.CreateRecoveryKey)
}
} else {
null
@@ -174,7 +174,7 @@ private fun ColumnScope.Buttons(
chooserTitle = chooserTitle,
text = state.setupState.recoveryKey()!!,
)
state.eventSink.invoke(SecureBackupSetupEvents.RecoveryKeyHasBeenSaved)
state.eventSink.invoke(SecureBackupSetupEvent.RecoveryKeyHasBeenSaved)
},
)
Button(
@@ -184,7 +184,7 @@ private fun ColumnScope.Buttons(
if (state.setupState is SetupState.CreatedAndSaved) {
onFinish()
} else {
state.eventSink.invoke(SecureBackupSetupEvents.Done)
state.eventSink.invoke(SecureBackupSetupEvent.Done)
}
},
)
@@ -58,7 +58,7 @@ class SecureBackupSetupPresenterTest {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink.invoke(SecureBackupSetupEvents.CreateRecoveryKey)
initialState.eventSink.invoke(SecureBackupSetupEvent.CreateRecoveryKey)
val creatingState = awaitItem()
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
assertThat(creatingState.recoveryKeyViewState).isEqualTo(
@@ -80,13 +80,13 @@ class SecureBackupSetupPresenterTest {
inProgress = false,
)
)
createdState.eventSink.invoke(SecureBackupSetupEvents.RecoveryKeyHasBeenSaved)
createdState.eventSink.invoke(SecureBackupSetupEvent.RecoveryKeyHasBeenSaved)
val createdAndSaveState = awaitItem()
assertThat(createdAndSaveState.setupState).isInstanceOf(SetupState.CreatedAndSaved::class.java)
createdAndSaveState.eventSink.invoke(SecureBackupSetupEvents.Done)
createdAndSaveState.eventSink.invoke(SecureBackupSetupEvent.Done)
val doneState = awaitItem()
assertThat(doneState.showSaveConfirmationDialog).isTrue()
doneState.eventSink.invoke(SecureBackupSetupEvents.DismissDialog)
doneState.eventSink.invoke(SecureBackupSetupEvent.DismissDialog)
val doneStateCancelled = awaitItem()
assertThat(doneStateCancelled.showSaveConfirmationDialog).isFalse()
}
@@ -130,12 +130,12 @@ class SecureBackupSetupPresenterTest {
assertThat(initialState.isChangeRecoveryKeyUserStory).isFalse()
assertThat(initialState.setupState).isEqualTo(SetupState.Init)
initialState.eventSink(SecureBackupSetupEvents.CreateRecoveryKey)
initialState.eventSink(SecureBackupSetupEvent.CreateRecoveryKey)
val creatingState = awaitItem()
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
val failedState = awaitItem()
assertThat(failedState.setupState).isInstanceOf(SetupState.Error::class.java)
failedState.eventSink(SecureBackupSetupEvents.DismissDialog)
failedState.eventSink(SecureBackupSetupEvent.DismissDialog)
val finalState = awaitItem()
assertThat(finalState.setupState).isEqualTo(SetupState.Init)
@@ -153,7 +153,7 @@ class SecureBackupSetupPresenterTest {
presenter.present()
}.test {
val initialState = awaitItem()
initialState.eventSink.invoke(SecureBackupSetupEvents.CreateRecoveryKey)
initialState.eventSink.invoke(SecureBackupSetupEvent.CreateRecoveryKey)
val creatingState = awaitItem()
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
assertThat(creatingState.recoveryKeyViewState).isEqualTo(
@@ -174,13 +174,13 @@ class SecureBackupSetupPresenterTest {
inProgress = false,
)
)
createdState.eventSink.invoke(SecureBackupSetupEvents.RecoveryKeyHasBeenSaved)
createdState.eventSink.invoke(SecureBackupSetupEvent.RecoveryKeyHasBeenSaved)
val createdAndSaveState = awaitItem()
assertThat(createdAndSaveState.setupState).isInstanceOf(SetupState.CreatedAndSaved::class.java)
createdAndSaveState.eventSink.invoke(SecureBackupSetupEvents.Done)
createdAndSaveState.eventSink.invoke(SecureBackupSetupEvent.Done)
val doneState = awaitItem()
assertThat(doneState.showSaveConfirmationDialog).isTrue()
doneState.eventSink.invoke(SecureBackupSetupEvents.DismissDialog)
doneState.eventSink.invoke(SecureBackupSetupEvent.DismissDialog)
val doneStateCancelled = awaitItem()
assertThat(doneStateCancelled.showSaveConfirmationDialog).isFalse()
}