Check APN type is selected before save

Not allow save APN without type.

Fix: 340969975
Test: manual - APN Settings
Test: unit test
Change-Id: I91f8e8137fc234c9c860fd446b7a1e2acfa11fc7
This commit is contained in:
Chaohui Wang
2024-05-24 15:56:06 +08:00
parent 574d64197a
commit 2faad6df6e
5 changed files with 65 additions and 13 deletions

View File

@@ -17,7 +17,11 @@
package com.android.settings.network.apn
import android.telephony.data.ApnSetting
import androidx.compose.runtime.mutableStateOf
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settings.network.apn.ApnTypes.isValid
import com.android.settings.network.apn.ApnTypes.toApnType
import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckOption
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
@@ -25,6 +29,50 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ApnTypesTest {
@Test
fun isValid_hasSelected() {
val options = listOf(
SettingsDropdownCheckOption(text = APN_TYPE, selected = mutableStateOf(true)),
)
val isValid = options.isValid()
assertThat(isValid).isTrue()
}
@Test
fun isValid_hasNotSelected() {
val options = listOf(
SettingsDropdownCheckOption(text = APN_TYPE, selected = mutableStateOf(false)),
)
val isValid = options.isValid()
assertThat(isValid).isFalse()
}
@Test
fun toApnType_hasSelected() {
val options = listOf(
SettingsDropdownCheckOption(text = APN_TYPE, selected = mutableStateOf(true)),
)
val apnType = options.toApnType()
assertThat(apnType).isEqualTo(APN_TYPE)
}
@Test
fun toApnType_hasNotSelected() {
val options = listOf(
SettingsDropdownCheckOption(text = APN_TYPE, selected = mutableStateOf(false)),
)
val apnType = options.toApnType()
assertThat(apnType).isEmpty()
}
@Test
fun getPreSelectedApnType_regular() {
val apnType = ApnTypes.getPreSelectedApnType(CustomizedConfig())
@@ -42,4 +90,8 @@ class ApnTypesTest {
assertThat(apnType).isEqualTo("default,mms,supl,hipri,fota,cbs,xcap")
}
private companion object {
const val APN_TYPE = "type"
}
}