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

Commit d3913657 authored by AI test gen's avatar AI test gen Committed by Ying Liu
Browse files

Add test for setTitleMaxLines in SelectorWithWidgetPreference

Adds a unit test to verify the behavior of the `setTitleMaxLines` method.

The test ensures that calling `setTitleMaxLines` updates the underlying value and that the change is reflected in the title TextView's `maxLines` property after the view is rebound.

Please help fill out the survey for feedback: https://forms.gle/Qz9q5boo4h4tESyd7


Original Change: ag/35118513
Bug: 431235865
Flag: TEST_ONLY

Test: The generated test has been validated via ABTD - http://go/forrest-run/L80600030016790095

Change-Id: I8dc1d659c0a9a4025ce66a1827c21bfd15ede4f7
parent 7e30dbcc
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -154,6 +154,29 @@ public class SelectorWithWidgetPreferenceTest {
        assertThat(title.getMaxLines()).isEqualTo(titleMaxLines);
    }

    @Test
    public void setTitleMaxLines_updatesTitleViewMaxLines() {
        final int newMaxLines = 5;
        View view = LayoutInflater.from(mContext)
                .inflate(mPreference.getLayoutResource(), null /* root */);
        PreferenceViewHolder preferenceViewHolder =
                PreferenceViewHolder.createInstanceForTests(view);
        TextView title = (TextView) preferenceViewHolder.findViewById(android.R.id.title);

        // Bind to set the initial state and verify it's the default.
        mPreference.onBindViewHolder(preferenceViewHolder);
        assertThat(title.getMaxLines()).isEqualTo(SelectorWithWidgetPreference.DEFAULT_MAX_LINES);

        // Set a new max lines value programmatically.
        mPreference.setTitleMaxLines(newMaxLines);

        // Re-bind the view holder to apply the change.
        mPreference.onBindViewHolder(preferenceViewHolder);

        // Assert that the TextView's max lines property is updated.
        assertThat(title.getMaxLines()).isEqualTo(newMaxLines);
    }

    @Test
    public void onBindViewHolder_appliesWidgetContentDescription() {
        mPreference = new SelectorWithWidgetPreference(mContext);