mirror of
https://github.com/hmalik144/Driver.git
synced 2026-03-18 15:36:03 +00:00
- mid commit
Took 8 hours 5 minutes
This commit is contained in:
@@ -1,16 +1,32 @@
|
||||
package h_mal.appttude.com.driver
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Instrumentation
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.provider.MediaStore
|
||||
import android.widget.DatePicker
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.test.espresso.Espresso.onData
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.ViewInteraction
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.action.ViewActions.swipeDown
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.contrib.PickerActions
|
||||
import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.espresso.intent.Intents.intending
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers.isInternal
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import org.hamcrest.CoreMatchers.allOf
|
||||
import org.hamcrest.CoreMatchers.anything
|
||||
import h_mal.appttude.com.driver.helpers.DataHelper
|
||||
import h_mal.appttude.com.driver.helpers.DataHelper.addFilePaths
|
||||
import org.hamcrest.CoreMatchers.*
|
||||
import org.hamcrest.Matchers
|
||||
import java.io.File
|
||||
|
||||
open class BaseTestRobot {
|
||||
|
||||
@@ -23,12 +39,12 @@ open class BaseTestRobot {
|
||||
fun clickButton(resId: Int): ViewInteraction =
|
||||
onView((withId(resId))).perform(ViewActions.click())
|
||||
|
||||
fun textView(resId: Int): ViewInteraction = onView(withId(resId))
|
||||
fun matchView(resId: Int): ViewInteraction = onView(withId(resId))
|
||||
|
||||
fun matchText(viewInteraction: ViewInteraction, text: String): ViewInteraction = viewInteraction
|
||||
.check(matches(ViewMatchers.withText(text)))
|
||||
|
||||
fun matchText(resId: Int, text: String): ViewInteraction = matchText(textView(resId), text)
|
||||
fun matchText(resId: Int, text: String): ViewInteraction = matchText(matchView(resId), text)
|
||||
|
||||
fun clickListItem(listRes: Int, position: Int) {
|
||||
onData(anything())
|
||||
@@ -39,7 +55,49 @@ open class BaseTestRobot {
|
||||
fun checkErrorOnTextEntry(resId: Int, errorMessage: String): ViewInteraction =
|
||||
onView(withId(resId)).check(matches(checkErrorMessage(errorMessage)))
|
||||
|
||||
fun swipeDown(resId: Int): ViewInteraction =
|
||||
onView(withId(resId)).perform(swipeDown())
|
||||
|
||||
fun getStringFromResource(@StringRes resId: Int): String =
|
||||
Resources.getSystem().getString(resId)
|
||||
|
||||
fun selectDateInPicker(year: Int, month: Int, day: Int) {
|
||||
onView(ViewMatchers.withClassName(Matchers.equalTo(DatePicker::class.java.name))).perform(
|
||||
PickerActions.setDate(
|
||||
year,
|
||||
month,
|
||||
day
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun selectSingleImageFromGallery(filePath: String, openSelector: () -> Unit) {
|
||||
Intents.init()
|
||||
// Build the result to return when the activity is launched.
|
||||
val resultData = Intent()
|
||||
resultData.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
resultData.data = Uri.fromFile(File(filePath))
|
||||
val result = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData)
|
||||
// Set up result stubbing when an intent sent to image picker is seen.
|
||||
intending(hasAction(Intent.ACTION_GET_CONTENT)).respondWith(result)
|
||||
|
||||
openSelector()
|
||||
Intents.release()
|
||||
}
|
||||
|
||||
fun selectMultipleImageFromGallery(filePaths: Array<String>, openSelector: () -> Unit) {
|
||||
Intents.init()
|
||||
openSelector()
|
||||
// Build the result to return when the activity is launched.
|
||||
val resultData = Intent()
|
||||
val clipData = DataHelper.createClipData(filePaths[0])
|
||||
val remainingFiles = filePaths.copyOfRange(1, filePaths.size-1)
|
||||
clipData.addFilePaths(remainingFiles)
|
||||
resultData.clipData = clipData
|
||||
val result = Instrumentation.ActivityResult(Activity.RESULT_OK, resultData)
|
||||
|
||||
// Set up result stubbing when an intent sent to "contacts" is seen.
|
||||
Intents.intending(IntentMatchers.toPackage("android.intent.action.PICK")).respondWith(result)
|
||||
Intents.release()
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ open class BaseUiTest<T : BaseActivity<*,*>>(
|
||||
mActivityScenarioRule.onActivity {
|
||||
mIdlingResource = it.getIdlingResource()!!
|
||||
IdlingRegistry.getInstance().register(mIdlingResource)
|
||||
afterLaunch()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +58,5 @@ open class BaseUiTest<T : BaseActivity<*,*>>(
|
||||
}
|
||||
|
||||
open fun beforeLaunch() {}
|
||||
open fun afterLaunch() {}
|
||||
}
|
||||
@@ -1,21 +1,27 @@
|
||||
package h_mal.appttude.com.driver
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsRule
|
||||
import com.google.firebase.auth.FirebaseAuth
|
||||
import com.google.firebase.database.FirebaseDatabase
|
||||
import com.google.firebase.storage.FirebaseStorage
|
||||
import h_mal.appttude.com.driver.base.BaseActivity
|
||||
import h_mal.appttude.com.driver.data.FirebaseAuthSource
|
||||
import h_mal.appttude.com.driver.utils.GenericsHelper.getGenericClassAt
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.tasks.await
|
||||
import org.junit.After
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Rule
|
||||
|
||||
open class FirebaseTest<T : BaseActivity<*,*>>(
|
||||
open class FirebaseTest<T : BaseActivity<*, *>>(
|
||||
activity: Class<T>,
|
||||
private val registered: Boolean = false,
|
||||
private val signedIn: Boolean = false
|
||||
) : BaseUiTest<T>(activity) {
|
||||
|
||||
// @get:Rule
|
||||
// val intentsRule = IntentsRule()
|
||||
|
||||
private val firebaseAuthSource by lazy { FirebaseAuthSource() }
|
||||
|
||||
private var email: String? = null
|
||||
|
||||
@@ -1,6 +1,30 @@
|
||||
package h_mal.appttude.com.driver
|
||||
|
||||
class FormRobot: BaseTestRobot() {
|
||||
import android.net.Uri
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
|
||||
// fun selectImage
|
||||
|
||||
open class FormRobot : BaseTestRobot() {
|
||||
fun submit() = clickButton(R.id.submit)
|
||||
fun setDate(datePickerLaunchViewId: Int, year: Int, monthOfYear: Int, dayOfMonth: Int) {
|
||||
onView(withId(datePickerLaunchViewId)).perform(click())
|
||||
selectDateInPicker(year, monthOfYear, dayOfMonth)
|
||||
// click ok in date picker
|
||||
onView(withId(android.R.id.button1)).perform(click())
|
||||
}
|
||||
|
||||
fun selectSingleImage(imagePickerLauncherViewId: Int, filePath: String) {
|
||||
selectSingleImageFromGallery(filePath) {
|
||||
onView(withId(imagePickerLauncherViewId)).perform(click())
|
||||
}
|
||||
// click ok in date picker
|
||||
}
|
||||
|
||||
fun selectMultipleImage(imagePickerLauncherViewId: Int, filePaths: Array<String>) {
|
||||
selectMultipleImageFromGallery(filePaths) {
|
||||
onView(withId(imagePickerLauncherViewId)).perform(click())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package h_mal.appttude.com.driver.helpers
|
||||
|
||||
import android.os.Environment
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* File paths for images on device
|
||||
*/
|
||||
private const val BASE = "/Camera/images/"
|
||||
const val PROFILE_PIC = "${BASE}driver_profile_pic.jpg"
|
||||
const val INSURANCE = "${BASE}driver_insurance.jpg"
|
||||
const val PRIVATE_HIRE = "${BASE}driver_license_private_hire.jpg"
|
||||
const val PRIVATE_HIRE_CAR = "${BASE}driver_license_private_hire_car.jpg"
|
||||
const val LOGBOOK = "${BASE}driver_logbook.jpg"
|
||||
const val MOT = "${BASE}driver_mot.jpg"
|
||||
const val LICENSE = "${BASE}driver_license_driver.jpg"
|
||||
|
||||
fun getImagePath(imageConst: String): String {
|
||||
return File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), imageConst).absolutePath
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package h_mal.appttude.com.driver.helpers
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipData.Item
|
||||
import android.content.ClipDescription
|
||||
import android.net.Uri
|
||||
import java.io.File
|
||||
|
||||
object DataHelper {
|
||||
|
||||
fun createClipItem(filePath: String) = Item(
|
||||
Uri.fromFile(File(filePath)
|
||||
))
|
||||
|
||||
fun createClipData(item: Item, mimeType: String = "text/uri-list") = ClipData(null, arrayOf(mimeType), item)
|
||||
|
||||
fun createClipData(filePath: String) = createClipData(createClipItem(filePath))
|
||||
|
||||
fun createClipData(uri: Uri) = createClipData(Item(uri))
|
||||
|
||||
fun ClipData.addFilePaths(filePaths: Array<String>) {
|
||||
filePaths.forEach { addItem(createClipItem(it)) }
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,17 @@ class RegisterRobot : BaseTestRobot() {
|
||||
|
||||
fun setName(name: String) = fillEditText(R.id.name_register, name)
|
||||
|
||||
fun setEmail(email: String) = fillEditText(R.id.email_register, email)
|
||||
fun setEmail(email: String) = fillEditText(R.id.email, email)
|
||||
|
||||
fun setPassword(pass: String) = fillEditText(R.id.password_top, pass)
|
||||
|
||||
fun setPasswordConfirm(pass: String) = fillEditText(R.id.password_bottom, pass)
|
||||
|
||||
fun clickLogin() = clickButton(R.id.email_sign_up)
|
||||
fun clickLogin() = clickButton(R.id.submit)
|
||||
|
||||
fun checkNameError(err: String) = checkErrorOnTextEntry(R.id.name_register, err)
|
||||
|
||||
fun checkEmailError(err: String) = checkErrorOnTextEntry(R.id.email_register, err)
|
||||
fun checkEmailError(err: String) = checkErrorOnTextEntry(R.id.email, err)
|
||||
|
||||
fun checkPasswordError(err: String) = checkErrorOnTextEntry(R.id.password_top, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user