Merge "Redesign individual conversation page" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-03-23 16:31:27 +00:00
committed by Android (Google) Code Review
14 changed files with 748 additions and 490 deletions

View File

@@ -122,7 +122,7 @@ public class BubblePreferenceControllerTest {
}
@Test
public void testIsAvailable_channel_notIfAppOff() {
public void testIsAvailable_channel_yesIfAppOff() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = false;
@@ -130,7 +130,7 @@ public class BubblePreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
assertTrue(mController.isAvailable());
}
@Test
@@ -199,18 +199,6 @@ public class BubblePreferenceControllerTest {
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_channelAppOff() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = false;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertFalse(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);

View File

@@ -1,206 +0,0 @@
/*
* Copyright (C) 2020 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.notification.app;
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class ConversationImportantPreferenceControllerTest {
private Context mContext;
@Mock
private NotificationBackend mBackend;
@Mock
private NotificationManager mNm;
@Mock
private UserManager mUm;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock
private NotificationSettings.DependentFieldListener mDependentFieldListener;
private ConversationImportantPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
mController = spy(new ConversationImportantPreferenceController(
mContext, mBackend, mDependentFieldListener));
}
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(Preference.class));
mController.onPreferenceChange(mock(Preference.class), true);
}
@Test
public void testIsAvailable_notChannelNull() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testUpdateState_disabledByAdmin() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something");
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
assertFalse(pref.isEnabled());
}
@Test
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setImportantConversation(true);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
assertTrue(pref.isChecked());
channel.setImportantConversation(false);
mController.onResume(appRow, channel, null, null, null, null);
mController.updateState(pref);
assertFalse(pref.isChecked());
}
@Test
public void testOnPreferenceChange_on() {
Settings.Secure.putInt(mContext.getContentResolver(),
BUBBLE_IMPORTANT_CONVERSATIONS, 0);
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
channel.setImportantConversation(false);
channel.setAllowBubbles(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
mController.onPreferenceChange(pref, true);
assertTrue(channel.isImportantConversation());
assertFalse(channel.canBubble());
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
}
@Test
public void testOnPreferenceChange_on_bubble() {
Settings.Secure.putInt(mContext.getContentResolver(),
BUBBLE_IMPORTANT_CONVERSATIONS, 1);
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
channel.setImportantConversation(false);
channel.setAllowBubbles(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
mController.updateState(pref);
mController.onPreferenceChange(pref, true);
assertTrue(channel.isImportantConversation());
assertTrue(channel.canBubble());
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
verify(mDependentFieldListener).onFieldValueChanged();
}
@Test
public void testOnPreferenceChange_off() {
Settings.Secure.putInt(mContext.getContentResolver(),
BUBBLE_IMPORTANT_CONVERSATIONS, 1);
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setImportantConversation(true);
channel.setAllowBubbles(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref =
new RestrictedSwitchPreference(RuntimeEnvironment.application);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, false);
assertFalse(channel.isImportantConversation());
assertFalse(channel.canBubble());
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* Copyright (C) 2020 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.
@@ -20,28 +20,32 @@ import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
import android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -54,21 +58,21 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class DefaultImportancePreferenceControllerTest {
public class ConversationPriorityPreferenceControllerTest {
private Context mContext;
@Mock
private NotificationManager mNm;
@Mock
private NotificationBackend mBackend;
@Mock
private NotificationSettings.DependentFieldListener mDependentFieldListener;
private NotificationManager mNm;
@Mock
private UserManager mUm;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock
private NotificationSettings.DependentFieldListener mDependentFieldListener;
private DefaultImportancePreferenceController mController;
private ConversationPriorityPreferenceController mController;
@Before
public void setUp() {
@@ -77,54 +81,28 @@ public class DefaultImportancePreferenceControllerTest {
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
mController = spy(new DefaultImportancePreferenceController(
mContext, mDependentFieldListener, mBackend));
mController = spy(new ConversationPriorityPreferenceController(
mContext, mBackend, mDependentFieldListener));
}
@Test
public void testNoCrashIfNoOnResume() {
mController.isAvailable();
mController.updateState(mock(Preference.class));
mController.onPreferenceChange(mock(Preference.class), true);
}
@Test
public void testIsAvailable_notIfNull() {
mController.onResume(null, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_ifAppBlocked() {
public void testIsAvailable_notChannelNull() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_notIfChannelBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_notForDefaultChannel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null, null, null);
mController.onResume(appRow, null, null, null, null, null);
assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
assertTrue(mController.isAvailable());
}
@@ -136,7 +114,7 @@ public class DefaultImportancePreferenceControllerTest {
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
Preference pref = new RestrictedSwitchPreference(mContext, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
assertFalse(pref.isEnabled());
@@ -150,7 +128,7 @@ public class DefaultImportancePreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
assertFalse(pref.isEnabled());
@@ -165,7 +143,7 @@ public class DefaultImportancePreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
@@ -180,67 +158,120 @@ public class DefaultImportancePreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
Preference pref = new ConversationPriorityPreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState_default() {
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
channel.setImportantConversation(true);
channel.setOriginalImportance(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
ConversationPriorityPreference pref = mock(ConversationPriorityPreference.class);
mController.updateState(pref);
assertTrue(pref.isChecked());
verify(pref, times(1)).setConfigurable(anyBoolean());
verify(pref, times(1)).setImportance(IMPORTANCE_HIGH);
verify(pref, times(1)).setOriginalImportance(IMPORTANCE_DEFAULT);
verify(pref, times(1)).setPriorityConversation(true);
}
@Test
public void testUpdateState_low() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
mController.updateState(pref);
assertFalse(pref.isChecked());
}
@Test
public void onPreferenceChange_onToOff() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, false);
assertEquals(IMPORTANCE_LOW, channel.getImportance());
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
}
@Test
public void onPreferenceChange_offToOn() {
public void testImportanceLowToImportant() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, true);
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_HIGH, true));
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
assertTrue(channel.canBubble());
assertTrue(channel.isImportantConversation());
}
@Test
public void testImportanceLowToDefault() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setAllowBubbles(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_HIGH, false));
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
assertFalse(channel.canBubble());
assertFalse(channel.isImportantConversation());
}
@Test
public void testImportanceDefaultToLow() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
channel.setAllowBubbles(false);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_LOW, false));
assertEquals(IMPORTANCE_LOW, channel.getImportance());
assertFalse(channel.canBubble());
assertFalse(channel.isImportantConversation());
}
@Test
public void testImportanceLowToDefault_bubblesMaintained() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
channel.setAllowBubbles(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_DEFAULT, false));
assertEquals(IMPORTANCE_DEFAULT, channel.getImportance());
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
assertTrue(channel.canBubble());
assertFalse(channel.isImportantConversation());
}
@Test
public void testImportancePriorityToDefault() {
NotificationChannel channel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
channel.setAllowBubbles(true);
channel.setImportantConversation(true);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
mController.displayPreference(mScreen);
mController.updateState(pref);
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_HIGH, false));
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
assertFalse(channel.canBubble());
assertFalse(channel.isImportantConversation());
}
}

View File

@@ -0,0 +1,172 @@
/*
* Copyright (C) 2020 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.notification.app;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class ConversationPriorityPreferenceTest {
private Context mContext;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
}
@Test
public void createNewPreference_shouldSetLayout() {
final ConversationPriorityPreference preference =
new ConversationPriorityPreference(mContext);
assertThat(preference.getLayoutResource()).isEqualTo(
R.layout.notif_priority_conversation_preference);
}
@Test
public void onBindViewHolder_nonConfigurable() {
final ConversationPriorityPreference preference =
new ConversationPriorityPreference(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
Drawable unselected = mock(Drawable.class);
Drawable selected = mock(Drawable.class);
preference.selectedBackground = selected;
preference.unselectedBackground = unselected;
preference.setConfigurable(false);
preference.setImportance(IMPORTANCE_DEFAULT);
preference.setPriorityConversation(true);
preference.onBindViewHolder(holder);
assertThat(holder.itemView.findViewById(R.id.silence).isEnabled()).isFalse();
assertThat(holder.itemView.findViewById(R.id.priority_group).isEnabled()).isFalse();
assertThat(holder.itemView.findViewById(R.id.alert).isEnabled()).isFalse();
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(selected);
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
.isEqualTo(unselected);
// other button
preference.setPriorityConversation(false);
holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
preference.onBindViewHolder(holder);
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(selected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
.isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(unselected);
// other other button
preference.setImportance(IMPORTANCE_LOW);
holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
preference.onBindViewHolder(holder);
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground()).isEqualTo(selected);
}
@Test
public void onBindViewHolder_selectButtonAndText() {
final ConversationPriorityPreference preference =
new ConversationPriorityPreference(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
Drawable unselected = mock(Drawable.class);
Drawable selected = mock(Drawable.class);
preference.selectedBackground = selected;
preference.unselectedBackground = unselected;
preference.setConfigurable(true);
preference.setImportance(IMPORTANCE_LOW);
preference.setPriorityConversation(true);
preference.onBindViewHolder(holder);
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
.isEqualTo(selected);
assertThat(holder.itemView.findViewById(R.id.silence_summary).getVisibility())
.isEqualTo(View.VISIBLE);
}
@Test
public void onClick_changesUICallsListener() {
final ConversationPriorityPreference preference =
spy(new ConversationPriorityPreference(mContext));
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
inflater.inflate(preference.getLayoutResource(), null));
Drawable unselected = mock(Drawable.class);
Drawable selected = mock(Drawable.class);
preference.selectedBackground = selected;
preference.unselectedBackground = unselected;
preference.setConfigurable(true);
preference.setImportance(IMPORTANCE_DEFAULT);
preference.setPriorityConversation(true);
preference.setOriginalImportance(IMPORTANCE_DEFAULT);
preference.onBindViewHolder(holder);
View silenceButton = holder.itemView.findViewById(R.id.silence);
silenceButton.callOnClick();
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
.isEqualTo(unselected);
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
.isEqualTo(selected);
verify(preference, times(1)).callChangeListener(new Pair(IMPORTANCE_LOW, false));
}
}