Merge "Provides TC ID for accessibility framework feature for "about" and "learn more" part" into sc-v2-dev am: 7f907d35cd
am: e8cba63525
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15175506 Change-Id: I4466b80721a6fe0356d120cef790dad6f6c86358
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
* Tests for {@link AccessibilityFooterPreferenceController}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityFooterPreferenceControllerTest {
|
||||
|
||||
private static final String TEST_KEY = "test_pref_key";
|
||||
private static final String TEST_TITLE = "test_title";
|
||||
private static final String TEST_INTRODUCTION_TITLE = "test_introduction_title";
|
||||
private static final String TEST_CONTENT_DESCRIPTION = "test_content_description";
|
||||
private static final int TEST_HELP_ID = 12345;
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
private AccessibilityFooterPreferenceController mController;
|
||||
private AccessibilityFooterPreference mPreference;
|
||||
private PreferenceViewHolder mPreferenceViewHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new AccessibilityFooterPreferenceController(mContext, TEST_KEY);
|
||||
mPreference = new AccessibilityFooterPreference(mContext);
|
||||
mPreference.setKey(TEST_KEY);
|
||||
mPreference.setTitle(TEST_TITLE);
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final View view = inflater.inflate(R.layout.preference_footer, null);
|
||||
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setIntroductionTitle_setCorrectIntroductionTitle() {
|
||||
mController.setIntroductionTitle(TEST_INTRODUCTION_TITLE);
|
||||
|
||||
assertThat(mController.getIntroductionTitle()).isEqualTo(TEST_INTRODUCTION_TITLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setIntroductionTitle_setCorrectIntroductionTitle() {
|
||||
mController.setIntroductionTitle(TEST_INTRODUCTION_TITLE);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
final TextView summaryView = (TextView) mPreferenceViewHolder
|
||||
.findViewById(android.R.id.title);
|
||||
assertThat(summaryView.getContentDescription().toString())
|
||||
.contains(TEST_INTRODUCTION_TITLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupHelpLink_setCorrectHelpLinkAndContentDescription() {
|
||||
mController.setupHelpLink(TEST_HELP_ID, TEST_CONTENT_DESCRIPTION);
|
||||
|
||||
assertThat(mController.getHelpResource()).isEqualTo(TEST_HELP_ID);
|
||||
assertThat(mController.getLearnMoreContentDescription())
|
||||
.isEqualTo(TEST_CONTENT_DESCRIPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setupHelpLink_setCorrectHelpLinkAndContentDescription() {
|
||||
mController.setupHelpLink(TEST_HELP_ID, TEST_CONTENT_DESCRIPTION);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
final TextView learnMoreView = (TextView) mPreferenceViewHolder
|
||||
.findViewById(com.android.settingslib.R.id.settingslib_learn_more);
|
||||
assertThat(learnMoreView.getContentDescription().toString())
|
||||
.contains(TEST_CONTENT_DESCRIPTION);
|
||||
assertThat(mPreference.isLinkEnabled()).isTrue();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user