Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 739f6ff6 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Avoid empty line for storage summary" into main

parents 7bc4ea01 ca0542d2
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.settingslib.spa.framework.util.mapItem
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.ui.SpinnerOption
import com.android.settingslib.spaprivileged.framework.compose.getPlaceholder
import com.android.settingslib.spaprivileged.model.app.AppListModel
import com.android.settingslib.spaprivileged.model.app.AppRecord
import com.android.settingslib.spaprivileged.model.app.installed
@@ -131,7 +132,11 @@ class AllAppListModel(
    override fun getSummary(option: Int, record: AppRecordWithSize): () -> String {
        val storageSummary = record.app.getStorageSummary()
        return {
            val summaryList = mutableListOf(storageSummary.value)
            val summaryList = mutableListOf<String>()
            val storageSummaryValue = storageSummary.value
            if (storageSummaryValue.isNotBlank()) {
                summaryList += storageSummaryValue
            }
            when {
                !record.app.installed && !record.app.isArchived -> {
                    summaryList += context.getString(R.string.not_installed)
@@ -142,6 +147,7 @@ class AllAppListModel(
                }
            }
            summaryList.joinToString(separator = System.lineSeparator())
                .ifEmpty { context.getPlaceholder() } // Use placeholder to reduce flaky
        }
    }

+35 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.settings.R
import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.testutils.FakeNavControllerWrapper
import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
import com.android.settingslib.spaprivileged.framework.compose.getPlaceholder
import com.android.settingslib.spaprivileged.template.app.AppListInput
import com.android.settingslib.spaprivileged.template.app.AppListItemModel
import com.google.common.truth.Truth.assertThat
@@ -142,7 +143,7 @@ class AllAppListTest {
    }

    @Test
    fun allAppListModel_getSummary() {
    fun listModelGetSummary_regular() {
        val listModel = AllAppListModel(context) { stateOf(SUMMARY) }

        lateinit var summary: () -> String
@@ -154,7 +155,19 @@ class AllAppListTest {
    }

    @Test
    fun allAppListModel_getSummaryWhenDisabled() {
    fun listModelGetSummary_emptyStorage() {
        val listModel = AllAppListModel(context) { stateOf("") }

        lateinit var summary: () -> String
        composeTestRule.setContent {
            summary = listModel.getSummary(option = 0, record = AppRecordWithSize(app = APP))
        }

        assertThat(summary()).isEqualTo(context.getPlaceholder())
    }

    @Test
    fun listModelGetSummary_disabled() {
        val listModel = AllAppListModel(context) { stateOf(SUMMARY) }
        val disabledApp = ApplicationInfo().apply {
            packageName = PACKAGE_NAME
@@ -172,7 +185,26 @@ class AllAppListTest {
    }

    @Test
    fun allAppListModel_getSummaryWhenNotInstalled() {
    fun listModelGetSummary_emptyStorageAndDisabled() {
        val listModel = AllAppListModel(context) { stateOf("") }
        val disabledApp = ApplicationInfo().apply {
            packageName = PACKAGE_NAME
            flags = ApplicationInfo.FLAG_INSTALLED
            enabled = false
        }

        lateinit var summary: () -> String
        composeTestRule.setContent {
            summary =
                listModel.getSummary(option = 0, record = AppRecordWithSize(app = disabledApp))
        }

        assertThat(summary())
            .isEqualTo(context.getString(com.android.settingslib.R.string.disabled))
    }

    @Test
    fun listModelGetSummary_notInstalled() {
        val listModel = AllAppListModel(context) { stateOf(SUMMARY) }
        val notInstalledApp = ApplicationInfo().apply {
            packageName = PACKAGE_NAME