Merge pull request #82 from H-PixelDroid/issue/81
fix tests using swipe motion
This commit is contained in:
commit
bf808725db
|
@ -65,7 +65,7 @@ dependencies {
|
|||
implementation "androidx.browser:browser:1.2.0"
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
|
||||
def room_version = "2.2.4"
|
||||
def room_version = "2.2.5"
|
||||
implementation "androidx.room:room-runtime:$room_version"
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
|
||||
|
@ -84,6 +84,8 @@ dependencies {
|
|||
|
||||
androidTestImplementation("com.squareup.okhttp3:mockwebserver:4.4.0")
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||
androidTestImplementation 'androidx.test:rules:1.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
|
|||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import okhttp3.mockwebserver.Dispatcher
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
|
@ -77,33 +78,23 @@ class MockedServerTest {
|
|||
.targetContext.getSharedPreferences("com.h.pixeldroid.pref", Context.MODE_PRIVATE)
|
||||
preferences.edit().putString("accessToken", "azerty").apply()
|
||||
preferences.edit().putString("domain", baseUrl.toString()).apply()
|
||||
ActivityScenario.launch(MainActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFollowersTextView() {
|
||||
onView(withId(R.id.view_pager)).perform(ViewActions.swipeLeft()).perform(ViewActions.swipeLeft()).perform(
|
||||
ViewActions.swipeLeft()
|
||||
).perform(ViewActions.swipeLeft())
|
||||
ActivityScenario.launch(MainActivity::class.java).onActivity{
|
||||
a -> a.findViewById<TabLayout>(R.id.tabs).getTabAt(4)?.select()
|
||||
}
|
||||
Thread.sleep(1000)
|
||||
onView(withId(R.id.nbFollowersTextView)).check(matches(withText("68\nFollowers")))
|
||||
onView(withId(R.id.accountNameTextView)).check(matches(withText("deerbard_photo")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swipingDownOnHomepageShowsMorePosts() {
|
||||
Thread.sleep(1000)
|
||||
|
||||
val firstDesc = withId(R.id.description)
|
||||
onView(withId(R.id.view_pager)).perform(ViewActions.swipeUp()).perform(ViewActions.swipeDown()).perform(
|
||||
ViewActions.swipeDown()
|
||||
)
|
||||
onView(withId(R.id.description)).check(matches(firstDesc))
|
||||
}
|
||||
@Test
|
||||
fun testNotificationsList() {
|
||||
onView(withId(R.id.view_pager)).perform(ViewActions.swipeLeft()).perform(
|
||||
ViewActions.swipeLeft()
|
||||
).perform(ViewActions.swipeLeft())
|
||||
ActivityScenario.launch(MainActivity::class.java).onActivity{
|
||||
a -> a.findViewById<TabLayout>(R.id.tabs).getTabAt(3)?.select()
|
||||
}
|
||||
Thread.sleep(1000)
|
||||
|
||||
onView(withId(R.id.view_pager)).perform(ViewActions.swipeUp()).perform(ViewActions.swipeDown())
|
||||
|
@ -115,9 +106,9 @@ class MockedServerTest {
|
|||
}
|
||||
@Test
|
||||
fun clickNotification() {
|
||||
onView(withId(R.id.view_pager)).perform(ViewActions.swipeLeft()).perform(
|
||||
ViewActions.swipeLeft()
|
||||
).perform(ViewActions.swipeLeft())
|
||||
ActivityScenario.launch(MainActivity::class.java).onActivity{
|
||||
a -> a.findViewById<TabLayout>(R.id.tabs).getTabAt(3)?.select()
|
||||
}
|
||||
Thread.sleep(1000)
|
||||
|
||||
onView(withId(R.id.view_pager)).perform(ViewActions.swipeUp()).perform(ViewActions.swipeDown())
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.junit.Before
|
|||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
|
@ -31,8 +30,6 @@ class SettingsTest {
|
|||
.targetContext.getSharedPreferences("com.h.pixeldroid.pref", Context.MODE_PRIVATE)
|
||||
preferences.edit().putString("accessToken", "azerty").apply()
|
||||
preferences.edit().putString("domain", "http://localhost").apply()
|
||||
ActivityScenario.launch(MainActivity::class.java)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
package com.h.pixeldroid
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.swipeLeft
|
||||
import androidx.test.espresso.action.ViewActions.swipeRight
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.action.ViewActions.*
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.hamcrest.Matcher
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
@ -28,33 +34,30 @@ class SwipeTest {
|
|||
.targetContext.getSharedPreferences("com.h.pixeldroid.pref", Context.MODE_PRIVATE)
|
||||
preferences.edit().putString("accessToken", "azerty").apply()
|
||||
preferences.edit().putString("domain", "http://localhost").apply()
|
||||
ActivityScenario.launch(MainActivity::class.java)
|
||||
}
|
||||
|
||||
fun swipingLeftOnSearchShowsCameraFragment() {
|
||||
onView(withId(R.id.main_activity_main_linear_layout))
|
||||
.perform(swipeLeft()) // go to search
|
||||
.perform(swipeLeft())
|
||||
onView(withId(R.id.camera_fragment_main_linear_layout)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swipingRightOnNotificationsShowsCameraFragment() {
|
||||
fun swipingLeftStopsAtProfile() {
|
||||
onView(withId(R.id.main_activity_main_linear_layout))
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft()) // go to notifications
|
||||
.perform(swipeRight())
|
||||
onView(withId(R.id.camera_fragment_main_linear_layout)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swipingLeftShowsProfileFragment() {
|
||||
onView(withId(R.id.view_pager))
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft())
|
||||
.perform(swipeLeft()) // search
|
||||
.perform(swipeLeft()) // camera
|
||||
.perform(swipeLeft()) // notifications
|
||||
.perform(swipeLeft()) // profile
|
||||
.perform(swipeLeft()) // should stop at profile
|
||||
onView(withId(R.id.nbFollowersTextView)).check(matches(isDisplayed()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swipingRightStopsAtHomepage() {
|
||||
ActivityScenario.launch(MainActivity::class.java).onActivity {
|
||||
a -> a.findViewById<TabLayout>(R.id.tabs).getTabAt(4)?.select()
|
||||
} // go to the last tab
|
||||
onView(withId(R.id.main_activity_main_linear_layout))
|
||||
.perform(swipeRight()) // notifications
|
||||
.perform(swipeRight()) // camera
|
||||
.perform(swipeRight()) // search
|
||||
.perform(swipeRight()) // homepage
|
||||
.perform(swipeRight()) // should stop at homepage
|
||||
onView(withId(R.id.feedList)).check(matches(isDisplayed()))
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import android.content.Intent
|
|||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
|
||||
import androidx.annotation.NonNull
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.GravityCompat
|
||||
|
@ -21,7 +20,6 @@ import com.h.pixeldroid.fragments.HomeFragment
|
|||
import com.h.pixeldroid.fragments.MyProfileFragment
|
||||
import com.h.pixeldroid.fragments.NotificationsFragment
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private lateinit var drawerLayout: DrawerLayout
|
||||
|
|
|
@ -33,8 +33,6 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
Loading…
Reference in New Issue