From 37073bff8f166dccfd8106cf0a8940d12ba24d03 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Thu, 1 Jun 2023 17:14:24 +0800 Subject: [PATCH] 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 --- .../spaprivileged/template/app/AppListPage.kt | 11 ++++-- .../template/app/AppListPageTest.kt | 34 ++++++++++++++----- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListPage.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListPage.kt index 89bfa0eb646b9..030b70a75a8b3 100644 --- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListPage.kt +++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListPage.kt @@ -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 AppListPage( title: String, listModel: AppListModel, showInstantApps: Boolean = false, + noMoreOptions: Boolean = false, matchAnyUserForAdmin: Boolean = false, primaryUserOnly: Boolean = false, noItemMessage: String? = null, @@ -49,9 +52,11 @@ fun AppListPage( SearchScaffold( title = title, actions = { - MoreOptionsAction { - ShowSystemAction(showSystem.value) { showSystem.value = it } - moreOptions() + if (!noMoreOptions) { + MoreOptionsAction { + ShowSystemAction(showSystem.value) { showSystem.value = it } + moreOptions() + } } }, ) { bottomPadding, searchQuery -> diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListPageTest.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListPageTest.kt index 06003c0cb8f9d..f6f48891030a6 100644 --- a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListPageTest.kt +++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListPageTest.kt @@ -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?> { val appListState = mutableStateOf?>(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" }