diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryEvents.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryEvent.kt similarity index 80% rename from libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryEvents.kt rename to libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryEvent.kt index 5116e0e101..a73c466275 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryEvents.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryEvent.kt @@ -12,9 +12,9 @@ import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.SessionId -sealed interface PushHistoryEvents { - data class SetShowOnlyErrors(val showOnlyErrors: Boolean) : PushHistoryEvents - data class Reset(val requiresConfirmation: Boolean) : PushHistoryEvents - data class NavigateTo(val sessionId: SessionId, val roomId: RoomId, val eventId: EventId) : PushHistoryEvents - data object ClearDialog : PushHistoryEvents +sealed interface PushHistoryEvent { + data class SetShowOnlyErrors(val showOnlyErrors: Boolean) : PushHistoryEvent + data class Reset(val requiresConfirmation: Boolean) : PushHistoryEvent + data class NavigateTo(val sessionId: SessionId, val roomId: RoomId, val eventId: EventId) : PushHistoryEvent + data object ClearDialog : PushHistoryEvent } diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenter.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenter.kt index ad1878051d..94e220a726 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenter.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenter.kt @@ -62,12 +62,12 @@ class PushHistoryPresenter( var resetAction: AsyncAction by remember { mutableStateOf(AsyncAction.Uninitialized) } var showNotSameAccountError by remember { mutableStateOf(false) } - fun handleEvent(event: PushHistoryEvents) { + fun handleEvent(event: PushHistoryEvent) { when (event) { - is PushHistoryEvents.SetShowOnlyErrors -> { + is PushHistoryEvent.SetShowOnlyErrors -> { showOnlyErrors = event.showOnlyErrors } - is PushHistoryEvents.Reset -> { + is PushHistoryEvent.Reset -> { if (event.requiresConfirmation) { resetAction = AsyncAction.ConfirmingNoParams } else { @@ -78,11 +78,11 @@ class PushHistoryPresenter( } } } - PushHistoryEvents.ClearDialog -> { + PushHistoryEvent.ClearDialog -> { resetAction = AsyncAction.Uninitialized showNotSameAccountError = false } - is PushHistoryEvents.NavigateTo -> { + is PushHistoryEvent.NavigateTo -> { if (event.sessionId != sessionId) { showNotSameAccountError = true } else { diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryState.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryState.kt index dbc98bdbe3..7afa567aa1 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryState.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryState.kt @@ -18,5 +18,5 @@ data class PushHistoryState( val showOnlyErrors: Boolean, val resetAction: AsyncAction, val showNotSameAccountError: Boolean, - val eventSink: (PushHistoryEvents) -> Unit, + val eventSink: (PushHistoryEvent) -> Unit, ) diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryStatePreviewParam.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryStatePreviewParam.kt index 968de5534c..cec0069237 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryStatePreviewParam.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryStatePreviewParam.kt @@ -53,7 +53,7 @@ fun aPushHistoryState( showOnlyErrors: Boolean = false, resetAction: AsyncAction = AsyncAction.Uninitialized, showNotSameAccountError: Boolean = false, - eventSink: (PushHistoryEvents) -> Unit = {}, + eventSink: (PushHistoryEvent) -> Unit = {}, ) = PushHistoryState( pushCounter = pushCounter, pushHistoryItems = pushHistoryItems.toImmutableList(), diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryView.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryView.kt index 7315cb4e5a..be10a2845e 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryView.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryView.kt @@ -100,14 +100,14 @@ fun PushHistoryView( }, onClick = { showMenu = false - state.eventSink(PushHistoryEvents.SetShowOnlyErrors(state.showOnlyErrors.not())) + state.eventSink(PushHistoryEvent.SetShowOnlyErrors(state.showOnlyErrors.not())) }, ) DropdownMenuItem( text = { Text(stringResource(id = CommonStrings.action_reset)) }, onClick = { showMenu = false - state.eventSink(PushHistoryEvents.Reset(requiresConfirmation = true)) + state.eventSink(PushHistoryEvent.Reset(requiresConfirmation = true)) }, ) } @@ -132,8 +132,8 @@ fun PushHistoryView( title = stringResource(CommonStrings.dialog_title_confirmation), submitText = stringResource(CommonStrings.action_reset), cancelText = stringResource(CommonStrings.action_cancel), - onSubmitClick = { state.eventSink(PushHistoryEvents.Reset(requiresConfirmation = false)) }, - onDismiss = { state.eventSink(PushHistoryEvents.ClearDialog) }, + onSubmitClick = { state.eventSink(PushHistoryEvent.Reset(requiresConfirmation = false)) }, + onDismiss = { state.eventSink(PushHistoryEvent.ClearDialog) }, ) }, onErrorDismiss = {}, @@ -142,7 +142,7 @@ fun PushHistoryView( if (state.showNotSameAccountError) { ErrorDialog( content = "Please switch account first to navigate to the event.", - onSubmit = { state.eventSink(PushHistoryEvents.ClearDialog) } + onSubmit = { state.eventSink(PushHistoryEvent.ClearDialog) } ) } } @@ -175,7 +175,7 @@ private fun PushHistoryContent( val roomId = pushHistory.roomId val eventId = pushHistory.eventId if (sessionId != null && roomId != null && eventId != null) { - state.eventSink(PushHistoryEvents.NavigateTo(sessionId, roomId, eventId)) + state.eventSink(PushHistoryEvent.NavigateTo(sessionId, roomId, eventId)) } } ) diff --git a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenterTest.kt b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenterTest.kt index 15fb6b5f25..e378cc9af6 100644 --- a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenterTest.kt +++ b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryPresenterTest.kt @@ -73,9 +73,9 @@ class PushHistoryPresenterTest { ) presenter.test { val initialState = awaitItem() - initialState.eventSink(PushHistoryEvents.Reset(requiresConfirmation = true)) + initialState.eventSink(PushHistoryEvent.Reset(requiresConfirmation = true)) assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.ConfirmingNoParams) - initialState.eventSink(PushHistoryEvents.ClearDialog) + initialState.eventSink(PushHistoryEvent.ClearDialog) assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.Uninitialized) resetPushHistoryResult.assertions().isNeverCalled() } @@ -92,9 +92,9 @@ class PushHistoryPresenterTest { ) presenter.test { val initialState = awaitItem() - initialState.eventSink(PushHistoryEvents.Reset(requiresConfirmation = true)) + initialState.eventSink(PushHistoryEvent.Reset(requiresConfirmation = true)) assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.ConfirmingNoParams) - initialState.eventSink(PushHistoryEvents.Reset(requiresConfirmation = false)) + initialState.eventSink(PushHistoryEvent.Reset(requiresConfirmation = false)) assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.Loading) assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.Uninitialized) resetPushHistoryResult.assertions().isCalledOnce() @@ -115,13 +115,13 @@ class PushHistoryPresenterTest { pushService.emitPushHistoryItems(listOf(item, itemError)) awaitItem().let { state -> assertThat(state.pushHistoryItems).containsExactly(item, itemError) - state.eventSink(PushHistoryEvents.SetShowOnlyErrors(showOnlyErrors = true)) + state.eventSink(PushHistoryEvent.SetShowOnlyErrors(showOnlyErrors = true)) } skipItems(1) awaitItem().let { state -> assertThat(state.showOnlyErrors).isTrue() assertThat(state.pushHistoryItems).containsExactly(itemError) - state.eventSink(PushHistoryEvents.SetShowOnlyErrors(showOnlyErrors = false)) + state.eventSink(PushHistoryEvent.SetShowOnlyErrors(showOnlyErrors = false)) } skipItems(1) awaitItem().let { state -> @@ -142,7 +142,7 @@ class PushHistoryPresenterTest { presenter.test { val initialState = awaitItem() initialState.eventSink( - PushHistoryEvents.NavigateTo( + PushHistoryEvent.NavigateTo( sessionId = A_SESSION_ID, roomId = A_ROOM_ID, eventId = AN_EVENT_ID, @@ -160,7 +160,7 @@ class PushHistoryPresenterTest { presenter.test { val initialState = awaitItem() initialState.eventSink( - PushHistoryEvents.NavigateTo( + PushHistoryEvent.NavigateTo( sessionId = A_SESSION_ID_2, roomId = A_ROOM_ID, eventId = AN_EVENT_ID, @@ -168,7 +168,7 @@ class PushHistoryPresenterTest { ) assertThat(awaitItem().showNotSameAccountError).isTrue() // Reset error - initialState.eventSink(PushHistoryEvents.ClearDialog) + initialState.eventSink(PushHistoryEvent.ClearDialog) assertThat(awaitItem().showNotSameAccountError).isFalse() } } diff --git a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryViewTest.kt b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryViewTest.kt index b9f615d68e..989f7bdc10 100644 --- a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryViewTest.kt +++ b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/history/PushHistoryViewTest.kt @@ -30,8 +30,8 @@ import org.junit.Test class PushHistoryViewTest : RobolectricTest() { @Test - fun `clicking on Reset sends a PushHistoryEvents`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + fun `clicking on Reset sends a PushHistoryEvent`() = runAndroidComposeUiTest { + val eventsRecorder = EventsRecorder() setPushHistoryView( aPushHistoryState( pushCounter = 123, @@ -41,14 +41,14 @@ class PushHistoryViewTest : RobolectricTest() { val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu) onNodeWithContentDescription(menuContentDescription).performClick() clickOn(CommonStrings.action_reset) - eventsRecorder.assertSingle(PushHistoryEvents.Reset(requiresConfirmation = true)) + eventsRecorder.assertSingle(PushHistoryEvent.Reset(requiresConfirmation = true)) // Also check that the push counter is rendered onNodeWithText("123").assertExists() } @Test - fun `clicking on show only errors sends a PushHistoryEvents(true)`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + fun `clicking on show only errors sends a PushHistoryEvent(true)`() = runAndroidComposeUiTest { + val eventsRecorder = EventsRecorder() setPushHistoryView( aPushHistoryState( showOnlyErrors = false, @@ -58,12 +58,12 @@ class PushHistoryViewTest : RobolectricTest() { val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu) onNodeWithContentDescription(menuContentDescription).performClick() onNodeWithText("Show only errors").performClick() - eventsRecorder.assertSingle(PushHistoryEvents.SetShowOnlyErrors(showOnlyErrors = true)) + eventsRecorder.assertSingle(PushHistoryEvent.SetShowOnlyErrors(showOnlyErrors = true)) } @Test - fun `clicking on show only errors sends a PushHistoryEvents(false)`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + fun `clicking on show only errors sends a PushHistoryEvent(false)`() = runAndroidComposeUiTest { + val eventsRecorder = EventsRecorder() setPushHistoryView( aPushHistoryState( showOnlyErrors = true, @@ -73,12 +73,12 @@ class PushHistoryViewTest : RobolectricTest() { val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu) onNodeWithContentDescription(menuContentDescription).performClick() onNodeWithText("Show only errors").performClick() - eventsRecorder.assertSingle(PushHistoryEvents.SetShowOnlyErrors(showOnlyErrors = false)) + eventsRecorder.assertSingle(PushHistoryEvent.SetShowOnlyErrors(showOnlyErrors = false)) } @Test fun `clicking on an invalid event has no effect`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder(expectEvents = false) + val eventsRecorder = EventsRecorder(expectEvents = false) setPushHistoryView( aPushHistoryState( pushHistoryItems = listOf( @@ -95,7 +95,7 @@ class PushHistoryViewTest : RobolectricTest() { @Test fun `clicking on a valid event emits the expected Event`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setPushHistoryView( aPushHistoryState( pushHistoryItems = listOf( @@ -111,7 +111,7 @@ class PushHistoryViewTest : RobolectricTest() { ) onNodeWithText(A_FORMATTED_DATE).performClick() eventsRecorder.assertSingle( - PushHistoryEvents.NavigateTo( + PushHistoryEvent.NavigateTo( sessionId = A_SESSION_ID, roomId = A_ROOM_ID, eventId = AN_EVENT_ID,