Add device details more settings page
BUG: 343317785 Test: atest DeviceDetailsFragmentFormatterTest Flag: com.android.settings.flags.enable_bluetooth_device_details_polish Change-Id: Ia9eff049e73e039ac5d0fb26096ab4e9add60315
This commit is contained in:
@@ -50,6 +50,7 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.ui.model.FragmentTypeModel;
|
||||
import com.android.settings.bluetooth.ui.view.DeviceDetailsFragmentFormatter;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -117,7 +118,9 @@ public class BluetoothDeviceDetailsFragmentTest {
|
||||
FakeFeatureFactory fakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
when(fakeFeatureFactory.mBluetoothFeatureProvider.getDeviceDetailsFragmentFormatter(any(),
|
||||
any(), any(), eq(mCachedDevice))).thenReturn(mFormatter);
|
||||
when(mFormatter.getVisiblePreferenceKeysForMainPage()).thenReturn(null);
|
||||
when(mFormatter.getVisiblePreferenceKeys(
|
||||
FragmentTypeModel.DeviceDetailsMainFragment.INSTANCE))
|
||||
.thenReturn(null);
|
||||
|
||||
mFragment = setupFragment();
|
||||
mFragment.onAttach(mContext);
|
||||
|
@@ -26,6 +26,7 @@ import androidx.preference.PreferenceManager
|
||||
import androidx.preference.PreferenceScreen
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.android.settings.bluetooth.domain.interactor.SpatialAudioInteractor
|
||||
import com.android.settings.bluetooth.ui.model.FragmentTypeModel
|
||||
import com.android.settings.dashboard.DashboardFragment
|
||||
import com.android.settings.testutils.FakeFeatureFactory
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice
|
||||
@@ -45,7 +46,6 @@ import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.ArgumentMatchers.eq
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.any
|
||||
@@ -111,10 +111,9 @@ class DeviceDetailsFragmentFormatterTest {
|
||||
DeviceSettingConfigItemModel.BuiltinItem(
|
||||
DeviceSettingId.DEVICE_SETTING_ID_ACTION_BUTTONS, "action_buttons"),
|
||||
),
|
||||
listOf(),
|
||||
"footer"))
|
||||
listOf()))
|
||||
|
||||
val keys = underTest.getVisiblePreferenceKeysForMainPage()
|
||||
val keys = underTest.getVisiblePreferenceKeys(FragmentTypeModel.DeviceDetailsMainFragment)
|
||||
|
||||
assertThat(keys).containsExactly("bluetooth_device_header", "action_buttons")
|
||||
}
|
||||
@@ -125,7 +124,7 @@ class DeviceDetailsFragmentFormatterTest {
|
||||
testScope.runTest {
|
||||
`when`(repository.getDeviceSettingsConfig(cachedDevice)).thenReturn(null)
|
||||
|
||||
val keys = underTest.getVisiblePreferenceKeysForMainPage()
|
||||
val keys = underTest.getVisiblePreferenceKeys(FragmentTypeModel.DeviceDetailsMainFragment)
|
||||
|
||||
assertThat(keys).isNull()
|
||||
}
|
||||
@@ -136,9 +135,9 @@ class DeviceDetailsFragmentFormatterTest {
|
||||
testScope.runTest {
|
||||
`when`(repository.getDeviceSettingsConfig(cachedDevice)).thenReturn(null)
|
||||
|
||||
underTest.updateLayout()
|
||||
underTest.updateLayout(FragmentTypeModel.DeviceDetailsMainFragment)
|
||||
|
||||
assertThat(getDisplayedPreferences().map { it.key })
|
||||
assertThat(getDisplayedPreferences().mapNotNull { it.key })
|
||||
.containsExactly("bluetooth_device_header", "action_buttons", "keyboard_settings")
|
||||
}
|
||||
}
|
||||
@@ -157,12 +156,11 @@ class DeviceDetailsFragmentFormatterTest {
|
||||
DeviceSettingId.DEVICE_SETTING_ID_KEYBOARD_SETTINGS,
|
||||
"keyboard_settings"),
|
||||
),
|
||||
listOf(),
|
||||
"footer"))
|
||||
listOf()))
|
||||
|
||||
underTest.updateLayout()
|
||||
underTest.updateLayout(FragmentTypeModel.DeviceDetailsMainFragment)
|
||||
|
||||
assertThat(getDisplayedPreferences().map { it.key })
|
||||
assertThat(getDisplayedPreferences().mapNotNull { it.key })
|
||||
.containsExactly("bluetooth_device_header", "keyboard_settings")
|
||||
}
|
||||
}
|
||||
@@ -183,8 +181,7 @@ class DeviceDetailsFragmentFormatterTest {
|
||||
DeviceSettingId.DEVICE_SETTING_ID_KEYBOARD_SETTINGS,
|
||||
"keyboard_settings"),
|
||||
),
|
||||
listOf(),
|
||||
"footer"))
|
||||
listOf()))
|
||||
`when`(repository.getDeviceSetting(cachedDevice, DeviceSettingId.DEVICE_SETTING_ID_ANC))
|
||||
.thenReturn(
|
||||
flowOf(
|
||||
@@ -209,9 +206,9 @@ class DeviceDetailsFragmentFormatterTest {
|
||||
isAllowedChangingState = true,
|
||||
updateState = {})))
|
||||
|
||||
underTest.updateLayout()
|
||||
underTest.updateLayout(FragmentTypeModel.DeviceDetailsMainFragment)
|
||||
|
||||
assertThat(getDisplayedPreferences().map { it.key })
|
||||
assertThat(getDisplayedPreferences().mapNotNull { it.key })
|
||||
.containsExactly(
|
||||
"bluetooth_device_header",
|
||||
"DEVICE_SETTING_${DeviceSettingId.DEVICE_SETTING_ID_ANC}",
|
||||
|
@@ -16,12 +16,14 @@
|
||||
|
||||
package com.android.settings.bluetooth.ui.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.android.settings.bluetooth.domain.interactor.SpatialAudioInteractor
|
||||
import com.android.settings.bluetooth.ui.layout.DeviceSettingLayout
|
||||
import com.android.settings.bluetooth.ui.model.DeviceSettingPreferenceModel
|
||||
import com.android.settings.bluetooth.ui.model.FragmentTypeModel
|
||||
import com.android.settings.testutils.FakeFeatureFactory
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice
|
||||
import com.android.settingslib.bluetooth.devicesettings.DeviceSettingId
|
||||
@@ -44,8 +46,6 @@ import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.ArgumentMatchers.eq
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.Mockito.verify
|
||||
@@ -73,26 +73,23 @@ class BluetoothDeviceDetailsViewModelTest {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
val application = ApplicationProvider.getApplicationContext<Application>()
|
||||
featureFactory = FakeFeatureFactory.setupForTest()
|
||||
`when`(
|
||||
featureFactory.bluetoothFeatureProvider.getDeviceSettingRepository(
|
||||
eq(context), eq(bluetoothAdapter), any()))
|
||||
.thenReturn(repository)
|
||||
|
||||
underTest =
|
||||
BluetoothDeviceDetailsViewModel(repository, spatialAudioInteractor, cachedDevice)
|
||||
BluetoothDeviceDetailsViewModel(
|
||||
application, repository, spatialAudioInteractor, cachedDevice)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getItems_returnConfigMainItems() {
|
||||
fun getItems_returnConfigMainMainItems() {
|
||||
testScope.runTest {
|
||||
`when`(repository.getDeviceSettingsConfig(cachedDevice))
|
||||
.thenReturn(
|
||||
DeviceSettingConfigModel(
|
||||
listOf(BUILTIN_SETTING_ITEM_1, BUILDIN_SETTING_ITEM_2), listOf(), "footer"))
|
||||
listOf(BUILTIN_SETTING_ITEM_1, BUILDIN_SETTING_ITEM_2), listOf()))
|
||||
|
||||
val keys = underTest.getItems()
|
||||
val keys = underTest.getItems(FragmentTypeModel.DeviceDetailsMainFragment)
|
||||
|
||||
assertThat(keys).containsExactly(BUILTIN_SETTING_ITEM_1, BUILDIN_SETTING_ITEM_2)
|
||||
}
|
||||
@@ -110,19 +107,18 @@ class BluetoothDeviceDetailsViewModelTest {
|
||||
BUILTIN_SETTING_ITEM_1,
|
||||
buildRemoteSettingItem(remoteSettingId1),
|
||||
),
|
||||
listOf(),
|
||||
"footer"))
|
||||
listOf()))
|
||||
`when`(repository.getDeviceSetting(cachedDevice, remoteSettingId1))
|
||||
.thenReturn(flowOf(pref))
|
||||
|
||||
var deviceSetting: DeviceSettingModel? = null
|
||||
var deviceSettingPreference: DeviceSettingPreferenceModel? = null
|
||||
underTest
|
||||
.getDeviceSetting(cachedDevice, remoteSettingId1)
|
||||
.onEach { deviceSetting = it }
|
||||
.onEach { deviceSettingPreference = it }
|
||||
.launchIn(testScope.backgroundScope)
|
||||
runCurrent()
|
||||
|
||||
assertThat(deviceSetting).isSameInstanceAs(pref)
|
||||
assertThat(deviceSettingPreference?.id).isEqualTo(pref.id)
|
||||
verify(repository, times(1)).getDeviceSetting(cachedDevice, remoteSettingId1)
|
||||
}
|
||||
}
|
||||
@@ -141,19 +137,18 @@ class BluetoothDeviceDetailsViewModelTest {
|
||||
buildRemoteSettingItem(
|
||||
DeviceSettingId.DEVICE_SETTING_ID_SPATIAL_AUDIO_MULTI_TOGGLE),
|
||||
),
|
||||
listOf(),
|
||||
"footer"))
|
||||
listOf()))
|
||||
`when`(spatialAudioInteractor.getDeviceSetting(cachedDevice)).thenReturn(flowOf(pref))
|
||||
|
||||
var deviceSetting: DeviceSettingModel? = null
|
||||
var deviceSettingPreference: DeviceSettingPreferenceModel? = null
|
||||
underTest
|
||||
.getDeviceSetting(
|
||||
cachedDevice, DeviceSettingId.DEVICE_SETTING_ID_SPATIAL_AUDIO_MULTI_TOGGLE)
|
||||
.onEach { deviceSetting = it }
|
||||
.onEach { deviceSettingPreference = it }
|
||||
.launchIn(testScope.backgroundScope)
|
||||
runCurrent()
|
||||
|
||||
assertThat(deviceSetting).isSameInstanceAs(pref)
|
||||
assertThat(deviceSettingPreference?.id).isEqualTo(pref.id)
|
||||
verify(spatialAudioInteractor, times(1)).getDeviceSetting(cachedDevice)
|
||||
}
|
||||
}
|
||||
@@ -164,9 +159,9 @@ class BluetoothDeviceDetailsViewModelTest {
|
||||
`when`(repository.getDeviceSettingsConfig(cachedDevice))
|
||||
.thenReturn(
|
||||
DeviceSettingConfigModel(
|
||||
listOf(BUILTIN_SETTING_ITEM_1, BUILDIN_SETTING_ITEM_2), listOf(), "footer"))
|
||||
listOf(BUILTIN_SETTING_ITEM_1, BUILDIN_SETTING_ITEM_2), listOf()))
|
||||
|
||||
val layout = underTest.getLayout()!!
|
||||
val layout = underTest.getLayout(FragmentTypeModel.DeviceDetailsMainFragment)!!
|
||||
|
||||
assertThat(getLatestLayout(layout))
|
||||
.isEqualTo(
|
||||
@@ -191,8 +186,7 @@ class BluetoothDeviceDetailsViewModelTest {
|
||||
buildRemoteSettingItem(remoteSettingId2),
|
||||
buildRemoteSettingItem(remoteSettingId3),
|
||||
),
|
||||
listOf(),
|
||||
"footer"))
|
||||
listOf()))
|
||||
`when`(repository.getDeviceSetting(cachedDevice, remoteSettingId1))
|
||||
.thenReturn(flowOf(buildMultiTogglePreference(remoteSettingId1)))
|
||||
`when`(repository.getDeviceSetting(cachedDevice, remoteSettingId2))
|
||||
@@ -200,7 +194,7 @@ class BluetoothDeviceDetailsViewModelTest {
|
||||
`when`(repository.getDeviceSetting(cachedDevice, remoteSettingId3))
|
||||
.thenReturn(flowOf(buildActionSwitchPreference(remoteSettingId3)))
|
||||
|
||||
val layout = underTest.getLayout()!!
|
||||
val layout = underTest.getLayout(FragmentTypeModel.DeviceDetailsMainFragment)!!
|
||||
|
||||
assertThat(getLatestLayout(layout))
|
||||
.isEqualTo(
|
||||
|
Reference in New Issue
Block a user