1 /* 2 * 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 17 package com.android.systemui.qs.tiles.impl.onehanded.ui 18 19 import android.graphics.drawable.TestStubDrawable 20 import android.widget.Switch 21 import androidx.test.ext.junit.runners.AndroidJUnit4 22 import androidx.test.filters.SmallTest 23 import com.android.systemui.SysuiTestCase 24 import com.android.systemui.common.shared.model.Icon 25 import com.android.systemui.kosmos.Kosmos 26 import com.android.systemui.qs.tileimpl.SubtitleArrayMapping 27 import com.android.systemui.qs.tiles.impl.custom.QSTileStateSubject 28 import com.android.systemui.qs.tiles.impl.onehanded.domain.model.OneHandedModeTileModel 29 import com.android.systemui.qs.tiles.impl.onehanded.qsOneHandedModeTileConfig 30 import com.android.systemui.qs.tiles.viewmodel.QSTileState 31 import com.android.systemui.res.R 32 import org.junit.Before 33 import org.junit.Test 34 import org.junit.runner.RunWith 35 36 @SmallTest 37 @RunWith(AndroidJUnit4::class) 38 class OneHandedModeTileMapperTest : SysuiTestCase() { 39 private val kosmos = Kosmos() 40 private val config = kosmos.qsOneHandedModeTileConfig 41 private val subtitleArrayId = SubtitleArrayMapping.getSubtitleId(config.tileSpec.spec) <lambda>null42 private val subtitleArray by lazy { context.resources.getStringArray(subtitleArrayId) } 43 44 private lateinit var mapper: OneHandedModeTileMapper 45 46 @Before setupnull47 fun setup() { 48 mapper = 49 OneHandedModeTileMapper( 50 context.orCreateTestableResources 51 .apply { 52 addOverride( 53 com.android.internal.R.drawable.ic_qs_one_handed_mode, 54 TestStubDrawable(), 55 ) 56 } 57 .resources, 58 context.theme, 59 ) 60 } 61 62 @Test disabledModelnull63 fun disabledModel() { 64 val inputModel = OneHandedModeTileModel(false) 65 66 val outputState = mapper.map(config, inputModel) 67 68 val expectedState = 69 createOneHandedModeTileState( 70 QSTileState.ActivationState.INACTIVE, 71 subtitleArray[1], 72 com.android.internal.R.drawable.ic_qs_one_handed_mode, 73 ) 74 QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState) 75 } 76 77 @Test enabledModelnull78 fun enabledModel() { 79 val inputModel = OneHandedModeTileModel(true) 80 81 val outputState = mapper.map(config, inputModel) 82 83 val expectedState = 84 createOneHandedModeTileState( 85 QSTileState.ActivationState.ACTIVE, 86 subtitleArray[2], 87 com.android.internal.R.drawable.ic_qs_one_handed_mode, 88 ) 89 QSTileStateSubject.assertThat(outputState).isEqualTo(expectedState) 90 } 91 createOneHandedModeTileStatenull92 private fun createOneHandedModeTileState( 93 activationState: QSTileState.ActivationState, 94 secondaryLabel: String, 95 iconRes: Int, 96 ): QSTileState { 97 val label = context.getString(R.string.quick_settings_onehanded_label) 98 return QSTileState( 99 Icon.Loaded(context.getDrawable(iconRes)!!, null), 100 iconRes, 101 label, 102 activationState, 103 secondaryLabel, 104 setOf(QSTileState.UserAction.CLICK, QSTileState.UserAction.LONG_CLICK), 105 label, 106 null, 107 QSTileState.SideViewIcon.None, 108 QSTileState.EnabledState.ENABLED, 109 Switch::class.qualifiedName, 110 ) 111 } 112 } 113