Goal: Improve readability which is a bit difficult because of string concatenation for accurate translation. Root cause: In some locales, framework features name would be a word rather than a product name. Hence it need to be in the different position in a sentence. Solution: Use whole sentence to translate instead of concatenating the string could solve this issue. Bug: 185478543 Test: make RunSettingsRoboTests ROBOTEST_FILTER=AccessibilityFooterPreferenceControllerTest Change-Id: Id198805329be9c773df87f38a074ae956e4d0cdb
125 lines
4.6 KiB
Java
125 lines
4.6 KiB
Java
/*
|
|
* 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();
|
|
}
|
|
}
|