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

Commit 35629bd1 authored by Mark Kim's avatar Mark Kim Committed by Android (Google) Code Review
Browse files

Merge "Tests that archived apps are returned for AllAppListPage when...

Merge "Tests that archived apps are returned for AllAppListPage when "android.content.pm.archiving" flag is enabled" into main
parents 15ca95a3 90781a30
Loading
Loading
Loading
Loading
+44 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.settings.spa.app

import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.State
import androidx.compose.ui.test.assertIsDisplayed
@@ -38,16 +40,28 @@ import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.stub


@RunWith(AndroidJUnit4::class)
class AllAppListTest {
    @get:Rule
    val composeTestRule = createComposeRule()

    private val context: Context = ApplicationProvider.getApplicationContext()

    private val fakeNavControllerWrapper = FakeNavControllerWrapper()

    private val packageManager = mock<PackageManager> {
        on { getPackagesForUid(USER_ID) } doReturn arrayOf(PACKAGE_NAME)
    }

    private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
        on { packageManager } doReturn packageManager
    }

    @Test
    fun allAppListPageProvider_name() {
        assertThat(AllAppListPageProvider.name).isEqualTo("AllAppList")
@@ -175,6 +189,33 @@ class AllAppListTest {
            .isEqualTo("$SUMMARY${System.lineSeparator()}Not installed for this user")
    }

    @Test
    fun allAppListModel_archivedApp() {
        val app = mock<ApplicationInfo> {
            on { loadUnbadgedIcon(any()) } doReturn UNBADGED_ICON
            on { loadLabel(any()) } doReturn LABEL
        }
        app.isArchived = true
        packageManager.stub {
            on {
                getApplicationInfoAsUser(PACKAGE_NAME, 0, USER_ID)
            } doReturn app
        }
        composeTestRule.setContent {
            fakeNavControllerWrapper.Wrapper {
                with(AllAppListModel(context)) {
                    AppListItemModel(
                        record = AppRecordWithSize(app = app),
                        label = LABEL,
                        summary = stateOf(SUMMARY),
                    ).AppItem()
                }
            }
        }

        composeTestRule.onNodeWithText(LABEL).assertIsDisplayed()
    }

    private fun getAppListInput(): AppListInput<AppRecordWithSize> {
        lateinit var input: AppListInput<AppRecordWithSize>
        composeTestRule.setContent {
@@ -206,6 +247,7 @@ class AllAppListTest {
        const val PACKAGE_NAME = "package.name"
        const val LABEL = "Label"
        const val SUMMARY = "Summary"
        val UNBADGED_ICON = mock<Drawable>()
        val APP = ApplicationInfo().apply {
            packageName = PACKAGE_NAME
            flags = ApplicationInfo.FLAG_INSTALLED