diff --git a/app/src/androidTest/java/kommunicate/io/sample/ConversationTest.kt b/app/src/androidTest/java/kommunicate/io/sample/ConversationTest.kt index eee79387..7566c779 100644 --- a/app/src/androidTest/java/kommunicate/io/sample/ConversationTest.kt +++ b/app/src/androidTest/java/kommunicate/io/sample/ConversationTest.kt @@ -21,7 +21,6 @@ import io.kommunicate.users.KMUser import kommunicate.io.sample.network.KommunicateChatAPI import kommunicate.io.sample.network.KommunicateDashboardAPI import kommunicate.io.sample.network.RetrofitClient -import kommunicate.io.sample.utils.KmTestHelper import kommunicate.io.sample.utils.KmTestHelper.getBotIdsFromDashboard import kommunicate.io.sample.utils.getAuthToken import kommunicate.io.sample.utils.getRandomKmUser @@ -45,7 +44,6 @@ import java.lang.Exception import java.util.concurrent.CountDownLatch import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException -import kotlin.math.log @RunWith(AndroidJUnit4::class) class ConversationTest { @@ -73,7 +71,7 @@ class ConversationTest { fun testCreateSingleThreadConversation() { val tempUser = getRandomKmUser() val latch = CountDownLatch(1) - var groupId = 0 + var groupId = 1 mActivityRule.onActivity { it.lifecycleScope.launch { @@ -173,6 +171,10 @@ class ConversationTest { assertEquals("Conversation Group ID miss-match. Single threaded conversation should have same group id irrespective of number of time launchConversation called.", groupIdFirst, groupIdSecond) sendMessageAsUser(secondMessage) + // wait for message to appear on dashboard. + onView(isRoot()) + .perform(waitFor(3000)) + // verify message on dashboard. verifyMessagesOnTheDashboard(groupIdFirst.toString(), listOf(firstMessage, secondMessage), tempUser.userId) } @@ -270,27 +272,38 @@ class ConversationTest { @Test fun testUpdateConversationAssigneeAndVerifyFromDashboard() { val tempUser = getRandomKmUser() - val latch = CountDownLatch(1) + var latch = CountDownLatch(1) var groupId = 0 val botIds = listOf("inline-code-34rpc") val updateBotAssigneeId = "kk-3s8r3" - val agentIds = listOf("prateek.singh@kommunicate.io") + val agentIds = listOf("prateek.singh@kommunicate.io", "prateek.singh+fhg@kommunicate.io") mActivityRule.onActivity { it.lifecycleScope.launch { loginUser(it, tempUser) groupId = launchConversation(it, botIds = botIds) as Int - updateConversationAssignee(it, groupId, updateBotAssigneeId) }.invokeOnCompletion { latch.countDown() } } onView(isRoot()) - .perform(waitForLatch(latch, waitAfterLatch = 5000)) + .perform(waitForLatch(latch)) sendMessageAsUser(getRandomString()) + latch = CountDownLatch(1) + mActivityRule.onActivity { + it.lifecycleScope.launch { + updateConversationAssignee(it, groupId, updateBotAssigneeId) + }.invokeOnCompletion { + latch.countDown() + } + } + + onView(isRoot()) + .perform(waitForLatch(latch)) + // validate data on dashboard runBlocking { val dashboardGroupFeeds = chatAPI.getMessageList( diff --git a/app/src/androidTest/java/kommunicate/io/sample/ConversationWithPreChatTest.kt b/app/src/androidTest/java/kommunicate/io/sample/ConversationWithPreChatTest.kt index 4d2bed6d..d2a48550 100644 --- a/app/src/androidTest/java/kommunicate/io/sample/ConversationWithPreChatTest.kt +++ b/app/src/androidTest/java/kommunicate/io/sample/ConversationWithPreChatTest.kt @@ -30,6 +30,7 @@ import io.kommunicate.users.KMUser import kommunicate.io.sample.network.KommunicateChatAPI import kommunicate.io.sample.network.KommunicateDashboardAPI import kommunicate.io.sample.network.RetrofitClient +import kommunicate.io.sample.utils.clearAppData import kommunicate.io.sample.utils.getAuthToken import kommunicate.io.sample.utils.getRandomString import kommunicate.io.sample.utils.sendMessageAsUser @@ -50,14 +51,17 @@ import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.Assert.fail import org.junit.Before +import org.junit.FixMethodOrder +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.junit.runners.MethodSorters import java.util.concurrent.CountDownLatch import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import com.applozic.mobicomkit.uiwidgets.R as Rui - +@FixMethodOrder(MethodSorters.NAME_ASCENDING) @RunWith(AndroidJUnit4::class) class ConversationWithPreChatTest { @@ -103,6 +107,9 @@ class ConversationWithPreChatTest { } }) } + onView(isRoot()) + .perform(waitFor(5000)) + onView(withId(Rui.id.kmPreChatRecyclerView)) .perform( actionOnItemAtPosition( @@ -144,11 +151,11 @@ class ConversationWithPreChatTest { } ) ) - onView(isRoot()).perform(waitFor(1000)) + onView(isRoot()).perform(waitFor(5000)) onView(withId(Rui.id.start_conversation)) .perform(click()) - onView(isRoot()).perform(waitFor(2500)) + onView(isRoot()).perform(waitFor(5000)) // Send message val messageList = listOf( @@ -318,7 +325,7 @@ class ConversationWithPreChatTest { } @Test - fun testLaunchConversationWithCustomUserWithoutUserId() { + fun atestLaunchConversationWithCustomUserWithoutUserId() { val tempUserMail = "${getRandomString(12)}@${getRandomString(5, ignoreNums = true)}.${getRandomString(3, ignoreNums = true)}" val tempName = getRandomString(10) val tempUserPhone = getRandomString(10, true) diff --git a/app/src/androidTest/java/kommunicate/io/sample/utils/Utils.kt b/app/src/androidTest/java/kommunicate/io/sample/utils/Utils.kt index 8929a141..a54802a5 100644 --- a/app/src/androidTest/java/kommunicate/io/sample/utils/Utils.kt +++ b/app/src/androidTest/java/kommunicate/io/sample/utils/Utils.kt @@ -6,6 +6,7 @@ import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.util.Base64 +import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.LinearLayout @@ -28,8 +29,10 @@ import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.ViewAssertion import androidx.test.espresso.action.ViewActions import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.typeText import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.platform.app.InstrumentationRegistry import com.applozic.mobicomkit.uiwidgets.R import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -122,7 +125,7 @@ fun getRandomKmUser(): KMUser { fun sendMessageAsUser(message: String) { onView(withId(R.id.conversation_message)) - .perform(ViewActions.typeText(message)) + .perform(click(), typeText(message)) closeSoftKeyboard() onView(withId(R.id.conversation_send)) @@ -204,3 +207,22 @@ private fun atPosition(position: Int): Matcher { } } } + +fun disableAnimations() { + val disableAnimationsCommand = listOf( + "settings put global window_animation_scale 0", + "settings put global transition_animation_scale 0", + "settings put global animator_duration_scale 0" + ) + + disableAnimationsCommand.forEach { command -> + InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand(command) + } +} + +fun clearAppData() { + val packageName = InstrumentationRegistry.getInstrumentation().targetContext.packageName + val uiAutomation = InstrumentationRegistry.getInstrumentation().uiAutomation + uiAutomation.executeShellCommand("pm clear $packageName").close() + Log.d("as", packageName) +} \ No newline at end of file