Avoid to save result of blank input.

 - Disable "Save" button if no input or only space chars.

fix: 335763360
Test: Manual test
Test: atest pass
Change-Id: Ied5f98ec0ce7d1f38f626211cb9f465781781cd8
diff --git a/src/com/android/settings/spa/network/SimOnboardingLabelSim.kt b/src/com/android/settings/spa/network/SimOnboardingLabelSim.kt
index 6c8ce6e..6466731 100644
--- a/src/com/android/settings/spa/network/SimOnboardingLabelSim.kt
+++ b/src/com/android/settings/spa/network/SimOnboardingLabelSim.kt
@@ -87,12 +87,17 @@
     }
     val phoneNumber = phoneNumber(subInfo)
     val alertDialogPresenter = rememberAlertDialogPresenter(
-        confirmButton = AlertDialogButton(stringResource(R.string.mobile_network_sim_name_rename)) {
+        confirmButton = AlertDialogButton(
+            stringResource(R.string.mobile_network_sim_name_rename),
+            titleSimName.isNotBlank()
+        ) {
             onboardingService.addItemForRenaming(
                 subInfo, if (titleSimName.isEmpty()) originalSimCarrierName else titleSimName
             )
         },
-        dismissButton = AlertDialogButton(stringResource(R.string.cancel)) {
+        dismissButton = AlertDialogButton(
+            stringResource(R.string.cancel),
+        ) {
             titleSimName = onboardingService.getSubscriptionInfoDisplayName(subInfo)
         },
         title = stringResource(R.string.sim_onboarding_label_sim_dialog_title),
@@ -107,7 +112,7 @@
                 placeholder = {Text(text = originalSimCarrierName)},
                 modifier = Modifier.fillMaxWidth().testTag("contentInput")
             ) {
-                titleSimName = if (it.matches(Regex("^\\s*$"))) originalSimCarrierName else it
+                titleSimName = it
             }
         },
     )
diff --git a/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingLabelSimTest.kt b/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingLabelSimTest.kt
index 79f53ca..ad2ba55 100644
--- a/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingLabelSimTest.kt
+++ b/tests/spa_unit/src/com/android/settings/spa/network/SimOnboardingLabelSimTest.kt
@@ -28,6 +28,8 @@
 import androidx.compose.ui.platform.LocalLifecycleOwner
 import androidx.compose.ui.semantics.SemanticsProperties
 import androidx.compose.ui.test.assertIsDisplayed
+import androidx.compose.ui.test.assertIsEnabled
+import androidx.compose.ui.test.assertIsNotEnabled
 import androidx.compose.ui.test.hasText
 import androidx.compose.ui.test.junit4.createComposeRule
 import androidx.compose.ui.test.onNodeWithTag
@@ -186,7 +188,7 @@
     }
 
     @Test
-    fun showDialog_clearContent_showOriginalDisplayName() {
+    fun showDialog_clearContent_saveBtnIsDisabled() {
         preSetupContent()
 
         composeTestRule.setContent {
@@ -196,15 +198,12 @@
         composeTestRule.onNodeWithText(DISPLAY_NAME_1).performClick()
         composeTestRule.onNodeWithTag(TEXT_FIELD_INPUT).performTextClearance()
 
-        assertEquals(
-            composeTestRule.onNodeWithTag(TEXT_FIELD_INPUT)
-                .fetchSemanticsNode()
-                .config[SemanticsProperties.EditableText].text, DISPLAY_NAME_1
-        )
+        composeTestRule.onNodeWithText(context.getString(R.string.mobile_network_sim_name_rename))
+            .assertIsNotEnabled()
     }
 
     @Test
-    fun showDialog_modifyContent_showModifiedDisplayName() {
+    fun showDialog_modifyContent_showAndSaveModifiedDisplayName() {
         val inputData = "input_data"
         preSetupContent()
 
@@ -232,7 +231,7 @@
     }
 
     @Test
-    fun showDialog_onlySpaceCharContent_showAndSaveOriginalDisplayName() {
+    fun showDialog_onlySpaceCharContent_saveBtnIsDisabled() {
         val spaceChars = "        ";
         preSetupContent()
 
@@ -241,30 +240,12 @@
         }
 
         // Simulate real operation,
-        // 1. Click preference of DISPLAY_NAME_1
         composeTestRule.onNodeWithText(DISPLAY_NAME_1).performClick()
-        // 2. Input space chars to EditText view
+        composeTestRule.onNodeWithTag(TEXT_FIELD_INPUT).performTextClearance()
         composeTestRule.onNodeWithTag(TEXT_FIELD_INPUT).performTextInput(spaceChars)
-        // 3. Remove the string of DISPLAY_NAME_1 from EditText view
-        repeat(DISPLAY_NAME_1.length) {
-            composeTestRule.onNodeWithTag(TEXT_FIELD_INPUT)
-                .performKeyPress(KeyEvent(NativeKeyEvent(ACTION_DOWN, KEYCODE_FORWARD_DEL)))
-        }
 
-        // Due to this TextField with Text and EditText, it need fetch correct node to get correct
-        // content.
-        assertEquals(
-            DISPLAY_NAME_1, composeTestRule.onNodeWithTag(TEXT_FIELD_INPUT)
-                .fetchSemanticsNode()
-                .config[SemanticsProperties.EditableText].text
-        )
-
-        // Click save button
         composeTestRule.onNodeWithText(context.getString(R.string.mobile_network_sim_name_rename))
-            .performClick()
-
-        // Check preference's name is still DISPLAY_NAME_1
-        composeTestRule.onNodeWithText(DISPLAY_NAME_1).assertExists()
+            .assertIsNotEnabled()
     }
 
     fun preSetupContent() {