mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 08:15:02 +00:00
UserProfileEvents -> UserProfileEvent
This commit is contained in:
+4
-4
@@ -17,7 +17,7 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import dev.zacsweers.metro.Assisted
|
||||
import dev.zacsweers.metro.AssistedInject
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfilePresenterFactory
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.api.UserProfileVerificationState
|
||||
@@ -112,12 +112,12 @@ class RoomMemberDetailsPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
fun handleEvent(event: UserProfileEvents) {
|
||||
fun handleEvent(event: UserProfileEvent) {
|
||||
when (event) {
|
||||
UserProfileEvents.WithdrawVerification -> coroutineScope.launch {
|
||||
UserProfileEvent.WithdrawVerification -> coroutineScope.launch {
|
||||
encryptionService.withdrawVerification(roomMemberId)
|
||||
}
|
||||
is UserProfileEvents.CopyToClipboard -> {
|
||||
is UserProfileEvent.CopyToClipboard -> {
|
||||
clipboardHelper.copyPlainText(event.text)
|
||||
snackbarDispatcher.post(SnackbarMessage(CommonStrings.common_copied_to_clipboard))
|
||||
}
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ package io.element.android.features.roomdetails.impl.members.details
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.roomdetails.impl.aJoinedRoom
|
||||
import io.element.android.features.roomdetails.impl.members.aRoomMember
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfilePresenterFactory
|
||||
import io.element.android.features.userprofile.api.UserProfileVerificationState
|
||||
import io.element.android.features.userprofile.shared.aUserProfileState
|
||||
@@ -348,7 +348,7 @@ class RoomMemberDetailsPresenterTest {
|
||||
|
||||
consumeItemsUntilPredicate { it.verificationState == UserProfileVerificationState.VERIFICATION_VIOLATION }
|
||||
|
||||
initialState.eventSink(UserProfileEvents.WithdrawVerification)
|
||||
initialState.eventSink(UserProfileEvent.WithdrawVerification)
|
||||
withdrawVerificationResult.assertions().isCalledOnce()
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -8,13 +8,13 @@
|
||||
|
||||
package io.element.android.features.userprofile.api
|
||||
|
||||
sealed interface UserProfileEvents {
|
||||
data object StartDM : UserProfileEvents
|
||||
data object ClearStartDMState : UserProfileEvents
|
||||
data class BlockUser(val needsConfirmation: Boolean = false) : UserProfileEvents
|
||||
data class UnblockUser(val needsConfirmation: Boolean = false) : UserProfileEvents
|
||||
data object ClearBlockUserError : UserProfileEvents
|
||||
data object ClearConfirmationDialog : UserProfileEvents
|
||||
data object WithdrawVerification : UserProfileEvents
|
||||
data class CopyToClipboard(val text: String) : UserProfileEvents
|
||||
sealed interface UserProfileEvent {
|
||||
data object StartDM : UserProfileEvent
|
||||
data object ClearStartDMState : UserProfileEvent
|
||||
data class BlockUser(val needsConfirmation: Boolean = false) : UserProfileEvent
|
||||
data class UnblockUser(val needsConfirmation: Boolean = false) : UserProfileEvent
|
||||
data object ClearBlockUserError : UserProfileEvent
|
||||
data object ClearConfirmationDialog : UserProfileEvent
|
||||
data object WithdrawVerification : UserProfileEvent
|
||||
data class CopyToClipboard(val text: String) : UserProfileEvent
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ data class UserProfileState(
|
||||
val canCall: Boolean,
|
||||
val snackbarMessage: SnackbarMessage?,
|
||||
val displayedStatus: DisplayedStatus?,
|
||||
val eventSink: (UserProfileEvents) -> Unit
|
||||
val eventSink: (UserProfileEvent) -> Unit
|
||||
) {
|
||||
enum class ConfirmationDialog {
|
||||
Block,
|
||||
|
||||
+10
-10
@@ -23,7 +23,7 @@ import dev.zacsweers.metro.AssistedFactory
|
||||
import dev.zacsweers.metro.AssistedInject
|
||||
import io.element.android.features.enterprise.api.SessionEnterpriseService
|
||||
import io.element.android.features.startchat.api.StartDMAction
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.api.UserProfileState.ConfirmationDialog
|
||||
import io.element.android.features.userprofile.api.UserProfileVerificationState
|
||||
@@ -101,9 +101,9 @@ class UserProfilePresenter(
|
||||
}
|
||||
val userProfile by produceState<MatrixUser?>(null) { value = client.getProfile(userId).getOrNull() }
|
||||
|
||||
fun handleEvent(event: UserProfileEvents) {
|
||||
fun handleEvent(event: UserProfileEvent) {
|
||||
when (event) {
|
||||
is UserProfileEvents.BlockUser -> {
|
||||
is UserProfileEvent.BlockUser -> {
|
||||
if (event.needsConfirmation) {
|
||||
confirmationDialog = ConfirmationDialog.Block
|
||||
} else {
|
||||
@@ -111,7 +111,7 @@ class UserProfilePresenter(
|
||||
coroutineScope.blockUser(isBlocked)
|
||||
}
|
||||
}
|
||||
is UserProfileEvents.UnblockUser -> {
|
||||
is UserProfileEvent.UnblockUser -> {
|
||||
if (event.needsConfirmation) {
|
||||
confirmationDialog = ConfirmationDialog.Unblock
|
||||
} else {
|
||||
@@ -119,11 +119,11 @@ class UserProfilePresenter(
|
||||
coroutineScope.unblockUser(isBlocked)
|
||||
}
|
||||
}
|
||||
UserProfileEvents.ClearConfirmationDialog -> confirmationDialog = null
|
||||
UserProfileEvents.ClearBlockUserError -> {
|
||||
UserProfileEvent.ClearConfirmationDialog -> confirmationDialog = null
|
||||
UserProfileEvent.ClearBlockUserError -> {
|
||||
isBlocked.value = AsyncData.Success(isBlocked.value.dataOrNull().orFalse())
|
||||
}
|
||||
UserProfileEvents.StartDM -> {
|
||||
UserProfileEvent.StartDM -> {
|
||||
coroutineScope.launch {
|
||||
startDMAction.execute(
|
||||
matrixUser = userProfile ?: MatrixUser(userId),
|
||||
@@ -132,12 +132,12 @@ class UserProfilePresenter(
|
||||
)
|
||||
}
|
||||
}
|
||||
UserProfileEvents.ClearStartDMState -> {
|
||||
UserProfileEvent.ClearStartDMState -> {
|
||||
startDmActionState.value = AsyncAction.Uninitialized
|
||||
}
|
||||
// Do nothing for other event as they are handled by the RoomMemberDetailsPresenter if needed
|
||||
UserProfileEvents.WithdrawVerification,
|
||||
is UserProfileEvents.CopyToClipboard -> Unit
|
||||
UserProfileEvent.WithdrawVerification,
|
||||
is UserProfileEvent.CopyToClipboard -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -18,7 +18,7 @@ import io.element.android.features.enterprise.test.FakeSessionEnterpriseService
|
||||
import io.element.android.features.invitepeople.test.FakeStartDMAction
|
||||
import io.element.android.features.startchat.api.ConfirmingStartDmWithMatrixUser
|
||||
import io.element.android.features.startchat.api.StartDMAction
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.api.UserProfileVerificationState
|
||||
import io.element.android.features.userprofile.impl.root.UserProfilePresenter
|
||||
@@ -182,12 +182,12 @@ class UserProfilePresenterTest {
|
||||
val presenter = createUserProfilePresenter()
|
||||
presenter.test {
|
||||
val initialState = awaitFirstItem()
|
||||
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = true))
|
||||
initialState.eventSink(UserProfileEvent.BlockUser(needsConfirmation = true))
|
||||
|
||||
val dialogState = awaitItem()
|
||||
assertThat(dialogState.displayConfirmationDialog).isEqualTo(UserProfileState.ConfirmationDialog.Block)
|
||||
|
||||
dialogState.eventSink(UserProfileEvents.ClearConfirmationDialog)
|
||||
dialogState.eventSink(UserProfileEvent.ClearConfirmationDialog)
|
||||
assertThat(awaitItem().displayConfirmationDialog).isNull()
|
||||
}
|
||||
}
|
||||
@@ -202,12 +202,12 @@ class UserProfilePresenterTest {
|
||||
)
|
||||
presenter.test {
|
||||
val initialState = awaitFirstItem()
|
||||
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = false))
|
||||
initialState.eventSink(UserProfileEvent.BlockUser(needsConfirmation = false))
|
||||
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
||||
ignoredUsersFlow.emit(persistentListOf(A_USER_ID))
|
||||
assertThat(awaitItem().isBlocked.dataOrNull()).isTrue()
|
||||
|
||||
initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = false))
|
||||
initialState.eventSink(UserProfileEvent.UnblockUser(needsConfirmation = false))
|
||||
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
||||
ignoredUsersFlow.emit(persistentListOf())
|
||||
assertThat(awaitItem().isBlocked.dataOrNull()).isFalse()
|
||||
@@ -222,12 +222,12 @@ class UserProfilePresenterTest {
|
||||
val presenter = createUserProfilePresenter(client = matrixClient)
|
||||
presenter.test {
|
||||
val initialState = awaitFirstItem(count = 2)
|
||||
initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = false))
|
||||
initialState.eventSink(UserProfileEvent.BlockUser(needsConfirmation = false))
|
||||
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
||||
val errorState = awaitItem()
|
||||
assertThat(errorState.isBlocked.errorOrNull()).isEqualTo(AN_EXCEPTION)
|
||||
// Clear error
|
||||
initialState.eventSink(UserProfileEvents.ClearBlockUserError)
|
||||
initialState.eventSink(UserProfileEvent.ClearBlockUserError)
|
||||
assertThat(awaitItem().isBlocked).isEqualTo(AsyncData.Success(false))
|
||||
}
|
||||
}
|
||||
@@ -240,12 +240,12 @@ class UserProfilePresenterTest {
|
||||
val presenter = createUserProfilePresenter(client = matrixClient)
|
||||
presenter.test {
|
||||
val initialState = awaitFirstItem(count = 2)
|
||||
initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = false))
|
||||
initialState.eventSink(UserProfileEvent.UnblockUser(needsConfirmation = false))
|
||||
assertThat(awaitItem().isBlocked.isLoading()).isTrue()
|
||||
val errorState = awaitItem()
|
||||
assertThat(errorState.isBlocked.errorOrNull()).isEqualTo(AN_EXCEPTION)
|
||||
// Clear error
|
||||
initialState.eventSink(UserProfileEvents.ClearBlockUserError)
|
||||
initialState.eventSink(UserProfileEvent.ClearBlockUserError)
|
||||
assertThat(awaitItem().isBlocked).isEqualTo(AsyncData.Success(true))
|
||||
}
|
||||
}
|
||||
@@ -255,12 +255,12 @@ class UserProfilePresenterTest {
|
||||
val presenter = createUserProfilePresenter()
|
||||
presenter.test {
|
||||
val initialState = awaitFirstItem()
|
||||
initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = true))
|
||||
initialState.eventSink(UserProfileEvent.UnblockUser(needsConfirmation = true))
|
||||
|
||||
val dialogState = awaitItem()
|
||||
assertThat(dialogState.displayConfirmationDialog).isEqualTo(UserProfileState.ConfirmationDialog.Unblock)
|
||||
|
||||
dialogState.eventSink(UserProfileEvents.ClearConfirmationDialog)
|
||||
dialogState.eventSink(UserProfileEvent.ClearConfirmationDialog)
|
||||
assertThat(awaitItem().displayConfirmationDialog).isNull()
|
||||
}
|
||||
}
|
||||
@@ -279,7 +279,7 @@ class UserProfilePresenterTest {
|
||||
val initialState = awaitFirstItem()
|
||||
assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
||||
val matrixUser = MatrixUser(UserId("@alice:server.org"))
|
||||
initialState.eventSink(UserProfileEvents.StartDM)
|
||||
initialState.eventSink(UserProfileEvent.StartDM)
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.startDmActionState).isEqualTo(startDMFailureResult)
|
||||
executeResult.assertions().isCalledOnce().with(
|
||||
@@ -287,7 +287,7 @@ class UserProfilePresenterTest {
|
||||
value(false),
|
||||
any(),
|
||||
)
|
||||
state.eventSink(UserProfileEvents.ClearStartDMState)
|
||||
state.eventSink(UserProfileEvent.ClearStartDMState)
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.startDmActionState.isUninitialized()).isTrue()
|
||||
@@ -309,7 +309,7 @@ class UserProfilePresenterTest {
|
||||
val initialState = awaitFirstItem()
|
||||
assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
||||
val matrixUser = MatrixUser(UserId("@alice:server.org"))
|
||||
initialState.eventSink(UserProfileEvents.StartDM)
|
||||
initialState.eventSink(UserProfileEvent.StartDM)
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.startDmActionState).isEqualTo(startDMSuccessResult)
|
||||
executeResult.assertions().isCalledOnce().with(
|
||||
@@ -335,7 +335,7 @@ class UserProfilePresenterTest {
|
||||
}.test {
|
||||
val initialState = awaitFirstItem()
|
||||
assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
||||
initialState.eventSink(UserProfileEvents.StartDM)
|
||||
initialState.eventSink(UserProfileEvent.StartDM)
|
||||
val confirmingState = awaitItem()
|
||||
assertThat(confirmingState.startDmActionState).isEqualTo(startDMConfirmationResult)
|
||||
executeResult.assertions().isCalledOnce().with(
|
||||
@@ -344,7 +344,7 @@ class UserProfilePresenterTest {
|
||||
any(),
|
||||
)
|
||||
// Cancelling should not create the DM
|
||||
confirmingState.eventSink(UserProfileEvents.ClearStartDMState)
|
||||
confirmingState.eventSink(UserProfileEvent.ClearStartDMState)
|
||||
val finalState = awaitItem()
|
||||
assertThat(finalState.startDmActionState.isUninitialized()).isTrue()
|
||||
executeResult.assertions().isCalledExactly(1)
|
||||
@@ -365,7 +365,7 @@ class UserProfilePresenterTest {
|
||||
}.test {
|
||||
val initialState = awaitFirstItem()
|
||||
assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java)
|
||||
initialState.eventSink(UserProfileEvents.StartDM)
|
||||
initialState.eventSink(UserProfileEvent.StartDM)
|
||||
val confirmingState = awaitItem()
|
||||
assertThat(confirmingState.startDmActionState).isEqualTo(startDMConfirmationResult)
|
||||
executeResult.assertions().isCalledOnce().with(
|
||||
@@ -374,7 +374,7 @@ class UserProfilePresenterTest {
|
||||
any(),
|
||||
)
|
||||
// Start DM again should invoke the action with createIfDmDoesNotExist = true
|
||||
confirmingState.eventSink(UserProfileEvents.StartDM)
|
||||
confirmingState.eventSink(UserProfileEvent.StartDM)
|
||||
executeResult.assertions().isCalledExactly(2).withSequence(
|
||||
listOf(value(matrixUser), value(false), any()),
|
||||
listOf(value(matrixUser), value(true), any()),
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ package io.element.android.features.userprofile.shared
|
||||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import io.element.android.features.startchat.api.ConfirmingStartDmWithMatrixUser
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.api.UserProfileVerificationState
|
||||
import io.element.android.libraries.architecture.AsyncAction
|
||||
@@ -50,7 +50,7 @@ fun aUserProfileState(
|
||||
canCall: Boolean = false,
|
||||
snackbarMessage: SnackbarMessage? = null,
|
||||
displayedStatus: DisplayedStatus? = null,
|
||||
eventSink: (UserProfileEvents) -> Unit = {},
|
||||
eventSink: (UserProfileEvent) -> Unit = {},
|
||||
) = UserProfileState(
|
||||
userId = userId,
|
||||
userName = userName,
|
||||
|
||||
+8
-8
@@ -23,7 +23,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||
import io.element.android.features.startchat.api.ConfirmingStartDmWithMatrixUser
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.api.UserProfileVerificationState
|
||||
import io.element.android.features.userprofile.shared.blockuser.BlockUserDialogs
|
||||
@@ -83,15 +83,15 @@ fun UserProfileView(
|
||||
openAvatarPreview(state.userName ?: state.userId.value, avatarUrl)
|
||||
},
|
||||
onUserIdClick = {
|
||||
state.eventSink(UserProfileEvents.CopyToClipboard(state.userId.value))
|
||||
state.eventSink(UserProfileEvent.CopyToClipboard(state.userId.value))
|
||||
},
|
||||
withdrawVerificationClick = { state.eventSink(UserProfileEvents.WithdrawVerification) },
|
||||
withdrawVerificationClick = { state.eventSink(UserProfileEvent.WithdrawVerification) },
|
||||
)
|
||||
UserProfileMainActionsSection(
|
||||
isCurrentUser = state.isCurrentUser,
|
||||
canCall = state.canCall,
|
||||
onShareUser = onShareUser,
|
||||
onStartDM = { state.eventSink(UserProfileEvents.StartDM) },
|
||||
onStartDM = { state.eventSink(UserProfileEvent.StartDM) },
|
||||
onCall = { intent -> state.dmRoomId?.let { onStartCall(it, intent) } }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(26.dp))
|
||||
@@ -109,18 +109,18 @@ fun UserProfileView(
|
||||
},
|
||||
onSuccess = onOpenDm,
|
||||
errorMessage = { stringResource(R.string.screen_start_chat_error_starting_chat) },
|
||||
onRetry = { state.eventSink(UserProfileEvents.StartDM) },
|
||||
onErrorDismiss = { state.eventSink(UserProfileEvents.ClearStartDMState) },
|
||||
onRetry = { state.eventSink(UserProfileEvent.StartDM) },
|
||||
onErrorDismiss = { state.eventSink(UserProfileEvent.ClearStartDMState) },
|
||||
confirmationDialog = { data ->
|
||||
if (data is ConfirmingStartDmWithMatrixUser) {
|
||||
CreateDmConfirmationBottomSheet(
|
||||
matrixUser = data.matrixUser,
|
||||
isUserIdentityUnknown = data.isUserIdentityUnknown,
|
||||
onSendInvite = {
|
||||
state.eventSink(UserProfileEvents.StartDM)
|
||||
state.eventSink(UserProfileEvent.StartDM)
|
||||
},
|
||||
onDismiss = {
|
||||
state.eventSink(UserProfileEvents.ClearStartDMState)
|
||||
state.eventSink(UserProfileEvent.ClearStartDMState)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
+5
-5
@@ -10,7 +10,7 @@ package io.element.android.features.userprofile.shared.blockuser
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.shared.R
|
||||
import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog
|
||||
@@ -23,24 +23,24 @@ fun BlockUserDialogs(state: UserProfileState) {
|
||||
BlockConfirmationDialog(
|
||||
onBlockAction = {
|
||||
state.eventSink(
|
||||
UserProfileEvents.BlockUser(
|
||||
UserProfileEvent.BlockUser(
|
||||
needsConfirmation = false
|
||||
)
|
||||
)
|
||||
},
|
||||
onDismiss = { state.eventSink(UserProfileEvents.ClearConfirmationDialog) }
|
||||
onDismiss = { state.eventSink(UserProfileEvent.ClearConfirmationDialog) }
|
||||
)
|
||||
}
|
||||
UserProfileState.ConfirmationDialog.Unblock -> {
|
||||
UnblockConfirmationDialog(
|
||||
onUnblockAction = {
|
||||
state.eventSink(
|
||||
UserProfileEvents.UnblockUser(
|
||||
UserProfileEvent.UnblockUser(
|
||||
needsConfirmation = false
|
||||
)
|
||||
)
|
||||
},
|
||||
onDismiss = { state.eventSink(UserProfileEvents.ClearConfirmationDialog) }
|
||||
onDismiss = { state.eventSink(UserProfileEvent.ClearConfirmationDialog) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -15,7 +15,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.shared.R
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
@@ -50,13 +50,13 @@ fun BlockUserSection(
|
||||
if (isBlocked is AsyncData.Failure) {
|
||||
RetryDialog(
|
||||
content = stringResource(CommonStrings.error_unknown),
|
||||
onDismiss = { state.eventSink(UserProfileEvents.ClearBlockUserError) },
|
||||
onDismiss = { state.eventSink(UserProfileEvent.ClearBlockUserError) },
|
||||
onRetry = {
|
||||
val event = when (isBlocked.prevData) {
|
||||
true -> UserProfileEvents.UnblockUser(needsConfirmation = false)
|
||||
false -> UserProfileEvents.BlockUser(needsConfirmation = false)
|
||||
true -> UserProfileEvent.UnblockUser(needsConfirmation = false)
|
||||
false -> UserProfileEvent.BlockUser(needsConfirmation = false)
|
||||
// null case Should not happen
|
||||
null -> UserProfileEvents.ClearBlockUserError
|
||||
null -> UserProfileEvent.ClearBlockUserError
|
||||
}
|
||||
state.eventSink(event)
|
||||
},
|
||||
@@ -68,7 +68,7 @@ fun BlockUserSection(
|
||||
private fun PreferenceBlockUser(
|
||||
isBlocked: Boolean?,
|
||||
isLoading: Boolean,
|
||||
eventSink: (UserProfileEvents) -> Unit,
|
||||
eventSink: (UserProfileEvent) -> Unit,
|
||||
) {
|
||||
val loadingCurrentValue = @Composable { _: Boolean ->
|
||||
CircularProgressIndicator(
|
||||
@@ -82,7 +82,7 @@ private fun PreferenceBlockUser(
|
||||
ListItem(
|
||||
content = { Text(stringResource(R.string.screen_dm_details_unblock_user)) },
|
||||
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Block())),
|
||||
onClick = { if (!isLoading) eventSink(UserProfileEvents.UnblockUser(needsConfirmation = true)) },
|
||||
onClick = { if (!isLoading) eventSink(UserProfileEvent.UnblockUser(needsConfirmation = true)) },
|
||||
trailingContent = if (isLoading) ListItemContent.Custom(loadingCurrentValue) else null,
|
||||
)
|
||||
} else {
|
||||
@@ -90,7 +90,7 @@ private fun PreferenceBlockUser(
|
||||
content = { Text(stringResource(R.string.screen_dm_details_block_user)) },
|
||||
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Block())),
|
||||
style = ListItemStyle.Destructive,
|
||||
onClick = { if (!isLoading) eventSink(UserProfileEvents.BlockUser(needsConfirmation = true)) },
|
||||
onClick = { if (!isLoading) eventSink(UserProfileEvent.BlockUser(needsConfirmation = true)) },
|
||||
trailingContent = if (isLoading) ListItemContent.Custom(loadingCurrentValue) else null,
|
||||
)
|
||||
}
|
||||
|
||||
+15
-15
@@ -16,7 +16,7 @@ import androidx.compose.ui.test.ExperimentalTestApi
|
||||
import androidx.compose.ui.test.hasTestTag
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.v2.runAndroidComposeUiTest
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.api.UserProfileVerificationState
|
||||
import io.element.android.features.userprofile.shared.R
|
||||
@@ -89,7 +89,7 @@ class UserProfileViewTest : RobolectricTest() {
|
||||
|
||||
@Test
|
||||
fun `on Message clicked - the StartDm event is emitted`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setUserProfileView(
|
||||
state = aUserProfileState(
|
||||
dmRoomId = A_ROOM_ID,
|
||||
@@ -97,7 +97,7 @@ class UserProfileViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(CommonStrings.action_message)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.StartDM)
|
||||
eventsRecorder.assertSingle(UserProfileEvent.StartDM)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,19 +131,19 @@ class UserProfileViewTest : RobolectricTest() {
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `on Block user clicked - a BlockUser event is emitted with needsConfirmation`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setUserProfileView(
|
||||
state = aUserProfileState(
|
||||
eventSink = eventsRecorder,
|
||||
),
|
||||
)
|
||||
clickOn(R.string.screen_dm_details_block_user)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.BlockUser(needsConfirmation = true))
|
||||
eventsRecorder.assertSingle(UserProfileEvent.BlockUser(needsConfirmation = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on confirming block user - a BlockUser event is emitted without needsConfirmation`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setUserProfileView(
|
||||
state = aUserProfileState(
|
||||
displayConfirmationDialog = UserProfileState.ConfirmationDialog.Block,
|
||||
@@ -151,12 +151,12 @@ class UserProfileViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(R.string.screen_dm_details_block_alert_action)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.BlockUser(needsConfirmation = false))
|
||||
eventsRecorder.assertSingle(UserProfileEvent.BlockUser(needsConfirmation = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on canceling blocking a user - a ClearConfirmationDialog event is emitted`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setUserProfileView(
|
||||
state = aUserProfileState(
|
||||
displayConfirmationDialog = UserProfileState.ConfirmationDialog.Block,
|
||||
@@ -164,13 +164,13 @@ class UserProfileViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(CommonStrings.action_cancel)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog)
|
||||
eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog)
|
||||
}
|
||||
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `on Unblock user clicked - an UnblockUser event is emitted with needsConfirmation`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setUserProfileView(
|
||||
state = aUserProfileState(
|
||||
isBlocked = AsyncData.Success(true),
|
||||
@@ -178,12 +178,12 @@ class UserProfileViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(R.string.screen_dm_details_unblock_user)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.UnblockUser(needsConfirmation = true))
|
||||
eventsRecorder.assertSingle(UserProfileEvent.UnblockUser(needsConfirmation = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on confirming Unblock user - an UnblockUser event is emitted without needsConfirmation`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setUserProfileView(
|
||||
state = aUserProfileState(
|
||||
isBlocked = AsyncData.Success(true),
|
||||
@@ -192,12 +192,12 @@ class UserProfileViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(R.string.screen_dm_details_unblock_alert_action)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.UnblockUser(needsConfirmation = false))
|
||||
eventsRecorder.assertSingle(UserProfileEvent.UnblockUser(needsConfirmation = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on canceling unblocking a user - a ClearConfirmationDialog event is emitted`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setUserProfileView(
|
||||
state = aUserProfileState(
|
||||
isBlocked = AsyncData.Success(true),
|
||||
@@ -206,7 +206,7 @@ class UserProfileViewTest : RobolectricTest() {
|
||||
),
|
||||
)
|
||||
clickOn(CommonStrings.action_cancel)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog)
|
||||
eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+9
-9
@@ -12,7 +12,7 @@ package io.element.android.features.userprofile.shared.blockuser
|
||||
|
||||
import androidx.compose.ui.test.ExperimentalTestApi
|
||||
import androidx.compose.ui.test.v2.runAndroidComposeUiTest
|
||||
import io.element.android.features.userprofile.api.UserProfileEvents
|
||||
import io.element.android.features.userprofile.api.UserProfileEvent
|
||||
import io.element.android.features.userprofile.api.UserProfileState
|
||||
import io.element.android.features.userprofile.shared.R
|
||||
import io.element.android.features.userprofile.shared.aUserProfileState
|
||||
@@ -25,7 +25,7 @@ import org.junit.Test
|
||||
class BlockUserDialogsTest : RobolectricTest() {
|
||||
@Test
|
||||
fun `confirm block user emit expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setContent {
|
||||
BlockUserDialogs(
|
||||
state = aUserProfileState(
|
||||
@@ -35,12 +35,12 @@ class BlockUserDialogsTest : RobolectricTest() {
|
||||
)
|
||||
}
|
||||
clickOn(R.string.screen_dm_details_block_alert_action)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.BlockUser(false))
|
||||
eventsRecorder.assertSingle(UserProfileEvent.BlockUser(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cancel block user emit expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setContent {
|
||||
BlockUserDialogs(
|
||||
state = aUserProfileState(
|
||||
@@ -50,12 +50,12 @@ class BlockUserDialogsTest : RobolectricTest() {
|
||||
)
|
||||
}
|
||||
clickOn(CommonStrings.action_cancel)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog)
|
||||
eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `confirm unblock user emit expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setContent {
|
||||
BlockUserDialogs(
|
||||
state = aUserProfileState(
|
||||
@@ -65,12 +65,12 @@ class BlockUserDialogsTest : RobolectricTest() {
|
||||
)
|
||||
}
|
||||
clickOn(R.string.screen_dm_details_unblock_alert_action)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.UnblockUser(false))
|
||||
eventsRecorder.assertSingle(UserProfileEvent.UnblockUser(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cancel unblock user emit expected Event`() = runAndroidComposeUiTest {
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setContent {
|
||||
BlockUserDialogs(
|
||||
state = aUserProfileState(
|
||||
@@ -80,6 +80,6 @@ class BlockUserDialogsTest : RobolectricTest() {
|
||||
)
|
||||
}
|
||||
clickOn(CommonStrings.action_cancel)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog)
|
||||
eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user