Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55a5ff14 authored by Kevin Liu's avatar Kevin Liu Committed by Ang Li
Browse files

[AI TestGen] Add tests for ActionButtonsPreference content description

- Add a test to confirm that `setButtonXDescription` correctly sets the content description for each button.
- Add a test to verify that if no content description is set, the button's text is used as a fallback.
- Update the `createMock()` helper method to include mocks for the `setButtonXDescription` methods.

**Caution:** This CL is AI generated based on change: 33749430.

Flag: TEST_ONLY
Change-Id: I3b85b47a1c971a8f07d09dbabdcad55fc27535f4
parent 8c4f5b3f
Loading
Loading
Loading
Loading
+40 −1
Original line number Diff line number Diff line
@@ -214,6 +214,41 @@ public class ActionButtonsPreferenceTest {
                .isEqualTo(mContext.getText(com.android.settingslib.R.string.install_other_apps));
    }

    @Test
    public void onBindViewHolder_setContentDescription_shouldShowSameContentDescription() {
        mPref.setButton1Text(com.android.settingslib.R.string.install_other_apps)
                .setButton1Description(android.R.string.copy);
        mPref.setButton2Text(com.android.settingslib.R.string.install_other_apps)
                .setButton2Description(android.R.string.cut);
        mPref.setButton3Text(com.android.settingslib.R.string.install_other_apps)
                .setButton3Description(android.R.string.paste);
        mPref.setButton4Text(com.android.settingslib.R.string.install_other_apps)
                .setButton4Description(android.R.string.cancel);

        mPref.onBindViewHolder(mHolder);

        assertThat(mRootView.findViewById(R.id.button1).getContentDescription().toString())
                .isEqualTo(mContext.getText(android.R.string.copy).toString());
        assertThat(mRootView.findViewById(R.id.button2).getContentDescription().toString())
                .isEqualTo(mContext.getText(android.R.string.cut).toString());
        assertThat(mRootView.findViewById(R.id.button3).getContentDescription().toString())
                .isEqualTo(mContext.getText(android.R.string.paste).toString());
        assertThat(mRootView.findViewById(R.id.button4).getContentDescription().toString())
                .isEqualTo(mContext.getText(android.R.string.cancel).toString());
    }

    @Test
    public void onBindViewHolder_noContentDescription_shouldUseButtonTextAsContentDescription() {
        mPref.setButton1Text(com.android.settingslib.R.string.install_other_apps);

        mPref.onBindViewHolder(mHolder);

        assertThat(mRootView.findViewById(R.id.button1).getContentDescription().toString())
                .isEqualTo(mContext.getText(
                        com.android.settingslib.R.string.install_other_apps
                ).toString());
    }

    @Test
    public void onBindViewHolder_setButtonIcon_iconMustDisplayAboveText() {
        mPref.setButton1Text(com.android.settingslib.R.string.install_other_apps);
@@ -368,24 +403,28 @@ public class ActionButtonsPreferenceTest {
        when(pref.setButton1Enabled(anyBoolean())).thenReturn(pref);
        when(pref.setButton1Visible(anyBoolean())).thenReturn(pref);
        when(pref.setButton1OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
        when(pref.setButton1Description(anyInt())).thenReturn(pref);

        when(pref.setButton2Text(anyInt())).thenReturn(pref);
        when(pref.setButton2Icon(anyInt())).thenReturn(pref);
        when(pref.setButton2Enabled(anyBoolean())).thenReturn(pref);
        when(pref.setButton2Visible(anyBoolean())).thenReturn(pref);
        when(pref.setButton2OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
        when(pref.setButton2Description(anyInt())).thenReturn(pref);

        when(pref.setButton3Text(anyInt())).thenReturn(pref);
        when(pref.setButton3Icon(anyInt())).thenReturn(pref);
        when(pref.setButton3Enabled(anyBoolean())).thenReturn(pref);
        when(pref.setButton3Visible(anyBoolean())).thenReturn(pref);
        when(pref.setButton3OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
        when(pref.setButton3Description(anyInt())).thenReturn(pref);

        when(pref.setButton4Text(anyInt())).thenReturn(pref);
        when(pref.setButton4Icon(anyInt())).thenReturn(pref);
        when(pref.setButton4Enabled(anyBoolean())).thenReturn(pref);
        when(pref.setButton4Visible(anyBoolean())).thenReturn(pref);
        when(pref.setButton4OnClickListener(any(View.OnClickListener.class))).thenReturn(pref);
        when(pref.setButton4Description(anyInt())).thenReturn(pref);
        return pref;
    }
}
 No newline at end of file