forked from RocketChat/Rocket.Chat.Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: channelFragment and member module
- Loading branch information
1 parent
125249b
commit a9a763b
Showing
5 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
app/src/androidTest/java/chat/rocket/android/createchannel/ui/CreateChannelFragmentTest.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,77 @@ | ||
package chat.rocket.android.createchannel.ui | ||
|
||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.NoMatchingViewException | ||
import androidx.test.espresso.action.ViewActions.* | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.* | ||
import androidx.test.rule.ActivityTestRule | ||
import chat.rocket.android.R | ||
import chat.rocket.android.analytics.event.ScreenViewEvent | ||
import chat.rocket.android.authentication.ui.AuthenticationActivity | ||
import chat.rocket.android.util.extensions.addFragmentBackStack | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import testConfig.Config.Companion.PASSWORD | ||
import testConfig.Config.Companion.USERNAME | ||
import testConfig.Config.Companion.serverUrl | ||
|
||
|
||
class CreateChannelFragmentTest { | ||
@JvmField | ||
var activityRule = ActivityTestRule(AuthenticationActivity::class.java, true, true) | ||
|
||
@Rule | ||
fun rule() = activityRule | ||
|
||
@Before | ||
fun setUp() { | ||
try { | ||
rule().activity.addFragmentBackStack(ScreenViewEvent.Login.screenName, R.id.fragment_container) { | ||
chat.rocket.android.authentication.login.ui.newInstance(serverUrl) | ||
} | ||
onView(withId(R.id.text_username_or_email)).perform(typeText(USERNAME), closeSoftKeyboard()) | ||
onView(withId(R.id.text_password)).perform(typeText(PASSWORD), closeSoftKeyboard()) | ||
onView(withId(R.id.button_log_in)).perform(click()) | ||
Thread.sleep(12000) | ||
onView(withId(R.id.action_new_channel)).perform(click()) | ||
} catch (e: NoMatchingViewException) { | ||
onView(withId(R.id.action_new_channel)).perform(click()) | ||
} | ||
} | ||
|
||
@Test | ||
fun check_UI_element() { | ||
onView(withId(R.id.text_channel_type)).check(matches(isDisplayed())) | ||
onView(withId(R.id.text_channel_type_description)).check(matches(isDisplayed())) | ||
onView(withId(R.id.switch_channel_type)).check(matches(isDisplayed())) | ||
onView(withId(R.id.text_read_only)).check(matches(isDisplayed())) | ||
onView(withId(R.id.text_read_only_description)).check(matches(isDisplayed())) | ||
onView(withId(R.id.switch_read_only)).check(matches(isDisplayed())) | ||
onView(withId(R.id.image_channel_icon)).check(matches(isDisplayed())) | ||
onView(withId(R.id.text_channel_name)).check(matches(isDisplayed())) | ||
onView(withId(R.id.image_invite_member)).check(matches(isDisplayed())) | ||
onView(withId(R.id.text_invite_members)).check(matches(isDisplayed())) | ||
} | ||
|
||
@Test | ||
fun channel_should_be_public() { | ||
onView(withId(R.id.text_channel_type)).check(matches(withText("Public"))) | ||
onView(withId(R.id.text_channel_type_description)).check(matches(withText(R.string.msg_public_channel_description))) | ||
} | ||
|
||
@Test | ||
fun channel_should_be_private() { | ||
onView(withId(R.id.switch_channel_type)).perform(click()) | ||
onView(withId(R.id.text_channel_type)).check(matches(withText("Private"))) | ||
onView(withId(R.id.switch_channel_type)).perform(click()) | ||
} | ||
|
||
@Test | ||
fun channel_description_should_change_on_making_channel_private() { | ||
onView(withId(R.id.switch_channel_type)).perform(click()) | ||
onView(withId(R.id.text_channel_type_description)).check(matches(withText(R.string.msg_private_channel_description))) | ||
onView(withId(R.id.switch_channel_type)).perform(click()) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/androidTest/java/chat/rocket/android/matchers/RecyclerViewCountAssertion.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,29 @@ | ||
package chat.rocket.android.matchers | ||
|
||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.test.espresso.NoMatchingViewException | ||
import androidx.test.espresso.ViewAssertion | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.MatcherAssert.assertThat | ||
|
||
|
||
class RecyclerViewItemCountAssertion private constructor(private val matcher: Matcher<Int>) : | ||
ViewAssertion { | ||
|
||
override fun check(view: View, noViewFoundException: NoMatchingViewException?) { | ||
if (noViewFoundException != null) { | ||
throw noViewFoundException | ||
} | ||
val recyclerView = view as RecyclerView | ||
val adapter = recyclerView.getAdapter() | ||
assertThat(adapter!!.itemCount, matcher) | ||
} | ||
|
||
companion object { | ||
|
||
fun withItemCount(matcher: Matcher<Int>): RecyclerViewItemCountAssertion { | ||
return RecyclerViewItemCountAssertion(matcher) | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
app/src/androidTest/java/chat/rocket/android/members/ui/MembersFragmentTest.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,76 @@ | ||
package chat.rocket.android.members.ui | ||
|
||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.NoMatchingViewException | ||
import androidx.test.espresso.action.ViewActions.* | ||
import androidx.test.espresso.contrib.RecyclerViewActions | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.rule.ActivityTestRule | ||
import chat.rocket.android.R | ||
import chat.rocket.android.analytics.event.ScreenViewEvent | ||
import chat.rocket.android.authentication.ui.AuthenticationActivity | ||
import chat.rocket.android.matchers.RecyclerViewItemCountAssertion.Companion.withItemCount | ||
import chat.rocket.android.util.extensions.addFragmentBackStack | ||
import org.hamcrest.Matchers.greaterThan | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import testConfig.Config.Companion.MEMBERS | ||
import testConfig.Config.Companion.PASSWORD | ||
import testConfig.Config.Companion.USERNAME | ||
import testConfig.Config.Companion.serverUrl | ||
|
||
|
||
class MembersFragmentTest { | ||
|
||
@JvmField | ||
var activityRule = ActivityTestRule(AuthenticationActivity::class.java, true, true) | ||
|
||
@Rule | ||
fun rule() = activityRule | ||
|
||
@Before | ||
fun setUp() { | ||
try { | ||
login_if_user_is_logged_out() | ||
navigate_to_channel_details() | ||
} catch (e: NoMatchingViewException) { | ||
navigate_to_channel_details() | ||
} | ||
} | ||
|
||
@Test | ||
fun members_should_be_greater_than_zero(){ | ||
onView(withText(MEMBERS)).perform(click()) | ||
Thread.sleep(6000) | ||
onView(withId(R.id.recycler_view)).check(withItemCount(greaterThan(0))) | ||
} | ||
|
||
|
||
private fun login_if_user_is_logged_out(){ | ||
rule().activity.addFragmentBackStack(ScreenViewEvent.Login.screenName, R.id.fragment_container) { | ||
chat.rocket.android.authentication.login.ui.newInstance(serverUrl) | ||
} | ||
onView(withId(R.id.text_username_or_email)).perform( | ||
typeText(USERNAME), | ||
closeSoftKeyboard() | ||
) | ||
onView(withId(R.id.text_password)).perform(typeText(PASSWORD), closeSoftKeyboard()) | ||
onView(withId(R.id.button_log_in)).perform(click()) | ||
Thread.sleep(12000) | ||
} | ||
|
||
private fun navigate_to_channel_details() { | ||
Thread.sleep(5000) | ||
onView(withId(R.id.recycler_view)) | ||
.perform( | ||
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>( | ||
0, click() | ||
) | ||
) | ||
Thread.sleep(2000) | ||
onView(withId(R.id.text_toolbar_title)).perform(click()) | ||
} | ||
} |
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
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