Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asa #588

Closed
wants to merge 2 commits into from
Closed

Asa #588

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions app/src/androidTest/java/kommunicate/io/sample/ConversationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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("[email protected]")
val agentIds = listOf("[email protected]", "[email protected]")

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -103,6 +107,9 @@ class ConversationWithPreChatTest {
}
})
}
onView(isRoot())
.perform(waitFor(5000))

onView(withId(Rui.id.kmPreChatRecyclerView))
.perform(
actionOnItemAtPosition<KmPrechatInputAdapter.KmPrechatInputViewHolder>(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion app/src/androidTest/java/kommunicate/io/sample/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -204,3 +207,22 @@ private fun atPosition(position: Int): Matcher<View> {
}
}
}

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)
}
Loading