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.settings.widget;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.widget.CompoundButton;
23 import android.widget.TextView;
24 
25 import androidx.test.core.app.ApplicationProvider;
26 
27 import com.android.settingslib.RestrictedLockUtils;
28 import com.android.settingslib.widget.mainswitch.R;
29 
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.RobolectricTestRunner;
33 
34 @RunWith(RobolectricTestRunner.class)
35 public class SettingsMainSwitchBarTest {
36 
37     private final Context mContext = ApplicationProvider.getApplicationContext();
38     private final SettingsMainSwitchBar mMainSwitchBar = new SettingsMainSwitchBar(mContext);
39 
40     private final TextView mTitle = mMainSwitchBar.findViewById(R.id.switch_text);
41 
42     private final CompoundButton mSwitchWidget =
43             mMainSwitchBar.findViewById(android.R.id.switch_widget);
44 
45     @Test
disabledByAdmin_shouldBeDisabled()46     public void disabledByAdmin_shouldBeDisabled() {
47         mMainSwitchBar.setDisabledByAdmin(new RestrictedLockUtils.EnforcedAdmin());
48 
49         assertThat(mTitle.isEnabled()).isFalse();
50         assertThat(mSwitchWidget.isEnabled()).isFalse();
51     }
52 
53     @Test
disabledByAdmin_setNull_shouldBeEnabled()54     public void disabledByAdmin_setNull_shouldBeEnabled() {
55         mMainSwitchBar.setDisabledByAdmin(null);
56 
57         assertThat(mTitle.isEnabled()).isTrue();
58         assertThat(mSwitchWidget.isEnabled()).isTrue();
59     }
60 }
61