mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 16:22:49 +00:00
LogoutEvents -> LogoutEvent
This commit is contained in:
+3
-3
@@ -8,7 +8,7 @@
|
||||
|
||||
package io.element.android.features.logout.impl
|
||||
|
||||
sealed interface LogoutEvents {
|
||||
data class Logout(val ignoreSdkError: Boolean) : LogoutEvents
|
||||
data object CloseDialogs : LogoutEvents
|
||||
sealed interface LogoutEvent {
|
||||
data class Logout(val ignoreSdkError: Boolean) : LogoutEvent
|
||||
data object CloseDialogs : LogoutEvent
|
||||
}
|
||||
+3
-3
@@ -74,16 +74,16 @@ class LogoutPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
fun handleEvent(event: LogoutEvents) {
|
||||
fun handleEvent(event: LogoutEvent) {
|
||||
when (event) {
|
||||
is LogoutEvents.Logout -> {
|
||||
is LogoutEvent.Logout -> {
|
||||
if (logoutAction.value.isConfirming() || event.ignoreSdkError) {
|
||||
localCoroutineScope.logout(logoutAction, event.ignoreSdkError)
|
||||
} else {
|
||||
logoutAction.value = AsyncAction.ConfirmingNoParams
|
||||
}
|
||||
}
|
||||
LogoutEvents.CloseDialogs -> {
|
||||
LogoutEvent.CloseDialogs -> {
|
||||
logoutAction.value = AsyncAction.Uninitialized
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,5 +21,5 @@ data class LogoutState(
|
||||
val backupUploadState: BackupUploadState,
|
||||
val waitingForALongTime: Boolean,
|
||||
val logoutAction: AsyncAction<Unit>,
|
||||
val eventSink: (LogoutEvents) -> Unit,
|
||||
val eventSink: (LogoutEvent) -> Unit,
|
||||
)
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ fun aLogoutState(
|
||||
backupUploadState: BackupUploadState = BackupUploadState.Unknown,
|
||||
waitingForALongTime: Boolean = false,
|
||||
logoutAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
|
||||
eventSink: (LogoutEvents) -> Unit = {},
|
||||
eventSink: (LogoutEvent) -> Unit = {},
|
||||
) = LogoutState(
|
||||
isLastDevice = isLastDevice,
|
||||
backupState = backupState,
|
||||
|
||||
+4
-4
@@ -61,7 +61,7 @@ fun LogoutView(
|
||||
state = state,
|
||||
onChangeRecoveryKeyClick = onChangeRecoveryKeyClick,
|
||||
onLogoutClick = {
|
||||
eventSink(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
eventSink(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
}
|
||||
)
|
||||
},
|
||||
@@ -72,13 +72,13 @@ fun LogoutView(
|
||||
LogoutActionDialog(
|
||||
state.logoutAction,
|
||||
onConfirmClick = {
|
||||
eventSink(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
eventSink(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
},
|
||||
onForceLogoutClick = {
|
||||
eventSink(LogoutEvents.Logout(ignoreSdkError = true))
|
||||
eventSink(LogoutEvent.Logout(ignoreSdkError = true))
|
||||
},
|
||||
onDismissDialog = {
|
||||
eventSink(LogoutEvents.CloseDialogs)
|
||||
eventSink(LogoutEvent.CloseDialogs)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
+10
-10
@@ -139,10 +139,10 @@ class LogoutPresenterTest {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitFirstItem()
|
||||
initialState.eventSink.invoke(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
initialState.eventSink.invoke(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
val confirmationState = awaitItem()
|
||||
assertThat(confirmationState.logoutAction).isEqualTo(AsyncAction.ConfirmingNoParams)
|
||||
initialState.eventSink.invoke(LogoutEvents.CloseDialogs)
|
||||
initialState.eventSink.invoke(LogoutEvent.CloseDialogs)
|
||||
val finalState = awaitItem()
|
||||
assertThat(finalState.logoutAction).isEqualTo(AsyncAction.Uninitialized)
|
||||
}
|
||||
@@ -157,10 +157,10 @@ class LogoutPresenterTest {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitFirstItem()
|
||||
initialState.eventSink.invoke(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
initialState.eventSink.invoke(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
val confirmationState = awaitItem()
|
||||
assertThat(confirmationState.logoutAction).isEqualTo(AsyncAction.ConfirmingNoParams)
|
||||
confirmationState.eventSink.invoke(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
confirmationState.eventSink.invoke(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
val loadingState = awaitItem()
|
||||
assertThat(loadingState.logoutAction).isInstanceOf(AsyncAction.Loading::class.java)
|
||||
val successState = awaitItem()
|
||||
@@ -184,15 +184,15 @@ class LogoutPresenterTest {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitFirstItem()
|
||||
initialState.eventSink.invoke(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
initialState.eventSink.invoke(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
val confirmationState = awaitItem()
|
||||
assertThat(confirmationState.logoutAction).isEqualTo(AsyncAction.ConfirmingNoParams)
|
||||
confirmationState.eventSink.invoke(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
confirmationState.eventSink.invoke(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
val loadingState = awaitItem()
|
||||
assertThat(loadingState.logoutAction).isInstanceOf(AsyncAction.Loading::class.java)
|
||||
val errorState = awaitItem()
|
||||
assertThat(errorState.logoutAction).isEqualTo(AsyncAction.Failure(AN_EXCEPTION))
|
||||
errorState.eventSink.invoke(LogoutEvents.CloseDialogs)
|
||||
errorState.eventSink.invoke(LogoutEvent.CloseDialogs)
|
||||
val finalState = awaitItem()
|
||||
assertThat(finalState.logoutAction).isEqualTo(AsyncAction.Uninitialized)
|
||||
}
|
||||
@@ -214,15 +214,15 @@ class LogoutPresenterTest {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitFirstItem()
|
||||
initialState.eventSink.invoke(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
initialState.eventSink.invoke(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
val confirmationState = awaitItem()
|
||||
assertThat(confirmationState.logoutAction).isEqualTo(AsyncAction.ConfirmingNoParams)
|
||||
confirmationState.eventSink.invoke(LogoutEvents.Logout(ignoreSdkError = false))
|
||||
confirmationState.eventSink.invoke(LogoutEvent.Logout(ignoreSdkError = false))
|
||||
val loadingState = awaitItem()
|
||||
assertThat(loadingState.logoutAction).isInstanceOf(AsyncAction.Loading::class.java)
|
||||
val errorState = awaitItem()
|
||||
assertThat(errorState.logoutAction).isEqualTo(AsyncAction.Failure(AN_EXCEPTION))
|
||||
errorState.eventSink.invoke(LogoutEvents.Logout(ignoreSdkError = true))
|
||||
errorState.eventSink.invoke(LogoutEvent.Logout(ignoreSdkError = true))
|
||||
val loadingState2 = awaitItem()
|
||||
assertThat(loadingState2.logoutAction).isInstanceOf(AsyncAction.Loading::class.java)
|
||||
val successState = awaitItem()
|
||||
|
||||
+14
-14
@@ -28,20 +28,20 @@ import org.junit.Test
|
||||
|
||||
class LogoutViewTest : RobolectricTest() {
|
||||
@Test
|
||||
fun `clicking on logout sends a LogoutEvents`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvents>()
|
||||
fun `clicking on logout sends a LogoutEvent`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvent>()
|
||||
setLogoutView(
|
||||
aLogoutState(
|
||||
eventSink = eventsRecorder
|
||||
),
|
||||
)
|
||||
clickOn(CommonStrings.action_signout)
|
||||
eventsRecorder.assertSingle(LogoutEvents.Logout(false))
|
||||
eventsRecorder.assertSingle(LogoutEvent.Logout(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `confirming logout sends a LogoutEvents`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvents>()
|
||||
fun `confirming logout sends a LogoutEvent`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvent>()
|
||||
setLogoutView(
|
||||
aLogoutState(
|
||||
logoutAction = AsyncAction.ConfirmingNoParams,
|
||||
@@ -49,12 +49,12 @@ class LogoutViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
pressTag(TestTags.dialogPositive.value)
|
||||
eventsRecorder.assertSingle(LogoutEvents.Logout(false))
|
||||
eventsRecorder.assertSingle(LogoutEvent.Logout(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clicking on back invoke back callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<LogoutEvent>(expectEvents = false)
|
||||
ensureCalledOnce { callback ->
|
||||
setLogoutView(
|
||||
aLogoutState(
|
||||
@@ -67,8 +67,8 @@ class LogoutViewTest : RobolectricTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clicking on confirm after error sends a LogoutEvents`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvents>()
|
||||
fun `clicking on confirm after error sends a LogoutEvent`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvent>()
|
||||
setLogoutView(
|
||||
aLogoutState(
|
||||
logoutAction = AsyncAction.Failure(Exception("Failed to logout")),
|
||||
@@ -76,12 +76,12 @@ class LogoutViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(CommonStrings.action_signout_anyway)
|
||||
eventsRecorder.assertSingle(LogoutEvents.Logout(true))
|
||||
eventsRecorder.assertSingle(LogoutEvent.Logout(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clicking on cancel after error sends a LogoutEvents`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvents>()
|
||||
fun `clicking on cancel after error sends a LogoutEvent`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvent>()
|
||||
setLogoutView(
|
||||
aLogoutState(
|
||||
logoutAction = AsyncAction.Failure(Exception("Failed to logout")),
|
||||
@@ -89,12 +89,12 @@ class LogoutViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(CommonStrings.action_cancel)
|
||||
eventsRecorder.assertSingle(LogoutEvents.CloseDialogs)
|
||||
eventsRecorder.assertSingle(LogoutEvent.CloseDialogs)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `last session setting button invoke onChangeRecoveryKeyClicked`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<LogoutEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<LogoutEvent>(expectEvents = false)
|
||||
ensureCalledOnce { callback ->
|
||||
setLogoutView(
|
||||
aLogoutState(
|
||||
|
||||
Reference in New Issue
Block a user