Skip to content

Commit

Permalink
Merge pull request #2 from malikdawar/develop
Browse files Browse the repository at this point in the history
Test cases using espresso to fill fields and to update data to firebase to verify the VM and UI
  • Loading branch information
malikdawar authored Nov 6, 2019
2 parents a2c6acd + b3701e0 commit df2f790
Showing 1 changed file with 72 additions and 0 deletions.
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())
}
}

0 comments on commit df2f790

Please sign in to comment.