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

Commit 37073bff authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Add noMoreOptions param to AppListPage

Default false. If true, then do not display more options action button,
including the "Show System" / "Hide System" action.

Bug: 285264906
Test: Unit test
Change-Id: I6e6c15275c428e66c45bf0da68a562a7319e3934
parent 4c45ee8c
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import com.android.settingslib.spaprivileged.template.common.UserProfilePager
/**
 * The full screen template for an App List page.
 *
 * @param noMoreOptions default false. If true, then do not display more options action button,
 * including the "Show System" / "Hide System" action.
 * @param header the description header appears before all the applications.
 */
@Composable
@@ -38,6 +40,7 @@ fun <T : AppRecord> AppListPage(
    title: String,
    listModel: AppListModel<T>,
    showInstantApps: Boolean = false,
    noMoreOptions: Boolean = false,
    matchAnyUserForAdmin: Boolean = false,
    primaryUserOnly: Boolean = false,
    noItemMessage: String? = null,
@@ -49,10 +52,12 @@ fun <T : AppRecord> AppListPage(
    SearchScaffold(
        title = title,
        actions = {
            if (!noMoreOptions) {
                MoreOptionsAction {
                    ShowSystemAction(showSystem.value) { showSystem.value = it }
                    moreOptions()
                }
            }
        },
    ) { bottomPadding, searchQuery ->
        UserProfilePager(primaryUserOnly) { userGroup ->
+25 −9
Original line number Diff line number Diff line
@@ -63,9 +63,7 @@ class AppListPageTest {
    fun canShowSystem() {
        val inputState by setContent()

        composeTestRule.onNodeWithContentDescription(
            context.getString(R.string.abc_action_menu_overflow_description)
        ).performClick()
        onMoreOptions().performClick()
        composeTestRule.onNodeWithText(context.getString(R.string.menu_show_system)).performClick()

        val state = inputState!!.state
@@ -75,20 +73,32 @@ class AppListPageTest {
    @Test
    fun afterShowSystem_displayHideSystem() {
        setContent()
        composeTestRule.onNodeWithContentDescription(
            context.getString(R.string.abc_action_menu_overflow_description)
        ).performClick()
        onMoreOptions().performClick()
        composeTestRule.onNodeWithText(context.getString(R.string.menu_show_system)).performClick()

        composeTestRule.onNodeWithContentDescription(
            context.getString(R.string.abc_action_menu_overflow_description)
        ).performClick()
        onMoreOptions().performClick()

        composeTestRule.onNodeWithText(context.getString(R.string.menu_hide_system))
            .assertIsDisplayed()
    }

    @Test
    fun noMoreOptions_notDisplayMoreOptions() {
        setContent(noMoreOptions = true)

        onMoreOptions().assertDoesNotExist()
    }

    @Test
    fun noMoreOptions_showSystemIsFalse() {
        val inputState by setContent(noMoreOptions = true)

        val state = inputState!!.state
        assertThat(state.showSystem.value).isFalse()
    }

    private fun setContent(
        noMoreOptions: Boolean = false,
        header: @Composable () -> Unit = {},
    ): State<AppListInput<TestAppRecord>?> {
        val appListState = mutableStateOf<AppListInput<TestAppRecord>?>(null)
@@ -96,6 +106,7 @@ class AppListPageTest {
            AppListPage(
                title = TITLE,
                listModel = TestAppListModel(),
                noMoreOptions = noMoreOptions,
                header = header,
                appList = { appListState.value = this },
            )
@@ -103,6 +114,11 @@ class AppListPageTest {
        return appListState
    }

    private fun onMoreOptions() =
        composeTestRule.onNodeWithContentDescription(
            context.getString(R.string.abc_action_menu_overflow_description)
        )

    private companion object {
        const val TITLE = "Title"
    }