mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
DeclineAndBlockEvents -> DeclineAndBlockEvent
This commit is contained in:
+6
-6
@@ -8,10 +8,10 @@
|
||||
|
||||
package io.element.android.features.invite.impl.declineandblock
|
||||
|
||||
sealed interface DeclineAndBlockEvents {
|
||||
data class UpdateReportReason(val reason: String) : DeclineAndBlockEvents
|
||||
data object ToggleReportRoom : DeclineAndBlockEvents
|
||||
data object ToggleBlockUser : DeclineAndBlockEvents
|
||||
data object Decline : DeclineAndBlockEvents
|
||||
data object ClearDeclineAction : DeclineAndBlockEvents
|
||||
sealed interface DeclineAndBlockEvent {
|
||||
data class UpdateReportReason(val reason: String) : DeclineAndBlockEvent
|
||||
data object ToggleReportRoom : DeclineAndBlockEvent
|
||||
data object ToggleBlockUser : DeclineAndBlockEvent
|
||||
data object Decline : DeclineAndBlockEvent
|
||||
data object ClearDeclineAction : DeclineAndBlockEvent
|
||||
}
|
||||
+6
-6
@@ -49,13 +49,13 @@ class DeclineAndBlockPresenter(
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
fun handleEvent(event: DeclineAndBlockEvents) {
|
||||
fun handleEvent(event: DeclineAndBlockEvent) {
|
||||
when (event) {
|
||||
DeclineAndBlockEvents.ClearDeclineAction -> declineAction.value = AsyncAction.Uninitialized
|
||||
DeclineAndBlockEvents.Decline -> coroutineScope.decline(reportReason, blockUser, reportRoom, declineAction)
|
||||
DeclineAndBlockEvents.ToggleBlockUser -> blockUser = !blockUser
|
||||
DeclineAndBlockEvents.ToggleReportRoom -> reportRoom = !reportRoom
|
||||
is DeclineAndBlockEvents.UpdateReportReason -> reportReason = event.reason
|
||||
DeclineAndBlockEvent.ClearDeclineAction -> declineAction.value = AsyncAction.Uninitialized
|
||||
DeclineAndBlockEvent.Decline -> coroutineScope.decline(reportReason, blockUser, reportRoom, declineAction)
|
||||
DeclineAndBlockEvent.ToggleBlockUser -> blockUser = !blockUser
|
||||
DeclineAndBlockEvent.ToggleReportRoom -> reportRoom = !reportRoom
|
||||
is DeclineAndBlockEvent.UpdateReportReason -> reportReason = event.reason
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ data class DeclineAndBlockState(
|
||||
val reportReason: String,
|
||||
val blockUser: Boolean,
|
||||
val declineAction: AsyncAction<Unit>,
|
||||
val eventSink: (DeclineAndBlockEvents) -> Unit
|
||||
val eventSink: (DeclineAndBlockEvent) -> Unit
|
||||
) {
|
||||
val canDecline = blockUser || reportRoom && reportReason.isNotEmpty()
|
||||
}
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ fun aDeclineAndBlockState(
|
||||
reportReason: String = "",
|
||||
blockUser: Boolean = false,
|
||||
declineAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
|
||||
eventSink: (DeclineAndBlockEvents) -> Unit = {},
|
||||
eventSink: (DeclineAndBlockEvent) -> Unit = {},
|
||||
) = DeclineAndBlockState(
|
||||
reportRoom = reportRoom,
|
||||
reportReason = reportReason,
|
||||
|
||||
+6
-6
@@ -56,8 +56,8 @@ fun DeclineAndBlockView(
|
||||
async = state.declineAction,
|
||||
onSuccess = { onDeclineSuccess() },
|
||||
errorMessage = { stringResource(CommonStrings.error_unknown) },
|
||||
onRetry = { state.eventSink(DeclineAndBlockEvents.Decline) },
|
||||
onErrorDismiss = { state.eventSink(DeclineAndBlockEvents.ClearDeclineAction) }
|
||||
onRetry = { state.eventSink(DeclineAndBlockEvent.Decline) },
|
||||
onErrorDismiss = { state.eventSink(DeclineAndBlockEvent.ClearDeclineAction) }
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
@@ -89,7 +89,7 @@ fun DeclineAndBlockView(
|
||||
Text(text = stringResource(R.string.screen_decline_and_block_block_user_option_description))
|
||||
},
|
||||
onClick = {
|
||||
state.eventSink(DeclineAndBlockEvents.ToggleBlockUser)
|
||||
state.eventSink(DeclineAndBlockEvent.ToggleBlockUser)
|
||||
},
|
||||
trailingContent = ListItemContent.Switch(checked = state.blockUser)
|
||||
)
|
||||
@@ -104,7 +104,7 @@ fun DeclineAndBlockView(
|
||||
Text(text = stringResource(R.string.screen_decline_and_block_report_user_option_description))
|
||||
},
|
||||
onClick = {
|
||||
state.eventSink(DeclineAndBlockEvents.ToggleReportRoom)
|
||||
state.eventSink(DeclineAndBlockEvent.ToggleReportRoom)
|
||||
},
|
||||
trailingContent = ListItemContent.Switch(checked = state.reportRoom)
|
||||
)
|
||||
@@ -113,7 +113,7 @@ fun DeclineAndBlockView(
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
TextField(
|
||||
value = state.reportReason,
|
||||
onValueChange = { state.eventSink(DeclineAndBlockEvents.UpdateReportReason(it)) },
|
||||
onValueChange = { state.eventSink(DeclineAndBlockEvent.UpdateReportReason(it)) },
|
||||
placeholder = stringResource(R.string.screen_decline_and_block_report_user_reason_placeholder),
|
||||
minLines = 3,
|
||||
enabled = !isDeclining,
|
||||
@@ -132,7 +132,7 @@ fun DeclineAndBlockView(
|
||||
enabled = !isDeclining && state.canDecline,
|
||||
onClick = {
|
||||
focusManager.clearFocus(force = true)
|
||||
state.eventSink(DeclineAndBlockEvents.Decline)
|
||||
state.eventSink(DeclineAndBlockEvent.Decline)
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
||||
+7
-7
@@ -53,21 +53,21 @@ class DeclineAndBlockPresenterTest {
|
||||
assertThat(state.blockUser).isTrue()
|
||||
assertThat(state.reportReason).isEmpty()
|
||||
assertThat(state.canDecline).isTrue()
|
||||
state.eventSink(DeclineAndBlockEvents.ToggleBlockUser)
|
||||
state.eventSink(DeclineAndBlockEvent.ToggleBlockUser)
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.reportRoom).isFalse()
|
||||
assertThat(state.blockUser).isFalse()
|
||||
assertThat(state.reportReason).isEmpty()
|
||||
assertThat(state.canDecline).isFalse()
|
||||
state.eventSink(DeclineAndBlockEvents.ToggleReportRoom)
|
||||
state.eventSink(DeclineAndBlockEvent.ToggleReportRoom)
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.reportRoom).isTrue()
|
||||
assertThat(state.blockUser).isFalse()
|
||||
assertThat(state.reportReason).isEmpty()
|
||||
assertThat(state.canDecline).isFalse()
|
||||
state.eventSink(DeclineAndBlockEvents.UpdateReportReason("Spam"))
|
||||
state.eventSink(DeclineAndBlockEvent.UpdateReportReason("Spam"))
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.reportRoom).isTrue()
|
||||
@@ -87,7 +87,7 @@ class DeclineAndBlockPresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
awaitItem().also { state ->
|
||||
state.eventSink(DeclineAndBlockEvents.Decline)
|
||||
state.eventSink(DeclineAndBlockEvent.Decline)
|
||||
}
|
||||
assertThat(awaitItem().declineAction.isLoading()).isTrue()
|
||||
awaitItem().also { state ->
|
||||
@@ -110,12 +110,12 @@ class DeclineAndBlockPresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
awaitItem().also { state ->
|
||||
state.eventSink(DeclineAndBlockEvents.Decline)
|
||||
state.eventSink(DeclineAndBlockEvent.Decline)
|
||||
}
|
||||
assertThat(awaitItem().declineAction.isLoading()).isTrue()
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.declineAction).isInstanceOf(AsyncAction.Failure::class.java)
|
||||
state.eventSink(DeclineAndBlockEvents.ClearDeclineAction)
|
||||
state.eventSink(DeclineAndBlockEvent.ClearDeclineAction)
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.declineAction).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
||||
@@ -137,7 +137,7 @@ class DeclineAndBlockPresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
awaitItem().also { state ->
|
||||
state.eventSink(DeclineAndBlockEvents.Decline)
|
||||
state.eventSink(DeclineAndBlockEvent.Decline)
|
||||
}
|
||||
assertThat(awaitItem().declineAction.isLoading()).isTrue()
|
||||
awaitItem().also { state ->
|
||||
|
||||
+11
-11
@@ -30,7 +30,7 @@ import org.junit.Test
|
||||
class DeclineAndBlockViewTest : RobolectricTest() {
|
||||
@Test
|
||||
fun `clicking on back invoke the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvent>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
setDeclineAndBlockView(
|
||||
aDeclineAndBlockState(
|
||||
@@ -44,7 +44,7 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
||||
|
||||
@Test
|
||||
fun `a successful decline invokes the expected callback`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvent>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
setDeclineAndBlockView(
|
||||
aDeclineAndBlockState(
|
||||
@@ -58,7 +58,7 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
||||
|
||||
@Test
|
||||
fun `clicking on decline when enabled emits the expected event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>()
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvent>()
|
||||
setDeclineAndBlockView(
|
||||
aDeclineAndBlockState(
|
||||
blockUser = true,
|
||||
@@ -66,12 +66,12 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(CommonStrings.action_decline)
|
||||
eventsRecorder.assertSingle(DeclineAndBlockEvents.Decline)
|
||||
eventsRecorder.assertSingle(DeclineAndBlockEvent.Decline)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clicking on decline when disabled does not emit event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>(expectEvents = false)
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvent>(expectEvents = false)
|
||||
setDeclineAndBlockView(
|
||||
aDeclineAndBlockState(
|
||||
blockUser = false,
|
||||
@@ -85,7 +85,7 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
||||
|
||||
@Test
|
||||
fun `clicking on block option emits the expected event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>()
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvent>()
|
||||
setDeclineAndBlockView(
|
||||
aDeclineAndBlockState(
|
||||
blockUser = true,
|
||||
@@ -93,12 +93,12 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(R.string.screen_decline_and_block_block_user_option_title)
|
||||
eventsRecorder.assertSingle(DeclineAndBlockEvents.ToggleBlockUser)
|
||||
eventsRecorder.assertSingle(DeclineAndBlockEvent.ToggleBlockUser)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clicking on report room option emits the expected event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>()
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvent>()
|
||||
setDeclineAndBlockView(
|
||||
aDeclineAndBlockState(
|
||||
reportRoom = true,
|
||||
@@ -106,12 +106,12 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(CommonStrings.action_report_room)
|
||||
eventsRecorder.assertSingle(DeclineAndBlockEvents.ToggleReportRoom)
|
||||
eventsRecorder.assertSingle(DeclineAndBlockEvent.ToggleReportRoom)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `typing text in the reason field emits the expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvents>()
|
||||
val eventsRecorder = EventsRecorder<DeclineAndBlockEvent>()
|
||||
setDeclineAndBlockView(
|
||||
aDeclineAndBlockState(
|
||||
reportRoom = true,
|
||||
@@ -120,7 +120,7 @@ class DeclineAndBlockViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
onNodeWithText("").performTextInput("Spam!")
|
||||
eventsRecorder.assertSingle(DeclineAndBlockEvents.UpdateReportReason("Spam!"))
|
||||
eventsRecorder.assertSingle(DeclineAndBlockEvent.UpdateReportReason("Spam!"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user