1 /* 2 * Copyright (C) 2023 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.location.domain 18 19 import android.graphics.drawable.TestStubDrawable 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import androidx.test.filters.SmallTest 22 import com.android.systemui.SysuiTestCase 23 import com.android.systemui.common.shared.model.Icon 24 import com.android.systemui.kosmos.Kosmos 25 import com.android.systemui.qs.tiles.impl.location.domain.model.LocationTileModel 26 import com.android.systemui.qs.tiles.impl.location.qsLocationTileConfig 27 import com.android.systemui.qs.tiles.viewmodel.QSTileState 28 import com.android.systemui.res.R 29 import com.google.common.truth.Truth 30 import junit.framework.Assert 31 import org.junit.Test 32 import org.junit.runner.RunWith 33 34 @SmallTest 35 @RunWith(AndroidJUnit4::class) 36 class LocationTileMapperTest : SysuiTestCase() { 37 private val kosmos = Kosmos() 38 private val qsTileConfig = kosmos.qsLocationTileConfig 39 <lambda>null40 private val mapper by lazy { 41 LocationTileMapper( 42 context.orCreateTestableResources 43 .apply { 44 addOverride(R.drawable.qs_location_icon_off, TestStubDrawable()) 45 addOverride(R.drawable.qs_location_icon_on, TestStubDrawable()) 46 } 47 .resources, 48 context.theme, 49 ) 50 } 51 52 @Test mapsDisabledDataToInactiveStatenull53 fun mapsDisabledDataToInactiveState() { 54 val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(false)) 55 56 val actualActivationState = tileState.activationState 57 Assert.assertEquals(QSTileState.ActivationState.INACTIVE, actualActivationState) 58 } 59 60 @Test mapsEnabledDataToActiveStatenull61 fun mapsEnabledDataToActiveState() { 62 val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(true)) 63 64 val actualActivationState = tileState.activationState 65 Assert.assertEquals(QSTileState.ActivationState.ACTIVE, actualActivationState) 66 } 67 68 @Test mapsEnabledDataToOnIconStatenull69 fun mapsEnabledDataToOnIconState() { 70 val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(true)) 71 72 val expectedIcon = Icon.Loaded(context.getDrawable(R.drawable.qs_location_icon_on)!!, null) 73 val actualIcon = tileState.icon 74 Truth.assertThat(actualIcon).isEqualTo(expectedIcon) 75 } 76 77 @Test mapsDisabledDataToOffIconStatenull78 fun mapsDisabledDataToOffIconState() { 79 val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(false)) 80 81 val expectedIcon = Icon.Loaded(context.getDrawable(R.drawable.qs_location_icon_off)!!, null) 82 val actualIcon = tileState.icon 83 Truth.assertThat(actualIcon).isEqualTo(expectedIcon) 84 } 85 86 @Test supportsClickAndLongClickActionsnull87 fun supportsClickAndLongClickActions() { 88 val dontCare = true 89 90 val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(dontCare)) 91 92 val supportedActions = tileState.supportedActions 93 Truth.assertThat(supportedActions) 94 .containsExactly(QSTileState.UserAction.CLICK, QSTileState.UserAction.LONG_CLICK) 95 } 96 } 97