diff --git a/app/build.gradle b/app/build.gradle index 097de61..4a43c3f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -122,6 +122,7 @@ dependencies { implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion" androidTestImplementation "androidx.test:runner:$testRunnerVersion" androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion" + androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion" / * Google play services */ implementation "com.google.android.gms:play-services-auth:20.4.1" / * Google firebase */ diff --git a/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/InsuranceFragment.kt b/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/InsuranceFragment.kt index 1a107b4..12cf1f4 100644 --- a/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/InsuranceFragment.kt +++ b/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/InsuranceFragment.kt @@ -14,7 +14,7 @@ class InsuranceFragment : override fun setupView(binding: FragmentInsuranceBinding) { super.setupView(binding) - viewsToHide(binding.submitIns, binding.uploadInsurance) + viewsToHide(binding.submit, binding.uploadInsurance) } diff --git a/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/LogbookFragment.kt b/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/LogbookFragment.kt index 70a1b62..679ddb9 100644 --- a/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/LogbookFragment.kt +++ b/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/LogbookFragment.kt @@ -12,7 +12,7 @@ class LogbookFragment : override fun setupView(binding: FragmentLogbookBinding) { super.setupView(binding) - viewsToHide(binding.submitLb, binding.uploadLb) + viewsToHide(binding.submit, binding.uploadLb) } override fun setFields(data: Logbook) { diff --git a/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/MotFragment.kt b/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/MotFragment.kt index cc097e7..1c0a744 100644 --- a/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/MotFragment.kt +++ b/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/MotFragment.kt @@ -11,7 +11,7 @@ class MotFragment : DataViewerFragment() override fun setupView(binding: FragmentMotBinding) { super.setupView(binding) - viewsToHide(binding.submitMot, binding.uploadmot) + viewsToHide(binding.submit, binding.uploadmot) } override fun setFields(data: Mot) { diff --git a/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/VehicleProfileFragment.kt b/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/VehicleProfileFragment.kt index 42bcc6d..e5d3218 100644 --- a/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/VehicleProfileFragment.kt +++ b/app/src/admin/java/h_mal/appttude/com/driver/ui/vehicleprofile/VehicleProfileFragment.kt @@ -11,7 +11,7 @@ class VehicleProfileFragment : override fun setupView(binding: FragmentVehicleSetupBinding) { super.setupView(binding) - viewsToHide(binding.submitVehicle) + viewsToHide(binding.submit) } override fun setFields(data: VehicleProfile) { diff --git a/app/src/androidTest/java/h_mal/appttude/com/driver/BaseTestRobot.kt b/app/src/androidTest/java/h_mal/appttude/com/driver/BaseTestRobot.kt index 0da5e65..ab2e814 100644 --- a/app/src/androidTest/java/h_mal/appttude/com/driver/BaseTestRobot.kt +++ b/app/src/androidTest/java/h_mal/appttude/com/driver/BaseTestRobot.kt @@ -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, 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() + } } \ No newline at end of file diff --git a/app/src/androidTest/java/h_mal/appttude/com/driver/BaseUiTest.kt b/app/src/androidTest/java/h_mal/appttude/com/driver/BaseUiTest.kt index cc9e4fb..23d3f28 100644 --- a/app/src/androidTest/java/h_mal/appttude/com/driver/BaseUiTest.kt +++ b/app/src/androidTest/java/h_mal/appttude/com/driver/BaseUiTest.kt @@ -30,6 +30,7 @@ open class BaseUiTest>( mActivityScenarioRule.onActivity { mIdlingResource = it.getIdlingResource()!! IdlingRegistry.getInstance().register(mIdlingResource) + afterLaunch() } } @@ -57,4 +58,5 @@ open class BaseUiTest>( } open fun beforeLaunch() {} + open fun afterLaunch() {} } \ No newline at end of file diff --git a/app/src/androidTest/java/h_mal/appttude/com/driver/FirebaseTest.kt b/app/src/androidTest/java/h_mal/appttude/com/driver/FirebaseTest.kt index 00302cc..c495678 100644 --- a/app/src/androidTest/java/h_mal/appttude/com/driver/FirebaseTest.kt +++ b/app/src/androidTest/java/h_mal/appttude/com/driver/FirebaseTest.kt @@ -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>( +open class FirebaseTest>( activity: Class, private val registered: Boolean = false, private val signedIn: Boolean = false ) : BaseUiTest(activity) { +// @get:Rule +// val intentsRule = IntentsRule() + private val firebaseAuthSource by lazy { FirebaseAuthSource() } private var email: String? = null diff --git a/app/src/androidTest/java/h_mal/appttude/com/driver/FormRobot.kt b/app/src/androidTest/java/h_mal/appttude/com/driver/FormRobot.kt index 106375d..9869d93 100644 --- a/app/src/androidTest/java/h_mal/appttude/com/driver/FormRobot.kt +++ b/app/src/androidTest/java/h_mal/appttude/com/driver/FormRobot.kt @@ -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) { + selectMultipleImageFromGallery(filePaths) { + onView(withId(imagePickerLauncherViewId)).perform(click()) + } + } } \ No newline at end of file diff --git a/app/src/androidTest/java/h_mal/appttude/com/driver/helpers/Constants.kt b/app/src/androidTest/java/h_mal/appttude/com/driver/helpers/Constants.kt new file mode 100644 index 0000000..8f418cf --- /dev/null +++ b/app/src/androidTest/java/h_mal/appttude/com/driver/helpers/Constants.kt @@ -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 +} \ No newline at end of file diff --git a/app/src/androidTest/java/h_mal/appttude/com/driver/helpers/DataHelper.kt b/app/src/androidTest/java/h_mal/appttude/com/driver/helpers/DataHelper.kt new file mode 100644 index 0000000..5543c12 --- /dev/null +++ b/app/src/androidTest/java/h_mal/appttude/com/driver/helpers/DataHelper.kt @@ -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) { + filePaths.forEach { addItem(createClipItem(it)) } + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/h_mal/appttude/com/driver/robots/RegisterRobot.kt b/app/src/androidTest/java/h_mal/appttude/com/driver/robots/RegisterRobot.kt index d0bced1..b334357 100644 --- a/app/src/androidTest/java/h_mal/appttude/com/driver/robots/RegisterRobot.kt +++ b/app/src/androidTest/java/h_mal/appttude/com/driver/robots/RegisterRobot.kt @@ -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) diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DeleteRobot.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DeleteRobot.kt index 4391eb6..9df821e 100644 --- a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DeleteRobot.kt +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DeleteRobot.kt @@ -1,18 +1,17 @@ package h_mal.appttude.com.driver.robots -import h_mal.appttude.com.driver.BaseTestRobot +import h_mal.appttude.com.driver.FormRobot import h_mal.appttude.com.driver.R fun delete(func: DeleteRobot.() -> Unit) = DeleteRobot().apply { func() } -class DeleteRobot : BaseTestRobot() { +class DeleteRobot : FormRobot() { fun enterEmail(email: String) = fillEditText(R.id.email_update, email) fun enterPassword(password: String) = fillEditText(R.id.password_top, password) - fun submitDelete() = clickButton(R.id.submission_button_label) fun submitForm(email: String, password: String) { enterEmail(email) enterPassword(password) - submitDelete() + submit() } } \ No newline at end of file diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DriversLicenseRobot.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DriversLicenseRobot.kt index 044add4..95246db 100644 --- a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DriversLicenseRobot.kt +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DriversLicenseRobot.kt @@ -1,21 +1,21 @@ package h_mal.appttude.com.driver.robots -import h_mal.appttude.com.driver.BaseTestRobot +import h_mal.appttude.com.driver.FormRobot import h_mal.appttude.com.driver.R +import h_mal.appttude.com.driver.helpers.LICENSE +import h_mal.appttude.com.driver.helpers.getImagePath fun driversLicense(func: DriversLicenseRobot.() -> Unit) = DriversLicenseRobot().apply { func() } -class DriversLicenseRobot : BaseTestRobot() { +class DriversLicenseRobot : FormRobot() { fun enterLicenseNumber(text: String) = fillEditText(R.id.lic_no, text) - fun enterLicenseExpiry(text: String) = fillEditText(R.id.lic_expiry, text) - fun selectImage() = clickButton(R.id.search_image) - fun clickSubmit() = clickButton(R.id.submit) + fun enterLicenseExpiry(year: Int, monthOfYear: Int, dayOfMonth: Int) = setDate(R.id.lic_expiry, year, monthOfYear, dayOfMonth) + fun selectImage() = selectSingleImage(R.id.search_image, getImagePath(LICENSE)) - fun submitForm(licenseNumber: String, licenseExpiry: String) { + fun submitForm(licenseNumber: String, year: Int, monthOfYear: Int, dayOfMonth: Int) { selectImage() - // TODO: select image in gallery enterLicenseNumber(licenseNumber) - enterLicenseExpiry(licenseExpiry) - clickSubmit() + enterLicenseExpiry(year, monthOfYear, dayOfMonth) + submit() } } \ No newline at end of file diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DriversProfileRobot.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DriversProfileRobot.kt index cb14338..313f96b 100644 --- a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DriversProfileRobot.kt +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/DriversProfileRobot.kt @@ -1,21 +1,26 @@ package h_mal.appttude.com.driver.robots -import h_mal.appttude.com.driver.BaseTestRobot +import android.text.InputType +import h_mal.appttude.com.driver.FormRobot import h_mal.appttude.com.driver.R fun driversProfile(func: DriversProfileRobot.() -> Unit) = DriversProfileRobot().apply { func() } -class DriversProfileRobot : BaseTestRobot() { +class DriversProfileRobot : FormRobot() { + + fun enterName(name: String) = fillEditText(R.id.names_input, name) + fun enterAddress(address: String) = fillEditText(R.id.address_input, address) + fun enterPostcode(postcode: String) = fillEditText(R.id.postcode_input, postcode) + fun enterDateOfBirth(dob: String) = fillEditText(R.id.dob_input, dob) + fun enterNINumber(niNumber: String) = fillEditText(R.id.ni_number, niNumber) + fun enterDateFirstAvailable(year: Int, monthOfYear: Int, dayOfMonth: Int) = setDate(R.id.date_first, year, monthOfYear, dayOfMonth) - fun enterLicenseNumber(text: String) = fillEditText(R.id.lic_no, text) - fun enterLicenseExpiry(text: String) = fillEditText(R.id.lic_expiry, text) fun selectImage() = clickButton(R.id.add_photo) - fun clickSubmit() = clickButton(R.id.submit_driver) - fun submitForm(licenseNumber: String, licenseExpiry: String) { + fun submitForm(name: String, address: String, postcode: String, dob: String, niNumber: String, year: Int, monthOfYear: Int, dayOfMonth: Int) { selectImage() // TODO: select image in gallery - enterLicenseNumber(licenseNumber) - enterLicenseExpiry(licenseExpiry) - clickSubmit() + enterName(name) + enterAddress(address) + submit() } } \ No newline at end of file diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/HomeRobot.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/HomeRobot.kt index 29318a3..618308f 100644 --- a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/HomeRobot.kt +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/HomeRobot.kt @@ -27,4 +27,5 @@ class HomeRobot : BaseTestRobot() { fun openDriverProfile() = clickButton(R.id.driver) fun openVehicleProfile() = clickButton(R.id.car) + fun requestProfile() = clickButton(R.id.request_driver_button) } \ No newline at end of file diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateEmailRobot.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateEmailRobot.kt index b6dcff8..5170234 100644 --- a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateEmailRobot.kt +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateEmailRobot.kt @@ -1,22 +1,19 @@ -@file:JvmName("UpdateEmailRobotKt") - package h_mal.appttude.com.driver.robots -import h_mal.appttude.com.driver.BaseTestRobot +import h_mal.appttude.com.driver.FormRobot import h_mal.appttude.com.driver.R fun updateEmail(func: UpdateEmailRobot.() -> Unit) = UpdateEmailRobot().apply { func() } -class UpdateEmailRobot : BaseTestRobot() { +class UpdateEmailRobot : FormRobot() { fun enterEmail(email: String) = fillEditText(R.id.email_update, email) fun enterPassword(password: String) = fillEditText(R.id.password_top, password) fun enterNewEmail(email: String) = fillEditText(R.id.new_email, email) - fun submitDelete() = clickButton(R.id.submission_button_label) fun submitForm(email: String, password: String, newEmail: String) { enterEmail(email) enterPassword(password) enterNewEmail(newEmail) - submitDelete() + submit() } } \ No newline at end of file diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdatePasswordRobot.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdatePasswordRobot.kt index 0247f3a..b3b44f0 100644 --- a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdatePasswordRobot.kt +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdatePasswordRobot.kt @@ -1,20 +1,20 @@ package h_mal.appttude.com.driver.robots -import h_mal.appttude.com.driver.BaseTestRobot +import h_mal.appttude.com.driver.FormRobot import h_mal.appttude.com.driver.R fun updatePassword(func: UpdatePasswordRobot.() -> Unit) = UpdatePasswordRobot().apply { func() } -class UpdatePasswordRobot : BaseTestRobot() { +class UpdatePasswordRobot : FormRobot() { fun enterEmail(email: String) = fillEditText(R.id.email_update, email) fun enterPassword(password: String) = fillEditText(R.id.password_top, password) fun enterNewPassword(email: String) = fillEditText(R.id.password_bottom, email) - fun submitDelete() = clickButton(R.id.email_sign_up) + fun submitDelete() = clickButton(R.id.submit) fun submitForm(email: String, password: String, newPassword: String) { enterEmail(email) enterPassword(password) enterNewPassword(newPassword) - submitDelete() + submit() } } \ No newline at end of file diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateProfileRobot.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateProfileRobot.kt index 6e175af..f739153 100644 --- a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateProfileRobot.kt +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateProfileRobot.kt @@ -1,19 +1,18 @@ package h_mal.appttude.com.driver.robots -import h_mal.appttude.com.driver.BaseTestRobot +import h_mal.appttude.com.driver.FormRobot import h_mal.appttude.com.driver.R +import h_mal.appttude.com.driver.helpers.PROFILE_PIC fun updateProfile(func: UpdateProfileRobot.() -> Unit) = UpdateProfileRobot().apply { func() } -class UpdateProfileRobot : BaseTestRobot() { +class UpdateProfileRobot : FormRobot() { fun enterName(name: String) = fillEditText(R.id.update_name, name) - fun selectImage() = clickButton(R.id.profile_img) - fun submitProfileUpdate() = clickButton(R.id.submit_update_profile) +// fun selectImage() = selectSingleImage(R.id.profile_img, PROFILE_PIC) fun submitForm(name: String) { - selectImage() - // TODO: select image in gallery +// selectImage() enterName(name) - submitProfileUpdate() + submit() } } \ No newline at end of file diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateRobot.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateRobot.kt index 3a11686..7ddd3fb 100644 --- a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateRobot.kt +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/robots/UpdateRobot.kt @@ -1,8 +1,5 @@ package h_mal.appttude.com.driver.robots -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.contrib.DrawerActions -import androidx.test.espresso.matcher.ViewMatchers.withId import h_mal.appttude.com.driver.BaseTestRobot import h_mal.appttude.com.driver.R diff --git a/app/src/androidTestDriver/java/h_mal/appttude/com/driver/tests/newUser/SubmitNewDataActivityTest.kt b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/tests/newUser/SubmitNewDataActivityTest.kt new file mode 100644 index 0000000..0fb74bd --- /dev/null +++ b/app/src/androidTestDriver/java/h_mal/appttude/com/driver/tests/newUser/SubmitNewDataActivityTest.kt @@ -0,0 +1,41 @@ +package h_mal.appttude.com.driver.tests.newUser + + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import androidx.test.rule.GrantPermissionRule +import h_mal.appttude.com.driver.FirebaseTest +import h_mal.appttude.com.driver.R +import h_mal.appttude.com.driver.robots.* +import h_mal.appttude.com.driver.ui.MainActivity +import h_mal.appttude.com.driver.ui.user.LoginActivity +import org.junit.* +import org.junit.runner.RunWith + + +@LargeTest +@RunWith(AndroidJUnit4::class) +class SubmitNewDataActivityTest : + FirebaseTest(MainActivity::class.java, registered = true, signedIn = true) { + + @get:Rule var permissionRule = GrantPermissionRule.grant(android.Manifest.permission.READ_EXTERNAL_STORAGE) + + @Test + fun verifyUserRegistration_validUsernameAndPassword_loggedIn() { + home { + waitFor(2500) + checkTitleExists(getResourceString(R.string.welcome_title)) + requestProfile() + openDriverProfile() + } + driverScreen { + + driverLicense() + } + driversLicense { + submitForm("SAMPLE8456310LTU", 2022, 10, 2) + } + waitFor(5000) + } + +} diff --git a/app/src/driver/java/h_mal/appttude/com/driver/ui/driverprofile/DriverProfileFragment.kt b/app/src/driver/java/h_mal/appttude/com/driver/ui/driverprofile/DriverProfileFragment.kt index 91b0022..9bf7614 100644 --- a/app/src/driver/java/h_mal/appttude/com/driver/ui/driverprofile/DriverProfileFragment.kt +++ b/app/src/driver/java/h_mal/appttude/com/driver/ui/driverprofile/DriverProfileFragment.kt @@ -37,7 +37,7 @@ class DriverProfileFragment : } } addPhoto.setOnClickListener { openGalleryWithPermissionRequest() } - submitDriver.setOnClickListener { submit() } + submit.setOnClickListener { submit() } } override fun submit() { diff --git a/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/InsuranceFragment.kt b/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/InsuranceFragment.kt index 2f304b1..535fd10 100644 --- a/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/InsuranceFragment.kt +++ b/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/InsuranceFragment.kt @@ -34,7 +34,7 @@ class InsuranceFragment : } } uploadInsurance.setOnClickListener { openGalleryWithPermissionRequest() } - submitIns.setOnClickListener { submit() } + submit.setOnClickListener { submit() } } } diff --git a/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/LogbookFragment.kt b/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/LogbookFragment.kt index fc37aa9..be5afe7 100644 --- a/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/LogbookFragment.kt +++ b/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/LogbookFragment.kt @@ -17,7 +17,7 @@ class LogbookFragment : override fun setupView(binding: FragmentLogbookBinding) = binding.run { v5cNo.setTextOnChange { model.v5cnumber = it } uploadLb.setOnClickListener { openGalleryWithPermissionRequest() } - submitLb.setOnClickListener { submit() } + submit.setOnClickListener { submit() } } override fun submit() { diff --git a/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/MotFragment.kt b/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/MotFragment.kt index 8aed6be..f129729 100644 --- a/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/MotFragment.kt +++ b/app/src/driver/java/h_mal/appttude/com/driver/ui/vehicleprofile/MotFragment.kt @@ -24,7 +24,7 @@ class MotFragment : DataSubmissionBaseFragment model.isSeized = res } - submitVehicle.setOnClickListener { + submit.setOnClickListener { validateEditTexts( reg, make, diff --git a/app/src/main/java/h_mal/appttude/com/driver/application/DriverApplication.kt b/app/src/main/java/h_mal/appttude/com/driver/application/DriverApplication.kt index f8393ef..844e73e 100644 --- a/app/src/main/java/h_mal/appttude/com/driver/application/DriverApplication.kt +++ b/app/src/main/java/h_mal/appttude/com/driver/application/DriverApplication.kt @@ -18,15 +18,15 @@ import org.kodein.di.generic.singleton class DriverApplication : Application(), KodeinAware { - override fun onCreate() { - super.onCreate() - - val localHost = "10.0.2.2" - - FirebaseAuth.getInstance().useEmulator(localHost, 9099) - FirebaseDatabase.getInstance().useEmulator(localHost, 9000) - FirebaseStorage.getInstance().useEmulator(localHost, 9199) - } +// override fun onCreate() { +// super.onCreate() +// +// val localHost = "10.0.2.2" +// +// FirebaseAuth.getInstance().useEmulator(localHost, 9099) +// FirebaseDatabase.getInstance().useEmulator(localHost, 9000) +// FirebaseStorage.getInstance().useEmulator(localHost, 9199) +// } // Kodein aware to initialise the classes used for DI override val kodein = Kodein.lazy { diff --git a/app/src/main/java/h_mal/appttude/com/driver/base/BaseFragment.kt b/app/src/main/java/h_mal/appttude/com/driver/base/BaseFragment.kt index 9f13118..ba1d5b6 100644 --- a/app/src/main/java/h_mal/appttude/com/driver/base/BaseFragment.kt +++ b/app/src/main/java/h_mal/appttude/com/driver/base/BaseFragment.kt @@ -20,6 +20,7 @@ import h_mal.appttude.com.driver.utils.PermissionsUtils import org.kodein.di.KodeinAware import org.kodein.di.android.x.kodein import org.kodein.di.generic.instance +import java.io.File abstract class BaseFragment : Fragment(), KodeinAware { @@ -151,10 +152,10 @@ abstract class BaseFragment : Fragment(), K private fun getResultsContract(): ActivityResultContract { return object : ActivityResultContract() { override fun createIntent(context: Context, input: Boolean): Intent { - return Intent(Intent.ACTION_PICK).apply { - type = "image/*" - putExtra(Intent.EXTRA_ALLOW_MULTIPLE, input) - } + return Intent(Intent.ACTION_GET_CONTENT) + .addCategory(Intent.CATEGORY_OPENABLE) + .putExtra(Intent.EXTRA_ALLOW_MULTIPLE, input) + .setType("image/*") } override fun parseResult(resultCode: Int, intent: Intent?): Any? { diff --git a/app/src/main/java/h_mal/appttude/com/driver/ui/update/DeleteProfileFragment.kt b/app/src/main/java/h_mal/appttude/com/driver/ui/update/DeleteProfileFragment.kt index 1402ff2..2015bf7 100644 --- a/app/src/main/java/h_mal/appttude/com/driver/ui/update/DeleteProfileFragment.kt +++ b/app/src/main/java/h_mal/appttude/com/driver/ui/update/DeleteProfileFragment.kt @@ -12,7 +12,7 @@ class DeleteProfileFragment : override fun setupView(binding: FragmentDeleteProfileBinding) = binding.run { passwordTop.setEnterPressedListener { deleteUser() } - submissionButtonLabel.setOnClickListener { deleteUser() } + submit.setOnClickListener { deleteUser() } } private fun deleteUser() = applyBinding { diff --git a/app/src/main/java/h_mal/appttude/com/driver/ui/update/UpdateEmailFragment.kt b/app/src/main/java/h_mal/appttude/com/driver/ui/update/UpdateEmailFragment.kt index c0e1ef2..fe7e051 100644 --- a/app/src/main/java/h_mal/appttude/com/driver/ui/update/UpdateEmailFragment.kt +++ b/app/src/main/java/h_mal/appttude/com/driver/ui/update/UpdateEmailFragment.kt @@ -12,7 +12,7 @@ class UpdateEmailFragment : BaseFragment + app:layout_constraintTop_toBottomOf="@+id/til_name"> diff --git a/app/src/main/res/layout/fragment_insurance.xml b/app/src/main/res/layout/fragment_insurance.xml index 8dfe371..ffa2b0c 100644 --- a/app/src/main/res/layout/fragment_insurance.xml +++ b/app/src/main/res/layout/fragment_insurance.xml @@ -67,7 +67,7 @@ - + app:layout_constraintTop_toBottomOf="@id/til_new_password" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.8" /> + + + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintBottom_toTopOf="@id/til_email"> + android:autofillHints="name"/> - + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toBottomOf="@+id/til_name"> - - + app:layout_constraintTop_toBottomOf="@+id/til_new_password"> - - - - - diff --git a/app/src/main/res/layout/fragment_update_email.xml b/app/src/main/res/layout/fragment_update_email.xml index 55153aa..9c57b47 100644 --- a/app/src/main/res/layout/fragment_update_email.xml +++ b/app/src/main/res/layout/fragment_update_email.xml @@ -23,14 +23,14 @@ android:text="@string/update_email_subtitle" style="@style/subheader" android:layout_marginBottom="24dp" - app:layout_constraintBottom_toTopOf="@id/til_old_email" + app:layout_constraintBottom_toTopOf="@id/til_name" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" /> + tools:context="ui.update.UpdatePasswordFragment"> + app:layout_constraintTop_toBottomOf="@+id/til_name"> + tools:context=".ui.update.UpdateProfileFragment"> -