-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test cases using espresso to fill fields and to update data to fireba…
…se to verify VM
- Loading branch information
Malik Dawar
committed
Nov 6, 2019
1 parent
bc9e184
commit b3701e0
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
app/src/androidTest/java/com/dawar/sparknetwork/MainActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.dawar.sparknetwork | ||
|
||
import androidx.annotation.IdRes | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.action.ViewActions | ||
import androidx.test.espresso.matcher.RootMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.rule.ActivityTestRule | ||
import com.dawar.sparknetwork.models.User | ||
import com.dawar.sparknetwork.ui.main.MainActivity | ||
import org.hamcrest.Matchers | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class MainActivityTest { | ||
@Rule | ||
@JvmField | ||
val activityRule = ActivityTestRule(MainActivity::class.java) | ||
|
||
@Test | ||
fun testSubmitButton() { | ||
clickView(R.id.btnSubmit) | ||
|
||
|
||
} | ||
|
||
@Test | ||
fun testEmailField() { | ||
fillField(R.id.etEmail, "[email protected]") | ||
} | ||
|
||
@Test | ||
fun testNameField() { | ||
fillField(R.id.etName, "Malik Dawar") | ||
} | ||
|
||
@Test | ||
fun testPhoneField() { | ||
fillField(R.id.etPhone, "03217004140") | ||
} | ||
|
||
@Test | ||
fun testAddressField() { | ||
fillField(R.id.etAddress, "Lahore Pakistan") | ||
} | ||
|
||
@Test | ||
fun insertNewUser() { | ||
val mainActivity = activityRule.activity as MainActivity | ||
val user = User("Mobin").apply { | ||
address = "Lahore" | ||
email = "[email protected]" | ||
phone = "03217004104" | ||
} | ||
mainActivity.profileFragment.mProfileViewModel.saveProfile(user) | ||
|
||
} | ||
|
||
private fun fillField(@IdRes id: Int, text: String) { | ||
val mainActivity = activityRule.activity as MainActivity | ||
Espresso.onView(ViewMatchers.withId(id)) | ||
.inRoot(RootMatchers.withDecorView(Matchers.`is`(mainActivity.window.decorView))) | ||
.perform(ViewActions.typeText(text)) | ||
} | ||
|
||
private fun clickView(@IdRes id: Int) { | ||
val mainActivity = activityRule.activity as MainActivity | ||
Espresso.onView(ViewMatchers.withId(id)) | ||
.inRoot(RootMatchers.withDecorView(Matchers.`is`(mainActivity.window.decorView))) | ||
.perform(ViewActions.click()) | ||
} | ||
} |