From 4427e8923d66c09ff9c112f1adc6562e18768ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= <30429749+saleniuk@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:49:14 +0100 Subject: [PATCH] fix: allowing empty team name when migrating [WPB-15092] (#3763) --- .../teammigration/TeamMigrationViewModel.kt | 2 +- .../step2/TeamMigrationTeamNameStepScreen.kt | 2 +- .../teammigration/TeamMigrationViewModelTest.kt | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModel.kt index bf2b90fde04..4919c589571 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModel.kt @@ -108,7 +108,7 @@ class TeamMigrationViewModel @Inject constructor( fun migrateFromPersonalToTeamAccount(onSuccess: () -> Unit) { viewModelScope.launch { migrateFromPersonalToTeam.invoke( - teamMigrationState.teamNameTextState.text.toString(), + teamMigrationState.teamNameTextState.text.trim().toString(), ).let { result -> when (result) { is MigrateFromPersonalToTeamResult.Success -> { diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/step2/TeamMigrationTeamNameStepScreen.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/step2/TeamMigrationTeamNameStepScreen.kt index aa1e8a9ecf6..da3d8ab4504 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/step2/TeamMigrationTeamNameStepScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/teammigration/step2/TeamMigrationTeamNameStepScreen.kt @@ -129,7 +129,7 @@ private fun TeamMigrationTeamNameStepScreenContent( textFieldState = teamNameTextFieldState, ) } - val isContinueButtonEnabled = teamNameTextFieldState.text.isNotEmpty() + val isContinueButtonEnabled = teamNameTextFieldState.text.isNotEmpty() && teamNameTextFieldState.text.isNotBlank() BottomLineButtons( isContinueButtonEnabled = isContinueButtonEnabled, onContinue = onContinueButtonClicked, diff --git a/app/src/test/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModelTest.kt index 8fb30394cc2..e6e833a1604 100644 --- a/app/src/test/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/userprofile/teammigration/TeamMigrationViewModelTest.kt @@ -225,6 +225,22 @@ class TeamMigrationViewModelTest { Assertions.assertNull(viewModel.teamMigrationState.migrationFailure) } + @Test + fun `given team name with spaces at start or end, when invoking migration, then trim the name`() = runTest { + // given + val (arrangement, viewModel) = Arrangement() + .withMigrateFromPersonalToTeamSuccess() + .arrange() + val onSuccess = {} + viewModel.teamMigrationState.teamNameTextState.setTextAndPlaceCursorAtEnd(" ${Arrangement.TEAM_NAME} ") + // when + viewModel.migrateFromPersonalToTeamAccount(onSuccess) + // then + coVerify(exactly = 1) { + arrangement.migrateFromPersonalToTeam(Arrangement.TEAM_NAME) + } + } + private class Arrangement { @MockK