-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'autoresponder' into dev
- Loading branch information
Showing
17 changed files
with
545 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...at/ConversationStorageInstrumentedTest.kt → ...ce/ConversationStorageInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...ndroidTest/kotlin/com/glodanif/bluetoothchat/ui/BluetoothCommunicationInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package com.glodanif.bluetoothchat.ui; | ||
|
||
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE | ||
import android.app.Activity | ||
import android.content.Intent | ||
import android.support.test.espresso.Espresso.onView | ||
import android.support.test.espresso.action.ViewActions.* | ||
import android.support.test.espresso.assertion.ViewAssertions.matches | ||
import android.support.test.espresso.matcher.RootMatchers.withDecorView | ||
import android.support.test.espresso.matcher.ViewMatchers.* | ||
import android.support.test.filters.LargeTest | ||
import android.support.test.filters.MediumTest | ||
import android.support.test.rule.ActivityTestRule | ||
import android.support.test.rule.GrantPermissionRule | ||
import android.support.test.runner.AndroidJUnit4 | ||
import com.glodanif.bluetoothchat.R | ||
import com.glodanif.bluetoothchat.data.internal.AutoresponderProxy | ||
import com.glodanif.bluetoothchat.ui.UITestUtils.Companion.atPosition | ||
import com.glodanif.bluetoothchat.ui.UITestUtils.Companion.withToolbarSubTitle | ||
import com.glodanif.bluetoothchat.ui.activity.ChatActivity | ||
import org.hamcrest.Matchers.`is` | ||
import org.hamcrest.Matchers.not | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
class BluetoothCommunicationInstrumentedTest { | ||
|
||
private val autoResponderAddress = "AC:22:0B:A1:89:A8" | ||
|
||
@Rule | ||
@JvmField | ||
val activityRule = ActivityTestRule(ChatActivity::class.java, true, false) | ||
|
||
@Rule | ||
@JvmField | ||
val grantPermissionRule: GrantPermissionRule? = GrantPermissionRule.grant(WRITE_EXTERNAL_STORAGE) | ||
|
||
private val textMessageDelay = 2500.toLong() | ||
private val fileMessageDelay = 12500.toLong() | ||
private lateinit var context: Activity | ||
|
||
@Before | ||
fun setup() { | ||
activityRule.launchActivity(Intent() | ||
.putExtra(ChatActivity.EXTRA_ADDRESS, autoResponderAddress)) | ||
context = activityRule.activity | ||
} | ||
|
||
@Test | ||
fun communication() { | ||
checkNotConnected() | ||
checkNotSendingTextIfDisconnected() | ||
|
||
onView(withText(R.string.chat__connect)).perform(click()) | ||
checkOutcommingConnection() | ||
|
||
checkTextMessageReceiving() | ||
checkTextMessageReceiving() | ||
checkFileMessageReceiving() | ||
checkFileMessageReceivingAndCancelByPartner() | ||
checkFileMessageReceiving() | ||
checkFileMessageReceivingAndCancelByPartner() | ||
checkTextMessageReceiving() | ||
|
||
checkDisconnectionByPartner() | ||
onView(withId(android.R.id.button2)).perform(click()) | ||
|
||
onView(withText(R.string.chat__connect)).perform(click()) | ||
checkOutcommingConnection() | ||
|
||
checkDisconnectionByPartner() | ||
onView(withId(android.R.id.button1)).perform(click()) | ||
checkOutcommingConnection() | ||
|
||
checkDisconnectionByPartner() | ||
onView(withId(android.R.id.button2)).perform(click()) | ||
|
||
checkNotConnected() | ||
} | ||
|
||
private fun checkOutcommingConnection() { | ||
onView(withText(R.string.chat__waiting_for_device)) | ||
onView(withId(R.id.tb_toolbar)).check(matches( | ||
withToolbarSubTitle(context.getString(R.string.chat__pending)))) | ||
Thread.sleep(textMessageDelay) | ||
onView(withId(R.id.av_actions)).check(matches(not(isDisplayed()))) | ||
onView(withId(R.id.tb_toolbar)).check(matches( | ||
withToolbarSubTitle(context.getString(R.string.chat__connected)))) | ||
} | ||
|
||
private fun checkFileMessageReceiving() { | ||
onView(withId(R.id.et_message)).perform(typeText(AutoresponderProxy.COMMAND_SEND_FILE)) | ||
onView(withId(R.id.ib_send)).perform(click()) | ||
Thread.sleep(textMessageDelay) | ||
onView(withText(R.string.chat__receiving_images)).check(matches(isDisplayed())) | ||
Thread.sleep(fileMessageDelay) | ||
onView(withId(R.id.rv_chat)) | ||
.check(matches(atPosition(0, hasDescendant(withId(R.id.iv_image))))) | ||
onView(withText(R.string.chat__receiving_images)).check(matches(not(isDisplayed()))) | ||
} | ||
|
||
private fun checkFileMessageReceivingAndCancelByPartner() { | ||
onView(withId(R.id.et_message)).perform(typeText(AutoresponderProxy.COMMAND_SEND_FILE_AND_CANCEL)) | ||
onView(withId(R.id.ib_send)).perform(click()) | ||
Thread.sleep(textMessageDelay * 2) | ||
onView(withText(R.string.chat__partner_canceled_image_transfer)) | ||
.inRoot(withDecorView(not(`is`(context.window.decorView)))).check(matches(isDisplayed())) | ||
onView(withText(R.string.chat__receiving_images)).check(matches(not(isDisplayed()))) | ||
onView(withId(R.id.rv_chat)) | ||
.check(matches(atPosition(0, not(hasDescendant(withText(AutoresponderProxy.RESPONSE_RECEIVED)))))) | ||
} | ||
|
||
private fun checkNotSendingTextIfDisconnected() { | ||
onView(withId(R.id.et_message)).perform(typeText(AutoresponderProxy.COMMAND_SEND_TEXT)) | ||
onView(withId(R.id.ib_send)).perform(click()) | ||
onView(withText(R.string.chat__not_connected_to_send)) | ||
.inRoot(withDecorView(not(`is`(context.window.decorView)))).check(matches(isDisplayed())) | ||
onView(withId(R.id.et_message)).perform(clearText()) | ||
} | ||
|
||
private fun checkTextMessageReceiving() { | ||
onView(withId(R.id.et_message)).perform(typeText(AutoresponderProxy.COMMAND_SEND_TEXT)) | ||
onView(withId(R.id.ib_send)).perform(click()) | ||
Thread.sleep(textMessageDelay) | ||
onView(withId(R.id.rv_chat)) | ||
.check(matches(atPosition(0, hasDescendant(withText(AutoresponderProxy.RESPONSE_RECEIVED))))) | ||
} | ||
|
||
private fun checkDisconnectionByPartner() { | ||
onView(withId(R.id.et_message)).perform(typeText(AutoresponderProxy.COMMAND_DISCONNECT)) | ||
onView(withId(R.id.ib_send)).perform(click()) | ||
Thread.sleep(textMessageDelay) | ||
onView(withText(R.string.chat__partner_disconnected)).check(matches(isDisplayed())) | ||
} | ||
|
||
private fun checkNotConnected() { | ||
onView(withText(R.string.chat__not_connected_to_this_device)) | ||
.check(matches(isDisplayed())) | ||
onView(withId(R.id.tb_toolbar)).check(matches( | ||
withToolbarSubTitle(context.getString(R.string.chat__not_connected)))) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/androidTest/kotlin/com/glodanif/bluetoothchat/ui/UITestUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.glodanif.bluetoothchat.ui | ||
|
||
import android.support.test.espresso.matcher.BoundedMatcher | ||
import android.support.v7.widget.RecyclerView | ||
import android.support.v7.widget.Toolbar | ||
import android.view.View | ||
import org.hamcrest.Description | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.Matchers | ||
|
||
class UITestUtils { | ||
|
||
companion object { | ||
|
||
fun atPosition(position: Int, itemMatcher: Matcher<View>): Matcher<View> { | ||
|
||
checkNotNull(itemMatcher) | ||
|
||
return object : BoundedMatcher<View, RecyclerView>(RecyclerView::class.java) { | ||
|
||
override fun describeTo(description: Description) { | ||
description.appendText("has item at position $position: ") | ||
itemMatcher.describeTo(description) | ||
} | ||
|
||
override fun matchesSafely(view: RecyclerView): Boolean { | ||
val viewHolder = view.findViewHolderForAdapterPosition(position) | ||
?: // has no item on such position | ||
return false | ||
return itemMatcher.matches(viewHolder.itemView) | ||
} | ||
} | ||
} | ||
|
||
fun withToolbarSubTitle(title: CharSequence): Matcher<View> { | ||
return withToolbarSubTitle(Matchers.`is`(title)) | ||
} | ||
|
||
fun withToolbarSubTitle(textMatcher: Matcher<CharSequence>): Matcher<View> { | ||
|
||
return object : BoundedMatcher<View, Toolbar>(Toolbar::class.java) { | ||
|
||
public override fun matchesSafely(toolbar: Toolbar): Boolean { | ||
return textMatcher.matches(toolbar.subtitle) | ||
} | ||
|
||
override fun describeTo(description: Description) { | ||
description.appendText("with toolbar title: ") | ||
textMatcher.describeTo(description) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name" translatable="false">BLC DEV</string> | ||
|
||
</resources> | ||
</resources> |
Oops, something went wrong.