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.settings.gestures; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.mock; 22 import static org.mockito.Mockito.when; 23 24 import android.app.Application; 25 26 import androidx.preference.PreferenceScreen; 27 import androidx.test.core.app.ApplicationProvider; 28 import androidx.test.ext.junit.runners.AndroidJUnit4; 29 30 import com.android.settings.R; 31 import com.android.settingslib.widget.IllustrationPreference; 32 33 import org.junit.Before; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 37 @RunWith(AndroidJUnit4.class) 38 public class DoubleTapPowerIllustrationPreferenceControllerTest { 39 40 private static final String KEY = "gesture_double_tap_power_video"; 41 private Application mContext; 42 private IllustrationPreference mPreference; 43 private DoubleTapPowerIllustrationPreferenceController mController; 44 45 @Before setUp()46 public void setUp() { 47 mContext = ApplicationProvider.getApplicationContext(); 48 mPreference = new IllustrationPreference(mContext); 49 mController = new DoubleTapPowerIllustrationPreferenceController(mContext, KEY); 50 51 PreferenceScreen mScreen = mock(PreferenceScreen.class); 52 when(mScreen.findPreference(KEY)).thenReturn(mPreference); 53 mController.displayPreference(mScreen); 54 } 55 56 @Test updateState_setDoubleTapPowerForCamera_showsCameraIllustration()57 public void updateState_setDoubleTapPowerForCamera_showsCameraIllustration() { 58 DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext); 59 60 mController.updateState(mPreference); 61 62 assertThat(mPreference.getLottieAnimationResId()).isEqualTo(R.drawable.quickly_open_camera); 63 } 64 65 @Test updateState_setDoubleTapPowerForWallet_showsWalletIllustration()66 public void updateState_setDoubleTapPowerForWallet_showsWalletIllustration() { 67 DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext); 68 69 mController.updateState(mPreference); 70 71 assertThat(mPreference.getLottieAnimationResId()) 72 .isEqualTo(R.drawable.double_tap_power_for_wallet); 73 } 74 } 75