Skip to content

Commit

Permalink
fix: change display name state [WPB-9653] (#3094)
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk authored Jun 14, 2024
1 parent a573beb commit 9297c06
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ChangeDisplayNameViewModel @Inject constructor(
) {
displayNameState = displayNameState.copy(loading = true)
viewModelScope.launch {
updateDisplayName(textState.toString().trim())
updateDisplayName(textState.text.toString().trim())
.also { displayNameState = displayNameState.copy(loading = false) }
.let {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import com.wire.kalium.logic.feature.user.UpdateDisplayNameUseCase
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.impl.annotations.MockK
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -120,6 +122,21 @@ class ChangeDisplayNameViewModelTest {
assertEquals(true, viewModel.displayNameState.saveEnabled)
}

@Test
fun `given valid name, when updating, then should take only text value not the whole state toString`() = runTest {
val (arrangement, viewModel) = Arrangement()
.withUserSaveNameResult(DisplayNameUpdateResult.Success)
.arrange()

val newValue = "valid new name"
viewModel.textState.setTextAndPlaceCursorAtEnd(newValue)
advanceUntilIdle()

viewModel.saveDisplayName(onFailure = {}, onSuccess = {})

coVerify(exactly = 1) { arrangement.updateDisplayNameUseCase(newValue) }
}

private class Arrangement {

@MockK
Expand Down

0 comments on commit 9297c06

Please sign in to comment.