Update texts for Settings->Sound->Do not disturb

- Update title to "Do not disturb preferences"
- Add summary text to reflect the priority only allows preferences
- Refactor the summary handling in ZenModeSettings so that the
  controller can get the summary text

Fix: 34975939
Test: make RunSettingsRoboTests

Change-Id: I3ca1dc43fe1d943735a9f625e66c89708a18300a
This commit is contained in:
Doris Ling
2017-02-15 12:04:57 -08:00
parent ec6cd665b1
commit 4d8a9bd879
5 changed files with 125 additions and 55 deletions

View File

@@ -16,7 +16,10 @@
package com.android.settings.notification;
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.content.Context;
import android.support.v7.preference.Preference;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -27,8 +30,13 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -36,6 +44,12 @@ public class ZenModePreferenceControllerTest {
@Mock
private Context mContext;
@Mock
private Preference mPreference;
@Mock
private NotificationManager mNotificationManager;
@Mock
private Policy mPolicy;
private ZenModePreferenceController mController;
@@ -43,6 +57,9 @@ public class ZenModePreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new ZenModePreferenceController(mContext);
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
.thenReturn(mNotificationManager);
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
}
@Test
@@ -50,4 +67,22 @@ public class ZenModePreferenceControllerTest {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void updateState_preferenceEnabled_shouldSetSummary() {
when(mPreference.isEnabled()).thenReturn(true);
mController.updateState(mPreference);
verify(mPreference).setSummary(anyString());
}
@Test
public void updateState_preferenceDisabled_shouldNotSetSummary() {
when(mPreference.isEnabled()).thenReturn(false);
mController.updateState(mPreference);
verify(mPreference, never()).setSummary(anyString());
}
}