88 lines
3.0 KiB
Kotlin
88 lines
3.0 KiB
Kotlin
|
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.*
|
||
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||
|
import androidx.test.espresso.intent.Intents.intended
|
||
|
import androidx.test.espresso.intent.Intents.intending
|
||
|
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
|
||
|
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
|
||
|
import androidx.test.rule.GrantPermissionRule
|
||
|
import com.h.pixeldroid.testUtility.MockServer
|
||
|
import kotlinx.android.synthetic.main.activity_main.*
|
||
|
import org.hamcrest.Matcher
|
||
|
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 PostCreationFragmentTest {
|
||
|
|
||
|
@get:Rule
|
||
|
var globalTimeout: Timeout = Timeout.seconds(30)
|
||
|
@get:Rule
|
||
|
var runtimePermissionRule: GrantPermissionRule =
|
||
|
GrantPermissionRule.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||
|
@get:Rule
|
||
|
var intentsTestRule: IntentsTestRule<MainActivity> =
|
||
|
IntentsTestRule(MainActivity::class.java)
|
||
|
|
||
|
@Before
|
||
|
fun setup() {
|
||
|
onView(withId(R.id.main_activity_main_linear_layout))
|
||
|
.perform(swipeLeft())
|
||
|
.perform(swipeLeft())
|
||
|
Thread.sleep(300)
|
||
|
}
|
||
|
|
||
|
// upload intent
|
||
|
@Test
|
||
|
fun uploadButtonLaunchesGalleryIntent() {
|
||
|
val expectedIntent: Matcher<Intent> = hasAction(Intent.ACTION_CHOOSER)
|
||
|
intending(expectedIntent)
|
||
|
onView(withId(R.id.uploadPictureButton)).perform(click())
|
||
|
Thread.sleep(1000)
|
||
|
intended(expectedIntent)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@RunWith(AndroidJUnit4::class)
|
||
|
class PostFragmentUITests {
|
||
|
private val mockServer = MockServer()
|
||
|
|
||
|
@get:Rule
|
||
|
var globalTimeout: Timeout = Timeout.seconds(30)
|
||
|
@get:Rule
|
||
|
var rule = ActivityScenarioRule(MainActivity::class.java)
|
||
|
|
||
|
@Before
|
||
|
fun setup() {
|
||
|
mockServer.start()
|
||
|
val baseUrl = mockServer.getUrl()
|
||
|
val preferences = InstrumentationRegistry.getInstrumentation()
|
||
|
.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).onActivity {
|
||
|
a -> a.tabs.getTabAt(2)!!.select()
|
||
|
}
|
||
|
Thread.sleep(300)
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
fun newPostUiTest() {
|
||
|
onView(withId(R.id.uploadPictureButton)).check(matches(isDisplayed()))
|
||
|
onView(withId(R.id.takePictureButton)).check(matches(isDisplayed()))
|
||
|
}
|
||
|
}
|