EditUserProfileEvents -> EditUserProfileEvent

This commit is contained in:
Benoit Marty 2025-12-03 17:04:53 +01:00 committed by Benoit Marty
parent f913b5963e
commit 2f52d7c683
7 changed files with 71 additions and 71 deletions

View file

@ -10,10 +10,10 @@ package io.element.android.features.preferences.impl.user.editprofile
import io.element.android.libraries.matrix.ui.media.AvatarAction import io.element.android.libraries.matrix.ui.media.AvatarAction
sealed interface EditUserProfileEvents { sealed interface EditUserProfileEvent {
data class HandleAvatarAction(val action: AvatarAction) : EditUserProfileEvents data class HandleAvatarAction(val action: AvatarAction) : EditUserProfileEvent
data class UpdateDisplayName(val name: String) : EditUserProfileEvents data class UpdateDisplayName(val name: String) : EditUserProfileEvent
data object Exit : EditUserProfileEvents data object Exit : EditUserProfileEvent
data object Save : EditUserProfileEvents data object Save : EditUserProfileEvent
data object CloseDialog : EditUserProfileEvents data object CloseDialog : EditUserProfileEvent
} }

View file

@ -112,15 +112,15 @@ class EditUserProfilePresenter(
!userDisplayName.isNullOrBlank() && hasProfileChanged !userDisplayName.isNullOrBlank() && hasProfileChanged
} }
fun handleEvent(event: EditUserProfileEvents) { fun handleEvent(event: EditUserProfileEvent) {
when (event) { when (event) {
is EditUserProfileEvents.Save -> localCoroutineScope.saveChanges( is EditUserProfileEvent.Save -> localCoroutineScope.saveChanges(
name = userDisplayName, name = userDisplayName,
avatarUri = userAvatarUri?.toUri(), avatarUri = userAvatarUri?.toUri(),
currentUser = matrixUser, currentUser = matrixUser,
action = saveAction, action = saveAction,
) )
is EditUserProfileEvents.HandleAvatarAction -> { is EditUserProfileEvent.HandleAvatarAction -> {
when (event.action) { when (event.action) {
AvatarAction.ChoosePhoto -> galleryImagePicker.launch() AvatarAction.ChoosePhoto -> galleryImagePicker.launch()
AvatarAction.TakePhoto -> if (cameraPermissionState.permissionGranted) { AvatarAction.TakePhoto -> if (cameraPermissionState.permissionGranted) {
@ -135,8 +135,8 @@ class EditUserProfilePresenter(
} }
} }
} }
is EditUserProfileEvents.UpdateDisplayName -> userDisplayName = event.name is EditUserProfileEvent.UpdateDisplayName -> userDisplayName = event.name
EditUserProfileEvents.Exit -> { EditUserProfileEvent.Exit -> {
when (saveAction.value) { when (saveAction.value) {
is AsyncAction.Confirming -> { is AsyncAction.Confirming -> {
// Close the dialog right now // Close the dialog right now
@ -157,7 +157,7 @@ class EditUserProfilePresenter(
} }
} }
} }
EditUserProfileEvents.CloseDialog -> saveAction.value = AsyncAction.Uninitialized EditUserProfileEvent.CloseDialog -> saveAction.value = AsyncAction.Uninitialized
} }
} }

View file

@ -22,5 +22,5 @@ data class EditUserProfileState(
val saveButtonEnabled: Boolean, val saveButtonEnabled: Boolean,
val saveAction: AsyncAction<Unit>, val saveAction: AsyncAction<Unit>,
val cameraPermissionState: PermissionsState, val cameraPermissionState: PermissionsState,
val eventSink: (EditUserProfileEvents) -> Unit val eventSink: (EditUserProfileEvent) -> Unit
) )

View file

@ -33,7 +33,7 @@ fun aEditUserProfileState(
saveButtonEnabled: Boolean = true, saveButtonEnabled: Boolean = true,
saveAction: AsyncAction<Unit> = AsyncAction.Uninitialized, saveAction: AsyncAction<Unit> = AsyncAction.Uninitialized,
cameraPermissionState: PermissionsState = aPermissionsState(showDialog = false), cameraPermissionState: PermissionsState = aPermissionsState(showDialog = false),
eventSink: (EditUserProfileEvents) -> Unit = {}, eventSink: (EditUserProfileEvent) -> Unit = {},
) = EditUserProfileState( ) = EditUserProfileState(
userId = userId, userId = userId,
displayName = displayName, displayName = displayName,

View file

@ -68,7 +68,7 @@ fun EditUserProfileView(
fun onBackClick() { fun onBackClick() {
focusManager.clearFocus() focusManager.clearFocus()
state.eventSink(EditUserProfileEvents.Exit) state.eventSink(EditUserProfileEvent.Exit)
} }
BackHandler( BackHandler(
@ -87,7 +87,7 @@ fun EditUserProfileView(
enabled = state.saveButtonEnabled, enabled = state.saveButtonEnabled,
onClick = { onClick = {
focusManager.clearFocus() focusManager.clearFocus()
state.eventSink(EditUserProfileEvents.Save) state.eventSink(EditUserProfileEvent.Save)
}, },
) )
} }
@ -125,7 +125,7 @@ fun EditUserProfileView(
value = state.displayName, value = state.displayName,
placeholder = stringResource(CommonStrings.common_room_name_placeholder), placeholder = stringResource(CommonStrings.common_room_name_placeholder),
singleLine = true, singleLine = true,
onValueChange = { state.eventSink(EditUserProfileEvents.UpdateDisplayName(it)) }, onValueChange = { state.eventSink(EditUserProfileEvent.UpdateDisplayName(it)) },
) )
} }
@ -133,7 +133,7 @@ fun EditUserProfileView(
actions = state.avatarActions, actions = state.avatarActions,
isVisible = isAvatarActionsSheetVisible.value, isVisible = isAvatarActionsSheetVisible.value,
onDismiss = { isAvatarActionsSheetVisible.value = false }, onDismiss = { isAvatarActionsSheetVisible.value = false },
onSelectAction = { state.eventSink(EditUserProfileEvents.HandleAvatarAction(it)) } onSelectAction = { state.eventSink(EditUserProfileEvent.HandleAvatarAction(it)) }
) )
AsyncActionView( AsyncActionView(
@ -147,9 +147,9 @@ fun EditUserProfileView(
when (confirming) { when (confirming) {
is AsyncAction.ConfirmingCancellation -> { is AsyncAction.ConfirmingCancellation -> {
SaveChangesDialog( SaveChangesDialog(
onSaveClick = { state.eventSink(EditUserProfileEvents.Save) }, onSaveClick = { state.eventSink(EditUserProfileEvent.Save) },
onDiscardClick = { state.eventSink(EditUserProfileEvents.Exit) }, onDiscardClick = { state.eventSink(EditUserProfileEvent.Exit) },
onDismiss = { state.eventSink(EditUserProfileEvents.CloseDialog) }, onDismiss = { state.eventSink(EditUserProfileEvent.CloseDialog) },
) )
} }
} }
@ -157,7 +157,7 @@ fun EditUserProfileView(
onSuccess = { onEditProfileSuccess() }, onSuccess = { onEditProfileSuccess() },
errorTitle = { stringResource(R.string.screen_edit_profile_error_title) }, errorTitle = { stringResource(R.string.screen_edit_profile_error_title) },
errorMessage = { stringResource(R.string.screen_edit_profile_error) }, errorMessage = { stringResource(R.string.screen_edit_profile_error) },
onErrorDismiss = { state.eventSink(EditUserProfileEvents.CloseDialog) }, onErrorDismiss = { state.eventSink(EditUserProfileEvent.CloseDialog) },
) )
} }
PermissionsView( PermissionsView(

View file

@ -124,7 +124,7 @@ class EditUserProfilePresenterTest {
) )
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(EditUserProfileEvents.Exit) initialState.eventSink(EditUserProfileEvent.Exit)
closeLambda.assertions().isCalledOnce() closeLambda.assertions().isCalledOnce()
} }
} }
@ -139,21 +139,21 @@ class EditUserProfilePresenterTest {
) )
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("New name")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("New name"))
val withUpdatedName = awaitItem() val withUpdatedName = awaitItem()
withUpdatedName.eventSink(EditUserProfileEvents.Exit) withUpdatedName.eventSink(EditUserProfileEvent.Exit)
val withConfirmation = awaitItem() val withConfirmation = awaitItem()
assertThat(withConfirmation.saveAction).isEqualTo(AsyncAction.ConfirmingCancellation) assertThat(withConfirmation.saveAction).isEqualTo(AsyncAction.ConfirmingCancellation)
// Cancel // Cancel
withConfirmation.eventSink(EditUserProfileEvents.CloseDialog) withConfirmation.eventSink(EditUserProfileEvent.CloseDialog)
val afterCancel = awaitItem() val afterCancel = awaitItem()
assertThat(afterCancel.saveAction).isEqualTo(AsyncAction.Uninitialized) assertThat(afterCancel.saveAction).isEqualTo(AsyncAction.Uninitialized)
// Try again and confirm // Try again and confirm
afterCancel.eventSink(EditUserProfileEvents.Exit) afterCancel.eventSink(EditUserProfileEvent.Exit)
val withConfirmation2 = awaitItem() val withConfirmation2 = awaitItem()
assertThat(withConfirmation2.saveAction).isEqualTo(AsyncAction.ConfirmingCancellation) assertThat(withConfirmation2.saveAction).isEqualTo(AsyncAction.ConfirmingCancellation)
closeLambda.assertions().isNeverCalled() closeLambda.assertions().isNeverCalled()
withConfirmation2.eventSink(EditUserProfileEvents.Exit) withConfirmation2.eventSink(EditUserProfileEvent.Exit)
// Dialog is closed // Dialog is closed
val finalState = awaitItem() val finalState = awaitItem()
assertThat(finalState.saveAction).isEqualTo(AsyncAction.Uninitialized) assertThat(finalState.saveAction).isEqualTo(AsyncAction.Uninitialized)
@ -174,17 +174,17 @@ class EditUserProfilePresenterTest {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.displayName).isEqualTo("Name") assertThat(initialState.displayName).isEqualTo("Name")
assertThat(initialState.userAvatarUrl).isEqualTo(AN_AVATAR_URL) assertThat(initialState.userAvatarUrl).isEqualTo(AN_AVATAR_URL)
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("Name II")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("Name II"))
awaitItem().apply { awaitItem().apply {
assertThat(displayName).isEqualTo("Name II") assertThat(displayName).isEqualTo("Name II")
assertThat(userAvatarUrl).isEqualTo(AN_AVATAR_URL) assertThat(userAvatarUrl).isEqualTo(AN_AVATAR_URL)
} }
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("Name III")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("Name III"))
awaitItem().apply { awaitItem().apply {
assertThat(displayName).isEqualTo("Name III") assertThat(displayName).isEqualTo("Name III")
assertThat(userAvatarUrl).isEqualTo(AN_AVATAR_URL) assertThat(userAvatarUrl).isEqualTo(AN_AVATAR_URL)
} }
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.Remove)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.Remove))
awaitItem().apply { awaitItem().apply {
assertThat(displayName).isEqualTo("Name III") assertThat(displayName).isEqualTo("Name III")
assertThat(userAvatarUrl).isNull() assertThat(userAvatarUrl).isNull()
@ -205,7 +205,7 @@ class EditUserProfilePresenterTest {
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.userAvatarUrl).isEqualTo(AN_AVATAR_URL) assertThat(initialState.userAvatarUrl).isEqualTo(AN_AVATAR_URL)
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.ChoosePhoto)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.ChoosePhoto))
awaitItem().apply { awaitItem().apply {
assertThat(userAvatarUrl).isEqualTo(ANOTHER_AVATAR_URL) assertThat(userAvatarUrl).isEqualTo(ANOTHER_AVATAR_URL)
} }
@ -229,7 +229,7 @@ class EditUserProfilePresenterTest {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.userAvatarUrl).isEqualTo(AN_AVATAR_URL) assertThat(initialState.userAvatarUrl).isEqualTo(AN_AVATAR_URL)
assertThat(initialState.cameraPermissionState.permissionGranted).isFalse() assertThat(initialState.cameraPermissionState.permissionGranted).isFalse()
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.TakePhoto)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.TakePhoto))
val stateWithAskingPermission = awaitItem() val stateWithAskingPermission = awaitItem()
assertThat(stateWithAskingPermission.cameraPermissionState.showDialog).isTrue() assertThat(stateWithAskingPermission.cameraPermissionState.showDialog).isTrue()
fakePermissionsPresenter.setPermissionGranted() fakePermissionsPresenter.setPermissionGranted()
@ -239,7 +239,7 @@ class EditUserProfilePresenterTest {
assertThat(stateWithNewAvatar.userAvatarUrl).isEqualTo(ANOTHER_AVATAR_URL) assertThat(stateWithNewAvatar.userAvatarUrl).isEqualTo(ANOTHER_AVATAR_URL)
// Do it again, no permission is requested // Do it again, no permission is requested
fakePickerProvider.givenResult(userAvatarUri) fakePickerProvider.givenResult(userAvatarUri)
stateWithNewAvatar.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.TakePhoto)) stateWithNewAvatar.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.TakePhoto))
val stateWithNewAvatar2 = awaitItem() val stateWithNewAvatar2 = awaitItem()
assertThat(stateWithNewAvatar2.userAvatarUrl).isEqualTo(AN_AVATAR_URL) assertThat(stateWithNewAvatar2.userAvatarUrl).isEqualTo(AN_AVATAR_URL)
deleteCallback.assertions().isCalledExactly(2).withSequence( deleteCallback.assertions().isCalledExactly(2).withSequence(
@ -264,22 +264,22 @@ class EditUserProfilePresenterTest {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.saveButtonEnabled).isFalse() assertThat(initialState.saveButtonEnabled).isFalse()
// Once a change is made, the save button is enabled // Once a change is made, the save button is enabled
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("Name II")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("Name II"))
awaitItem().apply { awaitItem().apply {
assertThat(saveButtonEnabled).isTrue() assertThat(saveButtonEnabled).isTrue()
} }
// If it's reverted then the save disables again // If it's reverted then the save disables again
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("Name")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("Name"))
awaitItem().apply { awaitItem().apply {
assertThat(saveButtonEnabled).isFalse() assertThat(saveButtonEnabled).isFalse()
} }
// Make a change... // Make a change...
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.Remove)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.Remove))
awaitItem().apply { awaitItem().apply {
assertThat(saveButtonEnabled).isTrue() assertThat(saveButtonEnabled).isTrue()
} }
// Revert it... // Revert it...
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.ChoosePhoto)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.ChoosePhoto))
awaitItem().apply { awaitItem().apply {
assertThat(saveButtonEnabled).isFalse() assertThat(saveButtonEnabled).isFalse()
} }
@ -305,22 +305,22 @@ class EditUserProfilePresenterTest {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.saveButtonEnabled).isFalse() assertThat(initialState.saveButtonEnabled).isFalse()
// Once a change is made, the save button is enabled // Once a change is made, the save button is enabled
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("Name II")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("Name II"))
awaitItem().apply { awaitItem().apply {
assertThat(saveButtonEnabled).isTrue() assertThat(saveButtonEnabled).isTrue()
} }
// If it's reverted then the save disables again // If it's reverted then the save disables again
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("Name")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("Name"))
awaitItem().apply { awaitItem().apply {
assertThat(saveButtonEnabled).isFalse() assertThat(saveButtonEnabled).isFalse()
} }
// Make a change... // Make a change...
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.ChoosePhoto)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.ChoosePhoto))
awaitItem().apply { awaitItem().apply {
assertThat(saveButtonEnabled).isTrue() assertThat(saveButtonEnabled).isTrue()
} }
// Revert it... // Revert it...
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.Remove)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.Remove))
awaitItem().apply { awaitItem().apply {
assertThat(saveButtonEnabled).isFalse() assertThat(saveButtonEnabled).isFalse()
} }
@ -344,9 +344,9 @@ class EditUserProfilePresenterTest {
) )
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("New name")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("New name"))
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.Remove)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.Remove))
initialState.eventSink(EditUserProfileEvents.Save) initialState.eventSink(EditUserProfileEvent.Save)
consumeItemsUntilPredicate { matrixClient.setDisplayNameCalled && matrixClient.removeAvatarCalled && !matrixClient.uploadAvatarCalled } consumeItemsUntilPredicate { matrixClient.setDisplayNameCalled && matrixClient.removeAvatarCalled && !matrixClient.uploadAvatarCalled }
assertThat(matrixClient.setDisplayNameCalled).isTrue() assertThat(matrixClient.setDisplayNameCalled).isTrue()
assertThat(matrixClient.removeAvatarCalled).isTrue() assertThat(matrixClient.removeAvatarCalled).isTrue()
@ -365,8 +365,8 @@ class EditUserProfilePresenterTest {
) )
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName(" Name ")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName(" Name "))
initialState.eventSink(EditUserProfileEvents.Save) initialState.eventSink(EditUserProfileEvent.Save)
consumeItemsUntilTimeout() consumeItemsUntilTimeout()
assertThat(matrixClient.setDisplayNameCalled).isFalse() assertThat(matrixClient.setDisplayNameCalled).isFalse()
assertThat(matrixClient.uploadAvatarCalled).isFalse() assertThat(matrixClient.uploadAvatarCalled).isFalse()
@ -384,8 +384,8 @@ class EditUserProfilePresenterTest {
) )
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName(""))
initialState.eventSink(EditUserProfileEvents.Save) initialState.eventSink(EditUserProfileEvent.Save)
assertThat(matrixClient.setDisplayNameCalled).isFalse() assertThat(matrixClient.setDisplayNameCalled).isFalse()
assertThat(matrixClient.uploadAvatarCalled).isFalse() assertThat(matrixClient.uploadAvatarCalled).isFalse()
assertThat(matrixClient.removeAvatarCalled).isFalse() assertThat(matrixClient.removeAvatarCalled).isFalse()
@ -407,8 +407,8 @@ class EditUserProfilePresenterTest {
) )
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.ChoosePhoto)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.ChoosePhoto))
initialState.eventSink(EditUserProfileEvents.Save) initialState.eventSink(EditUserProfileEvent.Save)
consumeItemsUntilPredicate { matrixClient.uploadAvatarCalled } consumeItemsUntilPredicate { matrixClient.uploadAvatarCalled }
assertThat(matrixClient.uploadAvatarCalled).isTrue() assertThat(matrixClient.uploadAvatarCalled).isTrue()
} }
@ -429,8 +429,8 @@ class EditUserProfilePresenterTest {
fakeMediaPreProcessor.givenResult(Result.failure(RuntimeException("Oh no"))) fakeMediaPreProcessor.givenResult(Result.failure(RuntimeException("Oh no")))
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(EditUserProfileEvents.HandleAvatarAction(AvatarAction.ChoosePhoto)) initialState.eventSink(EditUserProfileEvent.HandleAvatarAction(AvatarAction.ChoosePhoto))
initialState.eventSink(EditUserProfileEvents.Save) initialState.eventSink(EditUserProfileEvent.Save)
skipItems(2) skipItems(2)
assertThat(matrixClient.uploadAvatarCalled).isFalse() assertThat(matrixClient.uploadAvatarCalled).isFalse()
assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Failure::class.java) assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Failure::class.java)
@ -443,7 +443,7 @@ class EditUserProfilePresenterTest {
val matrixClient = FakeMatrixClient().apply { val matrixClient = FakeMatrixClient().apply {
givenSetDisplayNameResult(Result.failure(RuntimeException("!"))) givenSetDisplayNameResult(Result.failure(RuntimeException("!")))
} }
saveAndAssertFailure(user, matrixClient, EditUserProfileEvents.UpdateDisplayName("New name")) saveAndAssertFailure(user, matrixClient, EditUserProfileEvent.UpdateDisplayName("New name"))
} }
@Test @Test
@ -452,7 +452,7 @@ class EditUserProfilePresenterTest {
val matrixClient = FakeMatrixClient().apply { val matrixClient = FakeMatrixClient().apply {
givenRemoveAvatarResult(Result.failure(RuntimeException("!"))) givenRemoveAvatarResult(Result.failure(RuntimeException("!")))
} }
saveAndAssertFailure(user, matrixClient, EditUserProfileEvents.HandleAvatarAction(AvatarAction.Remove)) saveAndAssertFailure(user, matrixClient, EditUserProfileEvent.HandleAvatarAction(AvatarAction.Remove))
} }
@Test @Test
@ -462,7 +462,7 @@ class EditUserProfilePresenterTest {
val matrixClient = FakeMatrixClient().apply { val matrixClient = FakeMatrixClient().apply {
givenUploadAvatarResult(Result.failure(RuntimeException("!"))) givenUploadAvatarResult(Result.failure(RuntimeException("!")))
} }
saveAndAssertFailure(user, matrixClient, EditUserProfileEvents.HandleAvatarAction(AvatarAction.ChoosePhoto)) saveAndAssertFailure(user, matrixClient, EditUserProfileEvent.HandleAvatarAction(AvatarAction.ChoosePhoto))
} }
@Test @Test
@ -475,16 +475,16 @@ class EditUserProfilePresenterTest {
val presenter = createEditUserProfilePresenter(matrixUser = user, matrixClient = matrixClient) val presenter = createEditUserProfilePresenter(matrixUser = user, matrixClient = matrixClient)
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(EditUserProfileEvents.UpdateDisplayName("foo")) initialState.eventSink(EditUserProfileEvent.UpdateDisplayName("foo"))
initialState.eventSink(EditUserProfileEvents.Save) initialState.eventSink(EditUserProfileEvent.Save)
skipItems(2) skipItems(2)
assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Failure::class.java) assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Failure::class.java)
initialState.eventSink(EditUserProfileEvents.CloseDialog) initialState.eventSink(EditUserProfileEvent.CloseDialog)
assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Uninitialized::class.java) assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Uninitialized::class.java)
} }
} }
private suspend fun saveAndAssertFailure(matrixUser: MatrixUser, matrixClient: MatrixClient, event: EditUserProfileEvents) { private suspend fun saveAndAssertFailure(matrixUser: MatrixUser, matrixClient: MatrixClient, event: EditUserProfileEvent) {
val presenter = createEditUserProfilePresenter( val presenter = createEditUserProfilePresenter(
matrixUser = matrixUser, matrixUser = matrixUser,
matrixClient = matrixClient, matrixClient = matrixClient,
@ -495,7 +495,7 @@ class EditUserProfilePresenterTest {
presenter.test { presenter.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(event) initialState.eventSink(event)
initialState.eventSink(EditUserProfileEvents.Save) initialState.eventSink(EditUserProfileEvent.Save)
skipItems(1) skipItems(1)
assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Loading::class.java) assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Loading::class.java)
assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Failure::class.java) assertThat(awaitItem().saveAction).isInstanceOf(AsyncAction.Failure::class.java)

View file

@ -34,19 +34,19 @@ class EditUserProfileViewTest {
@Test @Test
fun `clicking on back emits the expected event`() { fun `clicking on back emits the expected event`() {
val eventsRecorder = EventsRecorder<EditUserProfileEvents>() val eventsRecorder = EventsRecorder<EditUserProfileEvent>()
rule.setEditUserProfileView( rule.setEditUserProfileView(
aEditUserProfileState( aEditUserProfileState(
eventSink = eventsRecorder, eventSink = eventsRecorder,
), ),
) )
rule.pressBack() rule.pressBack()
eventsRecorder.assertSingle(EditUserProfileEvents.Exit) eventsRecorder.assertSingle(EditUserProfileEvent.Exit)
} }
@Test @Test
fun `clicking on save from the exit confirmation dialog emits the expected event`() { fun `clicking on save from the exit confirmation dialog emits the expected event`() {
val eventsRecorder = EventsRecorder<EditUserProfileEvents>() val eventsRecorder = EventsRecorder<EditUserProfileEvent>()
rule.setEditUserProfileView( rule.setEditUserProfileView(
aEditUserProfileState( aEditUserProfileState(
saveAction = AsyncAction.ConfirmingCancellation, saveAction = AsyncAction.ConfirmingCancellation,
@ -54,12 +54,12 @@ class EditUserProfileViewTest {
), ),
) )
rule.clickOn(CommonStrings.action_save, inDialog = true) rule.clickOn(CommonStrings.action_save, inDialog = true)
eventsRecorder.assertSingle(EditUserProfileEvents.Save) eventsRecorder.assertSingle(EditUserProfileEvent.Save)
} }
@Test @Test
fun `clicking on discard exit emits the expected event`() { fun `clicking on discard exit emits the expected event`() {
val eventsRecorder = EventsRecorder<EditUserProfileEvents>() val eventsRecorder = EventsRecorder<EditUserProfileEvent>()
rule.setEditUserProfileView( rule.setEditUserProfileView(
aEditUserProfileState( aEditUserProfileState(
saveAction = AsyncAction.ConfirmingCancellation, saveAction = AsyncAction.ConfirmingCancellation,
@ -67,12 +67,12 @@ class EditUserProfileViewTest {
), ),
) )
rule.clickOn(CommonStrings.action_discard) rule.clickOn(CommonStrings.action_discard)
eventsRecorder.assertSingle(EditUserProfileEvents.Exit) eventsRecorder.assertSingle(EditUserProfileEvent.Exit)
} }
@Test @Test
fun `clicking on save emits the expected event`() { fun `clicking on save emits the expected event`() {
val eventsRecorder = EventsRecorder<EditUserProfileEvents>() val eventsRecorder = EventsRecorder<EditUserProfileEvent>()
rule.setEditUserProfileView( rule.setEditUserProfileView(
aEditUserProfileState( aEditUserProfileState(
saveButtonEnabled = true, saveButtonEnabled = true,
@ -81,12 +81,12 @@ class EditUserProfileViewTest {
), ),
) )
rule.clickOn(CommonStrings.action_save) rule.clickOn(CommonStrings.action_save)
eventsRecorder.assertSingle(EditUserProfileEvents.Save) eventsRecorder.assertSingle(EditUserProfileEvent.Save)
} }
@Test @Test
fun `clicking on avatar opens the bottom sheet dialog`() { fun `clicking on avatar opens the bottom sheet dialog`() {
val eventsRecorder = EventsRecorder<EditUserProfileEvents>() val eventsRecorder = EventsRecorder<EditUserProfileEvent>()
val actions = listOf( val actions = listOf(
AvatarAction.TakePhoto, AvatarAction.TakePhoto,
AvatarAction.ChoosePhoto, AvatarAction.ChoosePhoto,
@ -110,7 +110,7 @@ class EditUserProfileViewTest {
@Test @Test
fun `success invokes the expected callback`() { fun `success invokes the expected callback`() {
val eventsRecorder = EventsRecorder<EditUserProfileEvents>(expectEvents = false) val eventsRecorder = EventsRecorder<EditUserProfileEvent>(expectEvents = false)
ensureCalledOnce { callback -> ensureCalledOnce { callback ->
rule.setEditUserProfileView( rule.setEditUserProfileView(
aEditUserProfileState( aEditUserProfileState(