Merge "[2/n] Add aspect ratio app list page under apps" into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4e86d0d6b3
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.spa.app.appcompat
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN
|
||||
import android.content.pm.PackageManager.USER_MIN_ASPECT_RATIO_UNSET
|
||||
import android.os.Build
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
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.template.app.AppListItemModel
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* To run this test: atest SettingsSpaUnitTests:UserAspectRatioAppsPageProviderTest
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class UserAspectRatioAppsPageProviderTest {
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
private val fakeNavControllerWrapper = FakeNavControllerWrapper()
|
||||
|
||||
@Test
|
||||
fun aspectRatioAppsPageProvider_name() {
|
||||
assertThat(UserAspectRatioAppsPageProvider.name).isEqualTo(EXPECTED_PROVIDER_NAME)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun injectEntry_title() {
|
||||
setInjectEntry()
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.screen_size_title))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun injectEntry_summary() {
|
||||
setInjectEntry()
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.screen_size_summary, Build.MODEL))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun injectEntry_onClick_navigate() {
|
||||
setInjectEntry()
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.screen_size_title)).performClick()
|
||||
assertThat(fakeNavControllerWrapper.navigateCalledWith).isEqualTo("UserAspectRatioAppsPage")
|
||||
}
|
||||
|
||||
private fun setInjectEntry() {
|
||||
composeTestRule.setContent {
|
||||
fakeNavControllerWrapper.Wrapper {
|
||||
UserAspectRatioAppsPageProvider.buildInjectEntry().build().UiLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun title_displayed() {
|
||||
composeTestRule.setContent {
|
||||
UserAspectRatioAppList {}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.screen_size_title))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun item_labelDisplayed() {
|
||||
setItemContent()
|
||||
|
||||
composeTestRule.onNodeWithText(LABEL).assertIsDisplayed()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun aspectRatioAppListModel_transform() = runTest {
|
||||
val listModel = UserAspectRatioAppListModel(context)
|
||||
val recordListFlow = listModel.transform(flowOf(USER_ID), flowOf(listOf(APP)))
|
||||
val recordList = recordListFlow.firstWithTimeoutOrNull()!!
|
||||
|
||||
assertThat(recordList).hasSize(1)
|
||||
assertThat(recordList[0].app).isSameInstanceAs(APP)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun aspectRatioAppListModel_filter() = runTest {
|
||||
val listModel = UserAspectRatioAppListModel(context)
|
||||
|
||||
val recordListFlow = listModel.filter(flowOf(USER_ID), 0,
|
||||
flowOf(listOf(APP_RECORD_NOT_DISPLAYED, APP_RECORD_SUGGESTED)))
|
||||
|
||||
val recordList = checkNotNull(recordListFlow.firstWithTimeoutOrNull())
|
||||
assertThat(recordList).containsExactly(APP_RECORD_SUGGESTED)
|
||||
}
|
||||
|
||||
private fun setItemContent() {
|
||||
composeTestRule.setContent {
|
||||
fakeNavControllerWrapper.Wrapper {
|
||||
with(UserAspectRatioAppListModel(context)) {
|
||||
AppListItemModel(
|
||||
record = APP_RECORD_SUGGESTED,
|
||||
label = LABEL,
|
||||
summary = stateOf(SUMMARY)
|
||||
).AppItem()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aspectRatioAppListModel_getSummaryDefault() {
|
||||
val summaryState = setSummaryState(USER_MIN_ASPECT_RATIO_UNSET)
|
||||
assertThat(summaryState.value)
|
||||
.isEqualTo(context.getString(R.string.user_aspect_ratio_app_default))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aspectRatioAppListModel_getSummaryWhenSplitScreen() {
|
||||
val summaryState = setSummaryState(USER_MIN_ASPECT_RATIO_SPLIT_SCREEN)
|
||||
assertThat(summaryState.value)
|
||||
.isEqualTo(context.getString(R.string.user_aspect_ratio_half_screen))
|
||||
}
|
||||
|
||||
private fun setSummaryState(override: Int): State<String> {
|
||||
val listModel = UserAspectRatioAppListModel(context)
|
||||
lateinit var summaryState: State<String>
|
||||
composeTestRule.setContent {
|
||||
summaryState = listModel.getSummary(option = 0,
|
||||
record = UserAspectRatioAppListItemModel(
|
||||
app = APP,
|
||||
override = override,
|
||||
suggested = false,
|
||||
canDisplay = true,
|
||||
))
|
||||
}
|
||||
return summaryState
|
||||
}
|
||||
|
||||
|
||||
private companion object {
|
||||
private const val EXPECTED_PROVIDER_NAME = "UserAspectRatioAppsPage"
|
||||
private const val PACKAGE_NAME = "package.name"
|
||||
private const val USER_ID = 0
|
||||
private const val LABEL = "Label"
|
||||
private const val SUMMARY = "Summary"
|
||||
|
||||
private val APP = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
}
|
||||
private val APP_RECORD_SUGGESTED = UserAspectRatioAppListItemModel(
|
||||
APP,
|
||||
override = USER_MIN_ASPECT_RATIO_UNSET,
|
||||
suggested = true,
|
||||
canDisplay = true
|
||||
)
|
||||
private val APP_RECORD_NOT_DISPLAYED = UserAspectRatioAppListItemModel(
|
||||
APP,
|
||||
override = USER_MIN_ASPECT_RATIO_UNSET,
|
||||
suggested = true,
|
||||
canDisplay = false
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user