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.accessibility 18 19 import android.content.Context 20 import androidx.preference.SwitchPreferenceCompat 21 import androidx.test.core.app.ApplicationProvider 22 import androidx.test.ext.junit.runners.AndroidJUnit4 23 import com.android.settings.accessibility.RemoveAnimationsPreference.Companion.ANIMATION_ON_VALUE 24 import com.android.settingslib.datastore.SettingsGlobalStore 25 import com.android.settingslib.preference.createAndBindWidget 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 RemoveAnimationsPreferenceTest { 32 33 private val appContext: Context = ApplicationProvider.getApplicationContext() 34 getRemoveAnimationsSwitchPreferencenull35 private fun getRemoveAnimationsSwitchPreference(): SwitchPreferenceCompat = 36 RemoveAnimationsPreference().createAndBindWidget(appContext) 37 38 @Test 39 fun animationOff_switchPreferenceIsChecked() { 40 RemoveAnimationsPreference.setAnimationEnabled(appContext, false) 41 42 assertThat(getRemoveAnimationsSwitchPreference().isChecked).isTrue() 43 } 44 45 @Test animationOn_switchPreferenceIsNotCheckednull46 fun animationOn_switchPreferenceIsNotChecked() { 47 RemoveAnimationsPreference.setAnimationEnabled(appContext, true) 48 49 assertThat(getRemoveAnimationsSwitchPreference().isChecked).isFalse() 50 } 51 52 @Test oneAnimationValueOn_switchPreferenceIsNotCheckednull53 fun oneAnimationValueOn_switchPreferenceIsNotChecked() { 54 // Animation is disabled, except for one value. 55 RemoveAnimationsPreference.setAnimationEnabled(appContext, false) 56 SettingsGlobalStore.get(appContext) 57 .setFloat(RemoveAnimationsPreference.getAnimationKeys()[0], ANIMATION_ON_VALUE) 58 59 assertThat(getRemoveAnimationsSwitchPreference().isChecked).isFalse() 60 } 61 62 @Test toggleOnSwitch_turnsOffAnimationnull63 fun toggleOnSwitch_turnsOffAnimation() { 64 RemoveAnimationsPreference.setAnimationEnabled(appContext, true) 65 66 val switchPreference = getRemoveAnimationsSwitchPreference() 67 assertThat(switchPreference.isChecked).isFalse() 68 switchPreference.performClick() 69 assertThat(switchPreference.isChecked).isTrue() 70 71 assertThat(RemoveAnimationsPreference.isAnimationEnabled(appContext)).isFalse() 72 } 73 74 @Test toggleOffSwitch_turnsOnAnimationnull75 fun toggleOffSwitch_turnsOnAnimation() { 76 RemoveAnimationsPreference.setAnimationEnabled(appContext, false) 77 78 val switchPreference = getRemoveAnimationsSwitchPreference() 79 assertThat(switchPreference.isChecked).isTrue() 80 switchPreference.performClick() 81 assertThat(switchPreference.isChecked).isFalse() 82 83 assertThat(RemoveAnimationsPreference.isAnimationEnabled(appContext)).isTrue() 84 } 85 } 86