1 /* <lambda>null2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.settings.connecteddevice 17 18 import android.content.Intent 19 import android.provider.Settings.Global 20 import androidx.preference.PreferenceFragmentCompat 21 import androidx.test.core.app.ActivityScenario 22 import androidx.test.ext.junit.runners.AndroidJUnit4 23 import com.android.settings.Settings.BluetoothDashboardActivity 24 import com.android.settings.flags.Flags 25 import com.android.settingslib.preference.CatalystScreenTestCase 26 import com.google.common.truth.Truth.assertThat 27 import org.junit.Test 28 import org.junit.runner.RunWith 29 30 @RunWith(AndroidJUnit4::class) 31 class BluetoothDashboardScreenTest : CatalystScreenTestCase() { 32 override val preferenceScreenCreator = BluetoothDashboardScreen() 33 34 override val flagName: String 35 get() = Flags.FLAG_CATALYST_BLUETOOTH_SWITCHBAR_SCREEN 36 37 @Test 38 fun key() { 39 assertThat(preferenceScreenCreator.key).isEqualTo(BluetoothDashboardScreen.KEY) 40 } 41 42 override fun migration() {} 43 44 override fun launchFragment( 45 fragmentClass: Class<PreferenceFragmentCompat>, 46 action: (PreferenceFragmentCompat) -> Unit, 47 ) { 48 Global.putInt(appContext.contentResolver, Global.DEVICE_PROVISIONED, 1) 49 val intent = Intent(appContext, BluetoothDashboardActivity::class.java) 50 ActivityScenario.launch<BluetoothDashboardActivity>(intent).use { 51 it.onActivity { activity -> 52 val fragment = activity.supportFragmentManager.fragments[0] 53 assertThat(fragment.javaClass).isEqualTo(fragmentClass) 54 action(fragment as PreferenceFragmentCompat) 55 } 56 } 57 } 58 } 59