1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.messaging.ui.conversation; 18 19 import android.test.suitebuilder.annotation.SmallTest; 20 import android.text.TextUtils; 21 22 import com.android.messaging.BugleTestCase; 23 import com.android.messaging.ui.contact.ContactPickerFragment; 24 import com.android.messaging.ui.conversation.ConversationActivityUiState; 25 import com.android.messaging.ui.conversation.ConversationActivityUiState.ConversationActivityUiStateHost; 26 27 import org.mockito.Mock; 28 import org.mockito.Mockito; 29 30 @SmallTest 31 public class ConversationActivityUiStateTest extends BugleTestCase { 32 @Mock protected ConversationActivityUiStateHost mockListener; 33 34 /** 35 * Test the Ui state where we start off with the contact picker to pick the first contact. 36 */ 37 public void testPickInitialContact() { 38 final ConversationActivityUiState uiState = new ConversationActivityUiState(null); 39 uiState.setHost(mockListener); 40 assertTrue(uiState.shouldShowContactPickerFragment()); 41 assertFalse(uiState.shouldShowConversationFragment()); 42 assertEquals(ContactPickerFragment.MODE_PICK_INITIAL_CONTACT, 43 uiState.getDesiredContactPickingMode()); 44 uiState.onGetOrCreateConversation("conversation1"); 45 Mockito.verify(mockListener, Mockito.times(1)).onConversationContactPickerUiStateChanged( 46 Mockito.eq(ConversationActivityUiState.STATE_CONTACT_PICKER_ONLY_INITIAL_CONTACT), 47 Mockito.eq( 48 ConversationActivityUiState.STATE_HYBRID_WITH_CONVERSATION_AND_CHIPS_VIEW), 49 Mockito.anyBoolean()); 50 assertTrue(uiState.shouldShowContactPickerFragment()); 51 assertTrue(uiState.shouldShowConversationFragment()); 52 assertTrue(TextUtils.equals("conversation1", uiState.getConversationId())); 53 assertEquals(ContactPickerFragment.MODE_CHIPS_ONLY, 54 uiState.getDesiredContactPickingMode()); 55 } 56 57 /** 58 * Test the Ui state where we have both the chips view and the conversation view and we 59 * start message compose. 60 */ 61 public void testHybridUiStateStartCompose() { 62 final ConversationActivityUiState uiState = new ConversationActivityUiState("conv1"); 63 uiState.testSetUiState( 64 ConversationActivityUiState.STATE_HYBRID_WITH_CONVERSATION_AND_CHIPS_VIEW); 65 uiState.setHost(mockListener); 66 67 // Start message compose. 68 uiState.onStartMessageCompose(); 69 Mockito.verify(mockListener, Mockito.times(1)).onConversationContactPickerUiStateChanged( 70 Mockito.eq( 71 ConversationActivityUiState.STATE_HYBRID_WITH_CONVERSATION_AND_CHIPS_VIEW), 72 Mockito.eq(ConversationActivityUiState.STATE_CONVERSATION_ONLY), 73 Mockito.anyBoolean()); 74 assertFalse(uiState.shouldShowContactPickerFragment()); 75 assertTrue(uiState.shouldShowConversationFragment()); 76 } 77 78 /** 79 * Test the Ui state where we have both the chips view and the conversation view and we 80 * try to add a participant. 81 */ 82 public void testHybridUiStateAddParticipant() { 83 final ConversationActivityUiState uiState = new ConversationActivityUiState("conv1"); 84 uiState.testSetUiState( 85 ConversationActivityUiState.STATE_HYBRID_WITH_CONVERSATION_AND_CHIPS_VIEW); 86 uiState.setHost(mockListener); 87 88 uiState.onAddMoreParticipants(); 89 Mockito.verify(mockListener, Mockito.times(1)).onConversationContactPickerUiStateChanged( 90 Mockito.eq( 91 ConversationActivityUiState.STATE_HYBRID_WITH_CONVERSATION_AND_CHIPS_VIEW), 92 Mockito.eq( 93 ConversationActivityUiState.STATE_CONTACT_PICKER_ONLY_ADD_MORE_CONTACTS), 94 Mockito.anyBoolean()); 95 assertTrue(uiState.shouldShowContactPickerFragment()); 96 assertFalse(uiState.shouldShowConversationFragment()); 97 assertEquals(ContactPickerFragment.MODE_PICK_MORE_CONTACTS, 98 uiState.getDesiredContactPickingMode()); 99 } 100 101 /** 102 * Test the Ui state where we are trying to add more participants and commit. 103 */ 104 public void testCommitAddParticipant() { 105 final ConversationActivityUiState uiState = new ConversationActivityUiState(null); 106 uiState.testSetUiState( 107 ConversationActivityUiState.STATE_CONTACT_PICKER_ONLY_ADD_MORE_CONTACTS); 108 uiState.setHost(mockListener); 109 110 uiState.onGetOrCreateConversation("conversation1"); 111 112 // After adding more contacts, the terminal state is always conversation only (i.e. we 113 // don't go back to hybrid mode). 114 Mockito.verify(mockListener, Mockito.times(1)).onConversationContactPickerUiStateChanged( 115 Mockito.eq(ConversationActivityUiState.STATE_CONTACT_PICKER_ONLY_ADD_MORE_CONTACTS), 116 Mockito.eq(ConversationActivityUiState.STATE_CONVERSATION_ONLY), 117 Mockito.anyBoolean()); 118 assertFalse(uiState.shouldShowContactPickerFragment()); 119 assertTrue(uiState.shouldShowConversationFragment()); 120 } 121 } 122