1 /*
2  * Copyright (C) 2022 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 
29 import com.android.settings.R;
30 import com.android.settingslib.widget.IllustrationPreference;
31 
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.robolectric.RobolectricTestRunner;
36 
37 @RunWith(RobolectricTestRunner.class)
38 public class LongPressPowerIllustrationPreferenceControllerTest {
39 
40     private Application mContext;
41     private IllustrationPreference mPreference;
42     private LongPressPowerIllustrationPreferenceController mController;
43 
44     @Before
setUp()45     public void setUp() {
46         mContext = ApplicationProvider.getApplicationContext();
47         mPreference = new IllustrationPreference(mContext);
48         mController = new LongPressPowerIllustrationPreferenceController(mContext, "test_key");
49 
50         PreferenceScreen mScreen = mock(PreferenceScreen.class);
51         when(mScreen.findPreference("test_key")).thenReturn(mPreference);
52         mController.displayPreference(mScreen);
53     }
54 
55     @Test
updateState_longPressPowerForPowerMenu_showsPowerMenuAnimation()56     public void updateState_longPressPowerForPowerMenu_showsPowerMenuAnimation() {
57         PowerMenuSettingsUtils.setLongPressPowerForPowerMenu(mContext);
58 
59         mController.updateState(mPreference);
60 
61         assertThat(mPreference.getLottieAnimationResId())
62                 .isEqualTo(R.raw.lottie_long_press_power_for_power_menu);
63     }
64 
65     @Test
updateState_longPressPowerForAssistant_showsAssistantAnimation()66     public void updateState_longPressPowerForAssistant_showsAssistantAnimation() {
67         PowerMenuSettingsUtils.setLongPressPowerForAssistant(mContext);
68 
69         mController.updateState(mPreference);
70 
71         assertThat(mPreference.getLottieAnimationResId())
72                 .isEqualTo(R.raw.lottie_long_press_power_for_assistant);
73     }
74 }
75