mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 08:15:02 +00:00
PushHistoryEvents -> PushHistoryEvent
This commit is contained in:
+5
-5
@@ -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.RoomId
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
|
|
||||||
sealed interface PushHistoryEvents {
|
sealed interface PushHistoryEvent {
|
||||||
data class SetShowOnlyErrors(val showOnlyErrors: Boolean) : PushHistoryEvents
|
data class SetShowOnlyErrors(val showOnlyErrors: Boolean) : PushHistoryEvent
|
||||||
data class Reset(val requiresConfirmation: Boolean) : PushHistoryEvents
|
data class Reset(val requiresConfirmation: Boolean) : PushHistoryEvent
|
||||||
data class NavigateTo(val sessionId: SessionId, val roomId: RoomId, val eventId: EventId) : PushHistoryEvents
|
data class NavigateTo(val sessionId: SessionId, val roomId: RoomId, val eventId: EventId) : PushHistoryEvent
|
||||||
data object ClearDialog : PushHistoryEvents
|
data object ClearDialog : PushHistoryEvent
|
||||||
}
|
}
|
||||||
+5
-5
@@ -62,12 +62,12 @@ class PushHistoryPresenter(
|
|||||||
var resetAction: AsyncAction<Unit> by remember { mutableStateOf(AsyncAction.Uninitialized) }
|
var resetAction: AsyncAction<Unit> by remember { mutableStateOf(AsyncAction.Uninitialized) }
|
||||||
var showNotSameAccountError by remember { mutableStateOf(false) }
|
var showNotSameAccountError by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
fun handleEvent(event: PushHistoryEvents) {
|
fun handleEvent(event: PushHistoryEvent) {
|
||||||
when (event) {
|
when (event) {
|
||||||
is PushHistoryEvents.SetShowOnlyErrors -> {
|
is PushHistoryEvent.SetShowOnlyErrors -> {
|
||||||
showOnlyErrors = event.showOnlyErrors
|
showOnlyErrors = event.showOnlyErrors
|
||||||
}
|
}
|
||||||
is PushHistoryEvents.Reset -> {
|
is PushHistoryEvent.Reset -> {
|
||||||
if (event.requiresConfirmation) {
|
if (event.requiresConfirmation) {
|
||||||
resetAction = AsyncAction.ConfirmingNoParams
|
resetAction = AsyncAction.ConfirmingNoParams
|
||||||
} else {
|
} else {
|
||||||
@@ -78,11 +78,11 @@ class PushHistoryPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PushHistoryEvents.ClearDialog -> {
|
PushHistoryEvent.ClearDialog -> {
|
||||||
resetAction = AsyncAction.Uninitialized
|
resetAction = AsyncAction.Uninitialized
|
||||||
showNotSameAccountError = false
|
showNotSameAccountError = false
|
||||||
}
|
}
|
||||||
is PushHistoryEvents.NavigateTo -> {
|
is PushHistoryEvent.NavigateTo -> {
|
||||||
if (event.sessionId != sessionId) {
|
if (event.sessionId != sessionId) {
|
||||||
showNotSameAccountError = true
|
showNotSameAccountError = true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -18,5 +18,5 @@ data class PushHistoryState(
|
|||||||
val showOnlyErrors: Boolean,
|
val showOnlyErrors: Boolean,
|
||||||
val resetAction: AsyncAction<Unit>,
|
val resetAction: AsyncAction<Unit>,
|
||||||
val showNotSameAccountError: Boolean,
|
val showNotSameAccountError: Boolean,
|
||||||
val eventSink: (PushHistoryEvents) -> Unit,
|
val eventSink: (PushHistoryEvent) -> Unit,
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ fun aPushHistoryState(
|
|||||||
showOnlyErrors: Boolean = false,
|
showOnlyErrors: Boolean = false,
|
||||||
resetAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
|
resetAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
|
||||||
showNotSameAccountError: Boolean = false,
|
showNotSameAccountError: Boolean = false,
|
||||||
eventSink: (PushHistoryEvents) -> Unit = {},
|
eventSink: (PushHistoryEvent) -> Unit = {},
|
||||||
) = PushHistoryState(
|
) = PushHistoryState(
|
||||||
pushCounter = pushCounter,
|
pushCounter = pushCounter,
|
||||||
pushHistoryItems = pushHistoryItems.toImmutableList(),
|
pushHistoryItems = pushHistoryItems.toImmutableList(),
|
||||||
|
|||||||
+6
-6
@@ -100,14 +100,14 @@ fun PushHistoryView(
|
|||||||
},
|
},
|
||||||
onClick = {
|
onClick = {
|
||||||
showMenu = false
|
showMenu = false
|
||||||
state.eventSink(PushHistoryEvents.SetShowOnlyErrors(state.showOnlyErrors.not()))
|
state.eventSink(PushHistoryEvent.SetShowOnlyErrors(state.showOnlyErrors.not()))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(stringResource(id = CommonStrings.action_reset)) },
|
text = { Text(stringResource(id = CommonStrings.action_reset)) },
|
||||||
onClick = {
|
onClick = {
|
||||||
showMenu = false
|
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),
|
title = stringResource(CommonStrings.dialog_title_confirmation),
|
||||||
submitText = stringResource(CommonStrings.action_reset),
|
submitText = stringResource(CommonStrings.action_reset),
|
||||||
cancelText = stringResource(CommonStrings.action_cancel),
|
cancelText = stringResource(CommonStrings.action_cancel),
|
||||||
onSubmitClick = { state.eventSink(PushHistoryEvents.Reset(requiresConfirmation = false)) },
|
onSubmitClick = { state.eventSink(PushHistoryEvent.Reset(requiresConfirmation = false)) },
|
||||||
onDismiss = { state.eventSink(PushHistoryEvents.ClearDialog) },
|
onDismiss = { state.eventSink(PushHistoryEvent.ClearDialog) },
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onErrorDismiss = {},
|
onErrorDismiss = {},
|
||||||
@@ -142,7 +142,7 @@ fun PushHistoryView(
|
|||||||
if (state.showNotSameAccountError) {
|
if (state.showNotSameAccountError) {
|
||||||
ErrorDialog(
|
ErrorDialog(
|
||||||
content = "Please switch account first to navigate to the event.",
|
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 roomId = pushHistory.roomId
|
||||||
val eventId = pushHistory.eventId
|
val eventId = pushHistory.eventId
|
||||||
if (sessionId != null && roomId != null && eventId != null) {
|
if (sessionId != null && roomId != null && eventId != null) {
|
||||||
state.eventSink(PushHistoryEvents.NavigateTo(sessionId, roomId, eventId))
|
state.eventSink(PushHistoryEvent.NavigateTo(sessionId, roomId, eventId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+9
-9
@@ -73,9 +73,9 @@ class PushHistoryPresenterTest {
|
|||||||
)
|
)
|
||||||
presenter.test {
|
presenter.test {
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
initialState.eventSink(PushHistoryEvents.Reset(requiresConfirmation = true))
|
initialState.eventSink(PushHistoryEvent.Reset(requiresConfirmation = true))
|
||||||
assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.ConfirmingNoParams)
|
assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.ConfirmingNoParams)
|
||||||
initialState.eventSink(PushHistoryEvents.ClearDialog)
|
initialState.eventSink(PushHistoryEvent.ClearDialog)
|
||||||
assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.Uninitialized)
|
assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.Uninitialized)
|
||||||
resetPushHistoryResult.assertions().isNeverCalled()
|
resetPushHistoryResult.assertions().isNeverCalled()
|
||||||
}
|
}
|
||||||
@@ -92,9 +92,9 @@ class PushHistoryPresenterTest {
|
|||||||
)
|
)
|
||||||
presenter.test {
|
presenter.test {
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
initialState.eventSink(PushHistoryEvents.Reset(requiresConfirmation = true))
|
initialState.eventSink(PushHistoryEvent.Reset(requiresConfirmation = true))
|
||||||
assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.ConfirmingNoParams)
|
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.Loading)
|
||||||
assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.Uninitialized)
|
assertThat(awaitItem().resetAction).isEqualTo(AsyncAction.Uninitialized)
|
||||||
resetPushHistoryResult.assertions().isCalledOnce()
|
resetPushHistoryResult.assertions().isCalledOnce()
|
||||||
@@ -115,13 +115,13 @@ class PushHistoryPresenterTest {
|
|||||||
pushService.emitPushHistoryItems(listOf(item, itemError))
|
pushService.emitPushHistoryItems(listOf(item, itemError))
|
||||||
awaitItem().let { state ->
|
awaitItem().let { state ->
|
||||||
assertThat(state.pushHistoryItems).containsExactly(item, itemError)
|
assertThat(state.pushHistoryItems).containsExactly(item, itemError)
|
||||||
state.eventSink(PushHistoryEvents.SetShowOnlyErrors(showOnlyErrors = true))
|
state.eventSink(PushHistoryEvent.SetShowOnlyErrors(showOnlyErrors = true))
|
||||||
}
|
}
|
||||||
skipItems(1)
|
skipItems(1)
|
||||||
awaitItem().let { state ->
|
awaitItem().let { state ->
|
||||||
assertThat(state.showOnlyErrors).isTrue()
|
assertThat(state.showOnlyErrors).isTrue()
|
||||||
assertThat(state.pushHistoryItems).containsExactly(itemError)
|
assertThat(state.pushHistoryItems).containsExactly(itemError)
|
||||||
state.eventSink(PushHistoryEvents.SetShowOnlyErrors(showOnlyErrors = false))
|
state.eventSink(PushHistoryEvent.SetShowOnlyErrors(showOnlyErrors = false))
|
||||||
}
|
}
|
||||||
skipItems(1)
|
skipItems(1)
|
||||||
awaitItem().let { state ->
|
awaitItem().let { state ->
|
||||||
@@ -142,7 +142,7 @@ class PushHistoryPresenterTest {
|
|||||||
presenter.test {
|
presenter.test {
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
initialState.eventSink(
|
initialState.eventSink(
|
||||||
PushHistoryEvents.NavigateTo(
|
PushHistoryEvent.NavigateTo(
|
||||||
sessionId = A_SESSION_ID,
|
sessionId = A_SESSION_ID,
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
eventId = AN_EVENT_ID,
|
eventId = AN_EVENT_ID,
|
||||||
@@ -160,7 +160,7 @@ class PushHistoryPresenterTest {
|
|||||||
presenter.test {
|
presenter.test {
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
initialState.eventSink(
|
initialState.eventSink(
|
||||||
PushHistoryEvents.NavigateTo(
|
PushHistoryEvent.NavigateTo(
|
||||||
sessionId = A_SESSION_ID_2,
|
sessionId = A_SESSION_ID_2,
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
eventId = AN_EVENT_ID,
|
eventId = AN_EVENT_ID,
|
||||||
@@ -168,7 +168,7 @@ class PushHistoryPresenterTest {
|
|||||||
)
|
)
|
||||||
assertThat(awaitItem().showNotSameAccountError).isTrue()
|
assertThat(awaitItem().showNotSameAccountError).isTrue()
|
||||||
// Reset error
|
// Reset error
|
||||||
initialState.eventSink(PushHistoryEvents.ClearDialog)
|
initialState.eventSink(PushHistoryEvent.ClearDialog)
|
||||||
assertThat(awaitItem().showNotSameAccountError).isFalse()
|
assertThat(awaitItem().showNotSameAccountError).isFalse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -30,8 +30,8 @@ import org.junit.Test
|
|||||||
|
|
||||||
class PushHistoryViewTest : RobolectricTest() {
|
class PushHistoryViewTest : RobolectricTest() {
|
||||||
@Test
|
@Test
|
||||||
fun `clicking on Reset sends a PushHistoryEvents`() = runAndroidComposeUiTest {
|
fun `clicking on Reset sends a PushHistoryEvent`() = runAndroidComposeUiTest {
|
||||||
val eventsRecorder = EventsRecorder<PushHistoryEvents>()
|
val eventsRecorder = EventsRecorder<PushHistoryEvent>()
|
||||||
setPushHistoryView(
|
setPushHistoryView(
|
||||||
aPushHistoryState(
|
aPushHistoryState(
|
||||||
pushCounter = 123,
|
pushCounter = 123,
|
||||||
@@ -41,14 +41,14 @@ class PushHistoryViewTest : RobolectricTest() {
|
|||||||
val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu)
|
val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu)
|
||||||
onNodeWithContentDescription(menuContentDescription).performClick()
|
onNodeWithContentDescription(menuContentDescription).performClick()
|
||||||
clickOn(CommonStrings.action_reset)
|
clickOn(CommonStrings.action_reset)
|
||||||
eventsRecorder.assertSingle(PushHistoryEvents.Reset(requiresConfirmation = true))
|
eventsRecorder.assertSingle(PushHistoryEvent.Reset(requiresConfirmation = true))
|
||||||
// Also check that the push counter is rendered
|
// Also check that the push counter is rendered
|
||||||
onNodeWithText("123").assertExists()
|
onNodeWithText("123").assertExists()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `clicking on show only errors sends a PushHistoryEvents(true)`() = runAndroidComposeUiTest {
|
fun `clicking on show only errors sends a PushHistoryEvent(true)`() = runAndroidComposeUiTest {
|
||||||
val eventsRecorder = EventsRecorder<PushHistoryEvents>()
|
val eventsRecorder = EventsRecorder<PushHistoryEvent>()
|
||||||
setPushHistoryView(
|
setPushHistoryView(
|
||||||
aPushHistoryState(
|
aPushHistoryState(
|
||||||
showOnlyErrors = false,
|
showOnlyErrors = false,
|
||||||
@@ -58,12 +58,12 @@ class PushHistoryViewTest : RobolectricTest() {
|
|||||||
val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu)
|
val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu)
|
||||||
onNodeWithContentDescription(menuContentDescription).performClick()
|
onNodeWithContentDescription(menuContentDescription).performClick()
|
||||||
onNodeWithText("Show only errors").performClick()
|
onNodeWithText("Show only errors").performClick()
|
||||||
eventsRecorder.assertSingle(PushHistoryEvents.SetShowOnlyErrors(showOnlyErrors = true))
|
eventsRecorder.assertSingle(PushHistoryEvent.SetShowOnlyErrors(showOnlyErrors = true))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `clicking on show only errors sends a PushHistoryEvents(false)`() = runAndroidComposeUiTest {
|
fun `clicking on show only errors sends a PushHistoryEvent(false)`() = runAndroidComposeUiTest {
|
||||||
val eventsRecorder = EventsRecorder<PushHistoryEvents>()
|
val eventsRecorder = EventsRecorder<PushHistoryEvent>()
|
||||||
setPushHistoryView(
|
setPushHistoryView(
|
||||||
aPushHistoryState(
|
aPushHistoryState(
|
||||||
showOnlyErrors = true,
|
showOnlyErrors = true,
|
||||||
@@ -73,12 +73,12 @@ class PushHistoryViewTest : RobolectricTest() {
|
|||||||
val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu)
|
val menuContentDescription = activity!!.getString(CommonStrings.a11y_user_menu)
|
||||||
onNodeWithContentDescription(menuContentDescription).performClick()
|
onNodeWithContentDescription(menuContentDescription).performClick()
|
||||||
onNodeWithText("Show only errors").performClick()
|
onNodeWithText("Show only errors").performClick()
|
||||||
eventsRecorder.assertSingle(PushHistoryEvents.SetShowOnlyErrors(showOnlyErrors = false))
|
eventsRecorder.assertSingle(PushHistoryEvent.SetShowOnlyErrors(showOnlyErrors = false))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `clicking on an invalid event has no effect`() = runAndroidComposeUiTest {
|
fun `clicking on an invalid event has no effect`() = runAndroidComposeUiTest {
|
||||||
val eventsRecorder = EventsRecorder<PushHistoryEvents>(expectEvents = false)
|
val eventsRecorder = EventsRecorder<PushHistoryEvent>(expectEvents = false)
|
||||||
setPushHistoryView(
|
setPushHistoryView(
|
||||||
aPushHistoryState(
|
aPushHistoryState(
|
||||||
pushHistoryItems = listOf(
|
pushHistoryItems = listOf(
|
||||||
@@ -95,7 +95,7 @@ class PushHistoryViewTest : RobolectricTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `clicking on a valid event emits the expected Event`() = runAndroidComposeUiTest {
|
fun `clicking on a valid event emits the expected Event`() = runAndroidComposeUiTest {
|
||||||
val eventsRecorder = EventsRecorder<PushHistoryEvents>()
|
val eventsRecorder = EventsRecorder<PushHistoryEvent>()
|
||||||
setPushHistoryView(
|
setPushHistoryView(
|
||||||
aPushHistoryState(
|
aPushHistoryState(
|
||||||
pushHistoryItems = listOf(
|
pushHistoryItems = listOf(
|
||||||
@@ -111,7 +111,7 @@ class PushHistoryViewTest : RobolectricTest() {
|
|||||||
)
|
)
|
||||||
onNodeWithText(A_FORMATTED_DATE).performClick()
|
onNodeWithText(A_FORMATTED_DATE).performClick()
|
||||||
eventsRecorder.assertSingle(
|
eventsRecorder.assertSingle(
|
||||||
PushHistoryEvents.NavigateTo(
|
PushHistoryEvent.NavigateTo(
|
||||||
sessionId = A_SESSION_ID,
|
sessionId = A_SESSION_ID,
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
eventId = AN_EVENT_ID,
|
eventId = AN_EVENT_ID,
|
||||||
|
|||||||
Reference in New Issue
Block a user