diff --git a/app/build.gradle b/app/build.gradle index a674cb70..1c4f0af1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -66,11 +66,15 @@ dependencies { androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + // required if you want to use Mockito for unit tests + testImplementation 'org.mockito:mockito-core:3.7.7' + // required if you want to use Mockito for Android tests + androidTestImplementation 'org.mockito:mockito-android:3.7.7' implementation project(path: ':uikit') implementation 'com.google.android.material:material:1.2.0-alpha05' implementation 'com.facebook.shimmer:shimmer:0.4.0' // - implementation 'com.cometchat:pro-android-chat-sdk:2.2.1' + implementation 'com.cometchat:pro-android-chat-sdk:2.3.0' } diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/AppTestSuite.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/AppTestSuite.java index 0a03faa2..f1f0e531 100644 --- a/app/src/androidTest/java/com/cometchat/pro/androiduikit/AppTestSuite.java +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/AppTestSuite.java @@ -11,7 +11,6 @@ @Suite.SuiteClasses( { MainActivityTest.class, - CreateUserActivity.class, SelectActivityTest.class, ComponentActivityTest.class }) diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/UIKitTestSuite.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/UIKitTestSuite.java new file mode 100644 index 00000000..04d12303 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/UIKitTestSuite.java @@ -0,0 +1,23 @@ +package com.cometchat.pro.androiduikit; + +import com.cometchat.pro.androiduikit.app.ComponentActivityTest; +import com.cometchat.pro.androiduikit.app.MainActivityTest; +import com.cometchat.pro.androiduikit.app.SelectActivityTest; +import com.cometchat.pro.androiduikit.uikit.CometChatUITest; +import com.cometchat.pro.androiduikit.uikit.ConversationListTest; +import com.cometchat.pro.androiduikit.uikit.GroupListTest; +import com.cometchat.pro.androiduikit.uikit.UsersListTest; +import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CometChatUITest.class, + ConversationListTest.class, + UsersListTest.class, + GroupListTest.class + }) + +public class UIKitTestSuite {} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/ComponentActivityTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/ComponentActivityTest.java index a630eadd..d1f728a3 100644 --- a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/ComponentActivityTest.java +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/ComponentActivityTest.java @@ -153,6 +153,7 @@ public void J_checkCallList() { public void K_checkCallList_2Sec() { try { Espresso.onView(ViewMatchers.withId(R.id.cometchat_callList)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_callList)).check(matches(isDisplayed())); Espresso.onView(ViewMatchers.withId(R.id.cometchat_callList)).perform(click()); Thread.sleep(2000); Espresso.onView(ViewMatchers.withId(R.id.callList_rv)) @@ -168,16 +169,22 @@ public void D_checkUserList() { Espresso.onView(ViewMatchers.withId(R.id.cometchat_user_view)).perform(click()); try { Espresso.onView(ViewMatchers.withId(R.id.cometchatUserList)) - .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); - } catch (PerformException e) { + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())) + .perform(pressBack()); + mDevice.pressBack();; + } + catch (NoMatchingViewException e) { + Log.e( "D_checkUserList: ","No View found...Trying again with 2 Sec Delay"); + D_checkUserList_2Sec(); + } + catch (PerformException e) { Assert.assertTrue("View not loaded",true); } catch (Exception e) { - Assert.fail(); + Assert.fail(e.getMessage()); } } - @Test - public void E_checkUserList_2Sec() { + public void D_checkUserList_2Sec() { try { Espresso.onView(ViewMatchers.withId(R.id.cometchat_user_view)).perform(ViewActions.scrollTo()); Espresso.onView(ViewMatchers.withId(R.id.cometchat_user_view)).perform(ViewActions.click()); @@ -205,11 +212,45 @@ public void G_checkGroupList_2Sec() { Thread.sleep(2000); Espresso.onView(ViewMatchers.withId(R.id.cometchatGroupList)) .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); - } catch (InterruptedException e) { + } catch (NoMatchingViewException e) { + Log.e( "F_checkGroupList_2Sec: ","View Not loaded...Moving to 5 sec" ); + F_checkGroupList_5Sec(); + }catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void F_checkGroupList_5Sec() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_group_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_group_view)).perform(ViewActions.click()); + Thread.sleep(5000); + Espresso.onView(ViewMatchers.withId(R.id.cometchatGroupList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (NoMatchingViewException e) { + Log.e( "F_checkGroupList_2Sec: ","View Not loaded...Moving to 10 sec" ); + F_checkGroupList_10Sec(); + }catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void F_checkGroupList_10Sec() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_group_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_group_view)).perform(ViewActions.click()); + Thread.sleep(10000); + Espresso.onView(ViewMatchers.withId(R.id.cometchatGroupList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (NoMatchingViewException e) { + Assert.fail("View Not Loaded"+e.getMessage()); + }catch (InterruptedException e) { e.printStackTrace(); } } + + @Test public void H_checkConversationList() { Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.scrollTo()); @@ -217,26 +258,61 @@ public void H_checkConversationList() { try { Espresso.onView(ViewMatchers.withId(R.id.cometchatConversationList)) .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); - } catch (PerformException e) { + } + catch (NoMatchingViewException e) { + Log.e( "H_checkConversationList: ","No View found...Trying again with 2 Sec Delay"); + H_checkConversationList_2Sec(); + } + catch (PerformException e) { Assert.assertTrue("View not loaded",true); } catch (Exception e) { - Assert.fail(); + Assert.fail(e.getMessage()); } } - @Test - public void I_checkConversationList_2Sec() { + public void H_checkConversationList_2Sec() { try { Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.scrollTo()); Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.click()); Thread.sleep(2000); Espresso.onView(ViewMatchers.withId(R.id.cometchatConversationList)) .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); - } catch (InterruptedException e) { + } catch (NoMatchingViewException e) { + Log.e("H_checkConversationList_2Sec: ","View Not loaded..Moving to 5 Sec"); + H_checkConversationList_5Sec(); + }catch (InterruptedException e) { e.printStackTrace(); } } + public void H_checkConversationList_5Sec() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.click()); + Thread.sleep(5000); + Espresso.onView(ViewMatchers.withId(R.id.cometchatConversationList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (NoMatchingViewException e) { + Log.e("H_checkConversationList_5Sec: ","View Not loaded..Moving to 10 Sec"); + H_checkConversationList_10Sec(); + }catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void H_checkConversationList_10Sec() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.click()); + Thread.sleep(10000); + Espresso.onView(ViewMatchers.withId(R.id.cometchatConversationList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (NoMatchingViewException e) { + Assert.fail("View Not Loaded"+e.getMessage()); + }catch (InterruptedException e) { + e.printStackTrace(); + } + } // RecyclerView callRv = activityRule.getActivity().findViewById(R.id.cometchat_callList); // int itemCount = callRv.getAdapter().getItemCount(); // if (itemCount>0) { diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/CreateUserActivityTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/CreateUserActivityTest.java deleted file mode 100644 index 4b3bd4fb..00000000 --- a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/CreateUserActivityTest.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.cometchat.pro.androiduikit.app; - - -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -import androidx.test.espresso.Espresso; -import androidx.test.espresso.NoMatchingViewException; -import androidx.test.espresso.action.ViewActions; -import androidx.test.espresso.assertion.ViewAssertions; -import androidx.test.espresso.matcher.ViewMatchers; -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.rule.ActivityTestRule; -import androidx.test.uiautomator.By; -import androidx.test.uiautomator.UiDevice; -import androidx.test.uiautomator.Until; - -import com.cometchat.pro.androiduikit.ComponentListActivity; -import com.cometchat.pro.androiduikit.CreateUserActivity; -import com.cometchat.pro.androiduikit.R; -import com.cometchat.pro.core.CometChat; -import com.cometchat.pro.exceptions.CometChatException; -import com.cometchat.pro.uikit.ui_resources.utils.Utils; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -import java.util.Random; - -import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; - -public class CreateUserActivityTest { - - private static final String BASIC_SAMPLE_PACKAGE - = "com.cometchat.pro.androiduikit"; - - private static final int LAUNCH_TIMEOUT = 5000; - - private static String UID = "superhero1"; - - private static String NAME = "IronMan"; - - private UiDevice mDevice; - - @Rule - public ActivityTestRule activityRule = new ActivityTestRule<>(CreateUserActivity.class, true, false); - - @Before - public void setup() { - mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); - Context context = getInstrumentation().getContext(); - Intent intent = context.getPackageManager() - .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); - - // Clear out any previous instances - context.startActivity(intent); - mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); - if (CometChat.getLoggedInUser()!=null) { - CometChat.logout(new CometChat.CallbackListener() { - @Override - public void onSuccess(String s) { - Log.e("onSuccess: ",s ); - } - - @Override - public void onError(CometChatException e) { - Log.e( "onError: ",e.getMessage()); - } - }); - } - } - - @Test - public void A_createUserWithExistingUID() { - try { - Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); - Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); - Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText(UID)); - Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText(NAME)); - Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); - Thread.sleep(5000); - Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).perform(ViewActions.click()); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void B_createUserWithRandomUID() { - try { - Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); - Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); - Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText(Utils.generateRandomString(25))); - Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText("TestCase User")); - Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); - Thread.sleep(5000); - Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).perform(ViewActions.click()); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void C_createUserWithEmptyName() { - try { - Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); - Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); - Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText(Utils.generateRandomString(25))); - Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText("")); - Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); - Thread.sleep(5000); - try { - Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).check(ViewAssertions.matches(ViewMatchers.isDisplayed())); - Assert.fail("Failed: Able to create user without authentication"); - } catch (AssertionError e) { - Assert.assertTrue(true); - } catch (NoMatchingViewException e) { - Assert.assertTrue(true); - } - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/MainActivityTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/MainActivityTest.java index cd1dd84a..4eb99afc 100644 --- a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/MainActivityTest.java +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/MainActivityTest.java @@ -20,6 +20,7 @@ import androidx.test.espresso.UiController; import androidx.test.espresso.ViewAction; import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.assertion.ViewAssertions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.ComponentNameMatchers; import androidx.test.espresso.intent.matcher.IntentMatchers; @@ -38,6 +39,7 @@ import com.cometchat.pro.androiduikit.UIKitApplication; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.uikit.ui_resources.utils.Utils; import junit.framework.AssertionFailedError; @@ -149,13 +151,13 @@ public void A_sameActivity3Sec() { Thread.sleep(3000); } catch (Exception e) { Assert.fail("login_sameActivity:Failed in 3 Sec- "+e.getMessage()); + B_sameActivity7Sec(); } } else { Log.e( "login_sameActivity: ","User already logged IN" ); } } - @Test public void B_sameActivity7Sec() { if (CometChat.getLoggedInUser()==null) { ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); @@ -168,13 +170,13 @@ public void B_sameActivity7Sec() { Thread.sleep(3000); } catch (Exception e) { Assert.fail("login_sameActivity:Failed in 7 Sec - "+e.getMessage()); + C_sameActivity15Sec(); } } else { Log.e( "login_sameActivity: ","User already logged IN" ); } } - @Test public void C_sameActivity15Sec() { if (CometChat.getLoggedInUser()==null) { ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); @@ -228,6 +230,59 @@ public void E_failLoginActivity() { } } + + @Test + public void F_createUserWithExistingUID() { + try { + Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText("superhero1")); + Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText("IronMan")); + Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); + Thread.sleep(5000); + Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).perform(ViewActions.click()); + } catch (Exception e) { + Log.e( "A_createUserWithExistingUID: ",e.getMessage()); + e.printStackTrace(); + } + } + + @Test + public void G_createUserWithEmptyName() { + try { + Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText(Utils.generateRandomString(25))); + Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText("")); + Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); + Thread.sleep(5000); + try { + Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).check(ViewAssertions.matches(ViewMatchers.isDisplayed())); + Assert.fail("Failed: Able to create user without authentication"); + } catch (AssertionError e) { + Assert.assertTrue(true); + } catch (NoMatchingViewException e) { + Assert.assertTrue(true); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void H_createUserWithRandomUID() { + try { + Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText(Utils.generateRandomString(25))); + Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText("TestCase User")); + Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); + Thread.sleep(5000); + Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).perform(ViewActions.click()); + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * Uses package manager to find the package name of the device launcher. Usually this package * is "com.android.launcher" but can be different at times. This is a generic solution which diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/SelectActivityTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/SelectActivityTest.java index 42fe7d78..f3249de5 100644 --- a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/SelectActivityTest.java +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/SelectActivityTest.java @@ -18,6 +18,7 @@ import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.core.CometChat; import org.junit.Before; import org.junit.FixMethodOrder; diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/CometChatUITest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/CometChatUITest.java new file mode 100644 index 00000000..d690f856 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/CometChatUITest.java @@ -0,0 +1,257 @@ +package com.cometchat.pro.androiduikit.uikit; + +import android.content.Context; +import android.content.Intent; +import android.view.MenuItem; + +import androidx.fragment.app.Fragment; +import androidx.test.espresso.Espresso; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.espresso.PerformException; +import androidx.test.espresso.ViewAction; +import androidx.test.espresso.ViewInteraction; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.NavigationViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import com.cometchat.pro.androiduikit.MainActivity; +import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.androiduikit.utils.RecyclerViewAssertion; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.uikit.databinding.ActivityCometchatUnifiedBinding; +import com.cometchat.pro.uikit.ui_components.calls.call_list.CometChatCallList; +import com.cometchat.pro.uikit.ui_components.chats.CometChatConversationList; +import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI; +import com.cometchat.pro.uikit.ui_components.groups.group_list.CometChatGroupList; +import com.cometchat.pro.uikit.ui_components.userprofile.CometChatUserProfile; +import com.cometchat.pro.uikit.ui_components.users.user_list.CometChatUserList; +import com.google.android.material.bottomnavigation.BottomNavigationView; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withParent; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import static com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity.activity; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class CometChatUITest { + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private static final String STRING_TO_BE_TYPED = "superhero5"; + + private UiDevice mDevice; + + private BottomNavigationView bottomNavigation; + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(CometChatUI.class, true, false); + + + @Before + public void setup() { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + if (CometChat.getLoggedInUser()==null) { + // Type text and then press the button. + Espresso.onView(withId(R.id.superhero1)).perform(ViewActions.click()); + } + Espresso.onView(withId(R.id.directLaunch)).perform(click()); + bottomNavigation = CometChatUI.getBinding().bottomNavigation; + } + + @Test + public void A_checkConversations() { + try { + Thread.sleep(3000); + BottomNavigationView.OnNavigationItemSelectedListener mockedListener = + mock(BottomNavigationView.OnNavigationItemSelectedListener.class); + bottomNavigation.setOnNavigationItemSelectedListener(mockedListener); + + // Make the listener return true to allow selecting the item. + when(mockedListener.onNavigationItemSelected(any(MenuItem.class))).thenReturn(true); + Espresso.onView( + Matchers.allOf( + ViewMatchers.withId(R.id.menu_conversation), + isDescendantOfA(withId(R.id.bottom_navigation)), + isDisplayed())) + .perform(click()); + // Verify our listener has been notified of the click + verify(mockedListener, times(1)) + .onNavigationItemSelected(bottomNavigation.getMenu().findItem(R.id.menu_conversation)); + // Verify the item is now selected + assertTrue(bottomNavigation.getMenu().findItem(R.id.menu_conversation).isChecked()); + Fragment conversationList = new CometChatConversationList(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),conversationList).commit(); + }catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void B_checkCalls() { + try { + Thread.sleep(3000); + BottomNavigationView.OnNavigationItemSelectedListener mockedListener = + mock(BottomNavigationView.OnNavigationItemSelectedListener.class); + bottomNavigation.setOnNavigationItemSelectedListener(mockedListener); + + // Make the listener return true to allow selecting the item. + when(mockedListener.onNavigationItemSelected(any(MenuItem.class))).thenReturn(true); + Espresso.onView( + Matchers.allOf( + ViewMatchers.withId(R.id.menu_call), + isDescendantOfA(withId(R.id.bottom_navigation)), + isDisplayed())) + .perform(click()); + // Verify our listener has been notified of the click + verify(mockedListener, times(1)) + .onNavigationItemSelected(bottomNavigation.getMenu().findItem(R.id.menu_call)); + // Verify the item is now selected + assertTrue(bottomNavigation.getMenu().findItem(R.id.menu_call).isChecked()); + Fragment callList = new CometChatCallList(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),callList).commit(); + Thread.sleep(2500); + + }catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void C_checkUsers() { + try { + Thread.sleep(3000); + BottomNavigationView.OnNavigationItemSelectedListener mockedListener = + mock(BottomNavigationView.OnNavigationItemSelectedListener.class); + bottomNavigation.setOnNavigationItemSelectedListener(mockedListener); + + // Make the listener return true to allow selecting the item. + when(mockedListener.onNavigationItemSelected(any(MenuItem.class))).thenReturn(true); + Espresso.onView( + Matchers.allOf( + ViewMatchers.withId(R.id.menu_users), + isDescendantOfA(withId(R.id.bottom_navigation)), + isDisplayed())) + .perform(click()); + // Verify our listener has been notified of the click + verify(mockedListener, times(1)) + .onNavigationItemSelected(bottomNavigation.getMenu().findItem(R.id.menu_users)); + // Verify the item is now selected + assertTrue(bottomNavigation.getMenu().findItem(R.id.menu_users).isChecked()); + + Fragment usersList = new CometChatUserList(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),usersList).commit(); + Thread.sleep(2500); + + }catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void D_checkGroups() { + try { + Thread.sleep(5000); + BottomNavigationView.OnNavigationItemSelectedListener mockedListener = + mock(BottomNavigationView.OnNavigationItemSelectedListener.class); + bottomNavigation.setOnNavigationItemSelectedListener(mockedListener); + + // Make the listener return true to allow selecting the item. + when(mockedListener.onNavigationItemSelected(any(MenuItem.class))).thenReturn(true); + Espresso.onView( + Matchers.allOf( + ViewMatchers.withId(R.id.menu_group), + isDescendantOfA(withId(R.id.bottom_navigation)), + isDisplayed())) + .perform(click()); + // Verify our listener has been notified of the click + verify(mockedListener, times(1)) + .onNavigationItemSelected(bottomNavigation.getMenu().findItem(R.id.menu_group)); + // Verify the item is now selected + assertTrue(bottomNavigation.getMenu().findItem(R.id.menu_group).isChecked()); + + Fragment groupList = new CometChatGroupList(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),groupList).commit(); + Thread.sleep(2500); + + }catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void E_checkUserProfile() { + try { + Thread.sleep(5000); + BottomNavigationView.OnNavigationItemSelectedListener mockedListener = + mock(BottomNavigationView.OnNavigationItemSelectedListener.class); + bottomNavigation.setOnNavigationItemSelectedListener(mockedListener); + + // Make the listener return true to allow selecting the item. + when(mockedListener.onNavigationItemSelected(any(MenuItem.class))).thenReturn(true); + Espresso.onView( + Matchers.allOf( + ViewMatchers.withId(R.id.menu_more), + isDescendantOfA(withId(R.id.bottom_navigation)), + isDisplayed())) + .perform(click()); + // Verify our listener has been notified of the click + verify(mockedListener, times(1)) + .onNavigationItemSelected(bottomNavigation.getMenu().findItem(R.id.menu_more)); + // Verify the item is now selected + assertTrue(bottomNavigation.getMenu().findItem(R.id.menu_more).isChecked()); + + Fragment profileScreen = new CometChatUserProfile(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),profileScreen).commit(); + Thread.sleep(2500); + + }catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + + +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/ConversationListTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/ConversationListTest.java new file mode 100644 index 00000000..6cd4d792 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/ConversationListTest.java @@ -0,0 +1,117 @@ +package com.cometchat.pro.androiduikit.uikit; + +import android.content.Context; +import android.content.Intent; +import android.view.View; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; +import androidx.test.espresso.Espresso; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.uikit.ui_components.chats.CometChatConversationList; +import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI; +import com.google.android.material.bottomnavigation.BottomNavigationView; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ConversationListTest { + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private static final String STRING_TO_BE_TYPED = "superhero5"; + + private UiDevice mDevice; + + private BottomNavigationView bottomNavigation; + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(CometChatUI.class, true, false); + + private View view; + + @Before + public void setup() { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + if (CometChat.getLoggedInUser()==null) { + // Type text and then press the button. + Espresso.onView(withId(R.id.superhero1)).perform(ViewActions.click()); + } + Espresso.onView(withId(R.id.directLaunch)).perform(click()); + bottomNavigation = CometChatUI.getBinding().bottomNavigation; + Fragment conversationList = new CometChatConversationList(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),conversationList).commit(); + try { + Thread.sleep(3000); + view = conversationList.getView(); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void A_checkConversationListNotEmpty() { + RecyclerView conversationList = (RecyclerView)view.findViewById(R.id.rv_conversation_list); + RecyclerView.Adapter adapter = conversationList.getAdapter(); + if (adapter.getItemCount()>0) { + Espresso.onView(Matchers.allOf( + withId(R.id.rv_conversation_list), + isDescendantOfA(withId(view.getId())), + isDisplayed())) + .perform(RecyclerViewActions.actionOnItemAtPosition(0,click())); + Assert.assertTrue("Not Empty",true); + } else { + Assert.fail("ConversationList is Empty"); + } + } + + @Test + public void B_checkConversationListLastItem() { + RecyclerView conversationList = (RecyclerView)view.findViewById(R.id.rv_conversation_list); + RecyclerView.Adapter adapter = conversationList.getAdapter(); + if (adapter.getItemCount()>0) { + Espresso.onView(Matchers.allOf( + withId(R.id.rv_conversation_list), + isDescendantOfA(withId(view.getId())), + isDisplayed())) + .perform(RecyclerViewActions.scrollToPosition(adapter.getItemCount()-1)) + .perform(RecyclerViewActions.actionOnItemAtPosition(adapter.getItemCount()-1,click())); + } else { + Assert.fail("ConversationList is Empty"); + } + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/GroupListTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/GroupListTest.java new file mode 100644 index 00000000..93bf5bec --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/GroupListTest.java @@ -0,0 +1,117 @@ +package com.cometchat.pro.androiduikit.uikit; + +import android.content.Context; +import android.content.Intent; +import android.view.View; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; +import androidx.test.espresso.Espresso; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.uikit.ui_components.chats.CometChatConversationList; +import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI; +import com.cometchat.pro.uikit.ui_components.groups.group_list.CometChatGroupList; +import com.google.android.material.bottomnavigation.BottomNavigationView; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class GroupListTest { + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private static final String STRING_TO_BE_TYPED = "superhero5"; + + private UiDevice mDevice; + + private BottomNavigationView bottomNavigation; + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(CometChatUI.class, true, false); + + private View view; + + @Before + public void setup() { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + if (CometChat.getLoggedInUser()==null) { + // Type text and then press the button. + Espresso.onView(withId(R.id.superhero1)).perform(ViewActions.click()); + } + Espresso.onView(withId(R.id.directLaunch)).perform(click()); + bottomNavigation = CometChatUI.getBinding().bottomNavigation; + Fragment groupList = new CometChatGroupList(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),groupList).commit(); + try { + Thread.sleep(3000); + view = groupList.getView(); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void A_checkGroupListNotEmpty() { + RecyclerView groupList = (RecyclerView)view.findViewById(R.id.rv_group_list); + RecyclerView.Adapter adapter = groupList.getAdapter(); + if (adapter.getItemCount()>0) { + Espresso.onView(Matchers.allOf( + withId(R.id.rv_group_list), + isDescendantOfA(withId(view.getId())), + isDisplayed())) + .perform(RecyclerViewActions.actionOnItemAtPosition(0,click())); + Assert.assertTrue("Not Empty",true); + } else { + Assert.fail("ConversationList is Empty"); + } + } + + @Test + public void A_checkGroupListLastItem() { + RecyclerView groupList = (RecyclerView)view.findViewById(R.id.rv_group_list); + RecyclerView.Adapter adapter = groupList.getAdapter(); + if (adapter.getItemCount()>0) { + Espresso.onView(Matchers.allOf( + withId(R.id.rv_group_list), + isDescendantOfA(withId(view.getId())), + isDisplayed())) + .perform(RecyclerViewActions.scrollToPosition(adapter.getItemCount()-1)) + .perform(RecyclerViewActions.actionOnItemAtPosition(adapter.getItemCount()-1,click())); + } else { + Assert.fail("ConversationList is Empty"); + } + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/MessageListTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/MessageListTest.java new file mode 100644 index 00000000..5833d477 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/MessageListTest.java @@ -0,0 +1,238 @@ +package com.cometchat.pro.androiduikit.uikit; + +import android.app.Activity; +import android.app.Instrumentation; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Bundle; +import android.provider.MediaStore; +import android.util.Log; +import android.view.View; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; +import androidx.test.espresso.Espresso; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.intent.Intents; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.runner.intent.IntentCallback; +import androidx.test.runner.intent.IntentMonitorRegistry; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.uikit.ui_components.chats.CometChatConversationList; +import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI; +import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageList; +import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; +import com.google.android.material.bottomnavigation.BottomNavigationView; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import java.io.IOException; +import java.io.OutputStream; + +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.longClick; +import static androidx.test.espresso.intent.Intents.intending; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; +import static androidx.test.espresso.intent.matcher.IntentMatchers.isInternal; +import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.not; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class MessageListTest { + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private static final String STRING_TO_BE_TYPED = "superhero5"; + + private UiDevice mDevice; + + private BottomNavigationView bottomNavigation; + + @Rule + public ActivityTestRule activityTestRule = new ActivityTestRule<>(CometChatMessageListActivity.class,true,false); + + private View view; + + @Before + public void setup() { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + if (CometChat.getLoggedInUser()==null) { + // Type text and then press the button. + Espresso.onView(withId(R.id.superhero1)).perform(ViewActions.click()); + } + Espresso.onView(withId(R.id.directLaunch)).perform(click()); + bottomNavigation = CometChatUI.getBinding().bottomNavigation; + Fragment conversationList = new CometChatConversationList(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),conversationList).commit(); + try { + Thread.sleep(2000); + view = conversationList.getView(); + Espresso.onView(allOf( + withId(R.id.rv_conversation_list), + isDescendantOfA(withId(view.getId())), + isDisplayed())) + .perform(RecyclerViewActions.actionOnItemAtPosition(0,click())); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void A_sendTextMessage() { + Espresso.onView(Matchers.allOf( + withId(R.id.etComposeBox), + isDisplayed())).perform(ViewActions.typeText("Hi,Test Message")); + Espresso.onView(Matchers.allOf( + withId(R.id.ivSend), + isDisplayed())).perform(ViewActions.click()); + } + + @Test + public void B_sendMediaMessage() { + Intents.init(); + Intent resultData = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + intending(not(isInternal())).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData)); + + Espresso.onView(allOf( + withId(R.id.ivArrow), + isDisplayed())).perform(click()); + + Espresso.onView(allOf( + withId(R.id.gallery_message), + isDisplayed())).perform(click()); + try { + Thread.sleep(5000); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + Intents.release(); + } + + @Test + public void C_sendCameraImage() { + Intents.init(); + + intending(hasAction(MediaStore.ACTION_IMAGE_CAPTURE)).respondWith( + new Instrumentation.ActivityResult(Activity.RESULT_OK, null)); + + IntentCallback intentCallback = new IntentCallback() { + @Override + public void onIntentSent(Intent intent) { + if (intent.getAction().equals("android.media.action.IMAGE_CAPTURE")) { + try { + Uri imageUri = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT); + Context context = InstrumentationRegistry.getInstrumentation().getContext(); + Bitmap icon = BitmapFactory.decodeResource( + context.getResources(), + R.drawable.ic_menu_manage); + OutputStream out = InstrumentationRegistry.getInstrumentation() + .getContext().getContentResolver().openOutputStream(imageUri); + icon.compress(Bitmap.CompressFormat.JPEG, 100, out); + out.flush(); + out.close(); + } catch (IOException e) { + Log.e("onIntentSent: ",e.getMessage()); + } + } + } + }; + IntentMonitorRegistry.getInstance().addIntentCallback(intentCallback); + + Espresso.onView(allOf( + withId(R.id.ivArrow), + isDisplayed())).perform(click()); + + Espresso.onView(allOf( + withId(R.id.camera_message), + isDisplayed())).perform(click()); + try { + Thread.sleep(10000); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + Intents.release(); + } + + @Test + public void D_checkAudioMessage() { + Intents.init(); + Intent resultData = new Intent(Intent.ACTION_GET_CONTENT, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); + intending(not(isInternal())).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData)); + + Espresso.onView(allOf( + withId(R.id.ivArrow), + isDisplayed())).perform(click()); + + Espresso.onView(allOf( + withId(R.id.audio_message), + isDisplayed())).perform(click()); + try { + Thread.sleep(5000); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + Intents.release(); + + } + + @Test + public void E_checkLocationMessage() { + try { + Espresso.onView(allOf( + withId(R.id.ivArrow), + isDisplayed())).perform(click()); + + Espresso.onView(allOf( + withId(R.id.location_message), + isDisplayed())).perform(click()); + + Thread.sleep(2000); + + Espresso.onView(allOf( + withText(R.string.share), + isDisplayed())).perform(click()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + +} + + + + diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/UsersListTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/UsersListTest.java new file mode 100644 index 00000000..5b8ea600 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/uikit/UsersListTest.java @@ -0,0 +1,117 @@ +package com.cometchat.pro.androiduikit.uikit; + +import android.content.Context; +import android.content.Intent; +import android.view.View; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; +import androidx.test.espresso.Espresso; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.uikit.ui_components.chats.CometChatConversationList; +import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI; +import com.cometchat.pro.uikit.ui_components.users.user_list.CometChatUserList; +import com.google.android.material.bottomnavigation.BottomNavigationView; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class UsersListTest { + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private static final String STRING_TO_BE_TYPED = "superhero5"; + + private UiDevice mDevice; + + private BottomNavigationView bottomNavigation; + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(CometChatUI.class, true, false); + + private View view; + + @Before + public void setup() { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + if (CometChat.getLoggedInUser()==null) { + // Type text and then press the button. + Espresso.onView(withId(R.id.superhero1)).perform(ViewActions.click()); + } + Espresso.onView(withId(R.id.directLaunch)).perform(click()); + bottomNavigation = CometChatUI.getBinding().bottomNavigation; + Fragment userList = new CometChatUserList(); + CometChatUI.getCometChatUIActivity() + .getSupportFragmentManager().beginTransaction() + .replace(CometChatUI.getBinding().frame.getId(),userList).commit(); + try { + Thread.sleep(3000); + view = userList.getView(); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void A_checkUserListNotEmpty() { + RecyclerView userList = (RecyclerView)view.findViewById(R.id.rv_user_list); + RecyclerView.Adapter adapter = userList.getAdapter(); + if (adapter.getItemCount()>1) { + Espresso.onView(Matchers.allOf( + withId(R.id.rv_user_list), + isDescendantOfA(withId(view.getId())), + isDisplayed())) + .perform(RecyclerViewActions.actionOnItemAtPosition(1,click())); + Assert.assertTrue("Not Empty",true); + } else { + Assert.fail("UserList is Empty"); + } + } + + @Test + public void A_checkUserListLastItem() { + RecyclerView userList = (RecyclerView)view.findViewById(R.id.rv_user_list); + RecyclerView.Adapter adapter = userList.getAdapter(); + if (adapter.getItemCount()>1) { + Espresso.onView(Matchers.allOf( + withId(R.id.rv_user_list), + isDescendantOfA(withId(view.getId())), + isDisplayed())) + .perform(RecyclerViewActions.scrollToPosition(adapter.getItemCount()-1)) + .perform(RecyclerViewActions.actionOnItemAtPosition(adapter.getItemCount()-1,click())); + } else { + Assert.fail("ConversationList is Empty"); + } + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/RecyclerViewAssertion.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/RecyclerViewAssertion.java index 47a93f4c..b4417439 100644 --- a/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/RecyclerViewAssertion.java +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/RecyclerViewAssertion.java @@ -8,6 +8,7 @@ import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.Assert; public class RecyclerViewAssertion implements ViewAssertion { private final int expectedCount; @@ -24,6 +25,12 @@ public void check(View view, NoMatchingViewException noViewFoundException) { RecyclerView recyclerView = (RecyclerView) view; RecyclerView.Adapter adapter = recyclerView.getAdapter(); - MatcherAssert.assertThat(adapter.getItemCount(), Matchers.is(expectedCount)); + if (adapter.getItemCount()<1) { + Assert.fail("No Conversation Found"); + } else if (adapter.getItemCount() - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/navigation_bottom.xml b/app/src/main/res/menu/navigation_bottom.xml deleted file mode 100644 index e3ab2755..00000000 --- a/app/src/main/res/menu/navigation_bottom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9fd8bae3..7602914f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -29,7 +29,6 @@ @style/TextAppearance.MaterialComponents.Button @style/TextAppearance.MaterialComponents.Overline -