From d64585255c32ebe3bb0ae7b4eea34c039a09630b 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:14:08 +0000 Subject: [PATCH 1/2] 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 b4080251aa6..818a70b9b27 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 @@ -95,7 +95,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 42a7a926e05..ef00ce0c20c 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 @@ -243,6 +243,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 From 002ce0dc66ad835cde52292b068dcf8cafa9c146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= Date: Fri, 20 Dec 2024 17:21:51 +0100 Subject: [PATCH 2/2] trigger build