2020-04-17 15:07:04 +02:00
|
|
|
package com.h.pixeldroid
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import androidx.test.core.app.ActivityScenario
|
2020-05-19 09:49:34 +02:00
|
|
|
import androidx.test.core.app.ApplicationProvider
|
2020-04-17 15:07:04 +02:00
|
|
|
import androidx.test.espresso.Espresso.onView
|
2020-05-15 09:23:06 +02:00
|
|
|
import androidx.test.espresso.action.ViewActions.click
|
2020-04-17 15:07:04 +02:00
|
|
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
|
|
|
import androidx.test.espresso.contrib.DrawerActions
|
|
|
|
import androidx.test.espresso.contrib.DrawerMatchers
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.*
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
2020-05-14 20:14:41 +02:00
|
|
|
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
|
|
|
|
import androidx.test.uiautomator.UiDevice
|
2020-05-19 09:49:34 +02:00
|
|
|
import com.h.pixeldroid.db.AppDatabase
|
2020-11-27 17:02:52 +01:00
|
|
|
import com.h.pixeldroid.db.entities.InstanceDatabaseEntity
|
|
|
|
import com.h.pixeldroid.db.entities.UserDatabaseEntity
|
2020-04-17 15:07:04 +02:00
|
|
|
import com.h.pixeldroid.testUtility.MockServer
|
2020-11-08 20:24:38 +01:00
|
|
|
import com.h.pixeldroid.testUtility.clearData
|
2020-07-26 20:56:01 +02:00
|
|
|
import com.h.pixeldroid.testUtility.initDB
|
2020-11-08 20:24:38 +01:00
|
|
|
import org.junit.After
|
2020-04-17 15:07:04 +02:00
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.Timeout
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
class DrawerMenuTest {
|
|
|
|
|
2020-11-08 20:24:38 +01:00
|
|
|
private lateinit var mockServer: MockServer
|
2020-05-19 09:49:34 +02:00
|
|
|
private lateinit var db: AppDatabase
|
|
|
|
private lateinit var context: Context
|
|
|
|
|
2020-04-17 15:07:04 +02:00
|
|
|
|
|
|
|
@get:Rule
|
|
|
|
var globalTimeout: Timeout = Timeout.seconds(30)
|
|
|
|
|
|
|
|
@Before
|
|
|
|
fun before(){
|
2020-11-08 20:24:38 +01:00
|
|
|
mockServer = MockServer()
|
2020-04-17 15:07:04 +02:00
|
|
|
mockServer.start()
|
|
|
|
val baseUrl = mockServer.getUrl()
|
2020-05-19 09:49:34 +02:00
|
|
|
|
|
|
|
context = ApplicationProvider.getApplicationContext()
|
2020-07-26 20:56:01 +02:00
|
|
|
db = initDB(context)
|
2020-05-19 09:49:34 +02:00
|
|
|
db.clearAllTables()
|
|
|
|
db.instanceDao().insertInstance(
|
|
|
|
InstanceDatabaseEntity(
|
|
|
|
uri = baseUrl.toString(),
|
|
|
|
title = "PixelTest"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
db.userDao().insertUser(
|
|
|
|
UserDatabaseEntity(
|
|
|
|
user_id = "123",
|
|
|
|
instance_uri = baseUrl.toString(),
|
|
|
|
username = "Testi",
|
|
|
|
display_name = "Testi Testo",
|
|
|
|
avatar_static = "some_avatar_url",
|
|
|
|
isActive = true,
|
|
|
|
accessToken = "token"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
db.close()
|
|
|
|
|
2020-04-17 15:07:04 +02:00
|
|
|
// Open Drawer to click on navigation.
|
|
|
|
ActivityScenario.launch(MainActivity::class.java)
|
|
|
|
onView(withId(R.id.drawer_layout))
|
2020-05-14 20:14:41 +02:00
|
|
|
.check(matches(DrawerMatchers.isClosed())) // Left Drawer should be closed.
|
2020-04-17 15:07:04 +02:00
|
|
|
.perform(DrawerActions.open()) // Open Drawer
|
|
|
|
}
|
|
|
|
|
2020-11-08 20:24:38 +01:00
|
|
|
@After
|
|
|
|
fun after() {
|
|
|
|
clearData()
|
|
|
|
mockServer.stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-04-17 15:07:04 +02:00
|
|
|
fun testDrawerSettingsButton() {
|
|
|
|
// Start the screen of your activity.
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText(R.string.menu_settings)).perform(click())
|
2020-04-17 15:07:04 +02:00
|
|
|
// Check that settings activity was opened.
|
2020-05-15 09:23:06 +02:00
|
|
|
onView(withText(R.string.theme_title)).check(matches(isDisplayed()))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testThemeSettings() {
|
|
|
|
// Start the screen of your activity.
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText(R.string.menu_settings)).perform(click())
|
2020-05-15 09:23:06 +02:00
|
|
|
val themes = getInstrumentation().targetContext.resources.getStringArray(R.array.theme_entries)
|
|
|
|
//select theme modes
|
|
|
|
onView(withText(R.string.theme_title)).perform(click())
|
|
|
|
onView(withText(themes[2])).perform(click())
|
|
|
|
|
|
|
|
//Select an other theme
|
|
|
|
onView(withText(R.string.theme_title)).perform(click())
|
|
|
|
onView(withText(themes[0])).perform(click())
|
|
|
|
|
|
|
|
//Select the last theme
|
|
|
|
onView(withText(R.string.theme_title)).perform(click())
|
|
|
|
onView(withText(themes[1])).perform(click())
|
|
|
|
|
|
|
|
//Check that we are back in the settings page
|
|
|
|
onView(withText(R.string.theme_header)).check(matches(isDisplayed()))
|
2020-04-17 15:07:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testDrawerLogoutButton() {
|
|
|
|
// Start the screen of your activity.
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText(R.string.logout)).perform(click())
|
2020-11-08 20:24:38 +01:00
|
|
|
// Check that login activity was opened.
|
|
|
|
onView(withId(R.id.mascotImage)).check(matches(isDisplayed()))
|
2020-04-17 15:07:04 +02:00
|
|
|
}
|
2020-05-01 11:26:18 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testDrawerProfileButton() {
|
|
|
|
// Start the screen of your activity.
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText(R.string.menu_account)).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
// Check that profile activity was opened.
|
|
|
|
onView(withId(R.id.profilePictureImageView)).check(matches(isDisplayed()))
|
|
|
|
}
|
|
|
|
|
2020-06-03 16:32:02 +02:00
|
|
|
@Test
|
|
|
|
fun testDrawerOwnProfileFollowers() {
|
2020-05-01 11:26:18 +02:00
|
|
|
// Start the screen of your activity.
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText(R.string.menu_account)).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
// Check that profile activity was opened.
|
2020-06-03 16:32:02 +02:00
|
|
|
onView(withId(R.id.editButton)).check(matches(isDisplayed()))
|
|
|
|
val followersText = context.getString(R.string.nb_followers)
|
|
|
|
.format(68)
|
|
|
|
onView(withText(followersText)).perform(click())
|
|
|
|
onView(withText("Dobios")).check(matches(isDisplayed()))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testDrawerOwnProfileFollowing() {
|
|
|
|
// Start the screen of your activity.
|
|
|
|
onView(withText(R.string.menu_account)).perform(click())
|
|
|
|
// Check that profile activity was opened.
|
|
|
|
onView(withId(R.id.editButton)).check(matches(isDisplayed()))
|
|
|
|
val followingText = context.getString(R.string.nb_following)
|
|
|
|
.format(27)
|
|
|
|
onView(withText(followingText)).perform(click())
|
|
|
|
onView(withText("Dobios")).check(matches(isDisplayed()))
|
|
|
|
}
|
2020-05-01 11:26:18 +02:00
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
/*@Test
|
2020-05-01 11:26:18 +02:00
|
|
|
fun testDrawerAccountNameClick() {
|
|
|
|
// Start the screen of your activity.
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText("Testi")).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
// Check that profile activity was opened.
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText("Add Account")).check(matches(isDisplayed()))
|
|
|
|
}*/
|
2020-05-01 11:26:18 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
fun clickFollowers() {
|
|
|
|
// Open My Profile from drawer
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText(R.string.menu_account)).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
Thread.sleep(1000)
|
|
|
|
|
|
|
|
// Open followers list
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withId(R.id.nbFollowersTextView)).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
Thread.sleep(1000)
|
|
|
|
// Open follower's profile
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText("ete2")).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
Thread.sleep(1000)
|
|
|
|
|
|
|
|
onView(withId(R.id.accountNameTextView)).check(matches(withText("Christian")))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun clickFollowing() {
|
|
|
|
// Open My Profile from drawer
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText(R.string.menu_account)).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
Thread.sleep(1000)
|
|
|
|
// Open followers list
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withId(R.id.nbFollowingTextView)).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
Thread.sleep(1000)
|
|
|
|
// Open following's profile
|
2020-05-19 09:49:34 +02:00
|
|
|
onView(withText("Dobios")).perform(click())
|
2020-05-01 11:26:18 +02:00
|
|
|
Thread.sleep(1000)
|
|
|
|
|
|
|
|
onView(withId(R.id.accountNameTextView)).check(matches(withText("Andrew Dobis")))
|
|
|
|
}
|
2020-05-14 20:14:41 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
fun onBackPressedClosesDrawer() {
|
|
|
|
UiDevice.getInstance(getInstrumentation()).pressBack()
|
|
|
|
Thread.sleep(1000)
|
|
|
|
onView(withId(R.id.drawer_layout)).check(matches(DrawerMatchers.isClosed()))
|
|
|
|
}
|
2020-04-17 15:07:04 +02:00
|
|
|
}
|