Skip to content

Commit

Permalink
Merge branch 'develop' into CU16-TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
vggm committed Dec 14, 2023
2 parents ee6ae11 + 81ec092 commit 32ca628
Show file tree
Hide file tree
Showing 24 changed files with 3,459 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ android {
dependencies {


testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
val room_version = "2.5.0"

implementation("androidx.preference:preference-ktx:1.2.1")
Expand Down Expand Up @@ -75,7 +76,7 @@ dependencies {
androidTestImplementation("androidx.navigation:navigation-testing:$nav_version")

// Jetpack Compose Integration
implementation("androidx.navigation:navigation-compose:$nav_version")
//implementation("androidx.navigation:navigation-compose:$nav_version")

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
Expand All @@ -96,4 +97,18 @@ dependencies {
implementation("org.apache.poi:poi:5.1.0")
implementation("org.apache.poi:poi-ooxml:5.1.0")

testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito:mockito-core:4.6.1")
testImplementation("org.mockito:mockito-junit-jupiter:4.6.1")
testImplementation("com.squareup.okhttp3:mockwebserver:4.9.1")
androidTestImplementation("androidx.test.ext:junit:1.1.5")

// Espresso dependencies
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test:runner:1.5.1")
androidTestImplementation("androidx.test:rules:1.5.0")

//import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
androidTestImplementation("androidx.test.espresso:espresso-contrib:3.5.1")

}
229 changes: 229 additions & 0 deletions app/src/androidTest/java/es/unex/giis/asee/gepeto/view/TestCU01.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
package es.unex.giis.asee.gepeto.view


import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import es.unex.giis.asee.gepeto.R
import es.unex.giis.asee.gepeto.database.GepetoDatabase
import es.unex.giis.asee.gepeto.database.dao.UserDao
import es.unex.giis.asee.gepeto.model.User
import kotlinx.coroutines.runBlocking
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.`is`
import org.hamcrest.TypeSafeMatcher
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class TestCU01 {

@Rule
@JvmField
var mActivityScenarioRule = ActivityScenarioRule(LoginActivity::class.java)

private lateinit var volatileDB: GepetoDatabase
private lateinit var userDAO: UserDao

// Se ejecuta antes del test, crea un usuario de prueba
@Before
fun setupUserDB() {
// Obtiene una referencia a la base de datos de Room
var context: Context = ApplicationProvider.getApplicationContext<Context>()
volatileDB = GepetoDatabase.getInstance(context)!!

userDAO = volatileDB.userDao()

// Crea un usuario de prueba
val user = User(1, "admin", "admin")

// Inserta el usuario en la base de datos
runBlocking {
userDAO.insert(user)
}
}

@Test
fun testCU01() {
val appCompatEditText = onView(
allOf(
withId(R.id.et_username),
childAtPosition(
childAtPosition(
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
3
),
1
)
)
)
appCompatEditText.perform(scrollTo(), replaceText("admin"), closeSoftKeyboard())

val appCompatEditText2 = onView(
allOf(
withId(R.id.et_password),
childAtPosition(
childAtPosition(
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
3
),
3
)
)
)
appCompatEditText2.perform(scrollTo(), replaceText("admin"), closeSoftKeyboard())

val materialButton3 = onView(
allOf(
withId(R.id.bt_login), withText("Login"),
childAtPosition(
childAtPosition(
withClassName(`is`("android.widget.LinearLayout")),
4
),
0
)
)
)
materialButton3.perform(scrollTo(), click())

val bottomNavigationItemView = onView(
allOf(
withId(R.id.ingredientesFragment), withContentDescription("Crear Receta"),
childAtPosition(
childAtPosition(
withId(R.id.bottom_navigation),
0
),
2
),
isDisplayed()
)
)
bottomNavigationItemView.perform(click())

val materialButton4 = onView(
allOf(
withId(R.id.button_item), withText("5 spice powder"),
childAtPosition(
allOf(
withId(R.id.rv_item),
childAtPosition(
withId(R.id.rvTodosIngredientes),
0
)
),
0
)
)
)
materialButton4.perform(scrollTo(), click())

val materialButton5 = onView(
allOf(
withId(R.id.button_item), withText("Acorn squash"),
childAtPosition(
allOf(
withId(R.id.rv_item),
childAtPosition(
withId(R.id.rvTodosIngredientes),
0
)
),
0
)
)
)
materialButton5.perform(scrollTo(), click())

val materialButton6 = onView(
allOf(
withId(R.id.button_item), withText("Adobo sauce"),
childAtPosition(
allOf(
withId(R.id.rv_item),
childAtPosition(
withId(R.id.rvTodosIngredientes),
0
)
),
0
)
)
)
materialButton6.perform(scrollTo(), click())

val button = onView(
allOf(
withId(R.id.button_item), withText("5 spice powder"),
withParent(
allOf(
withId(R.id.rv_item),
withParent(withId(R.id.rvIngredientesSeleccionados))
)
),
isDisplayed()
)
)
button.check(matches(isDisplayed()))

val button2 = onView(
allOf(
withId(R.id.button_item), withText("Acorn squash"),
withParent(
allOf(
withId(R.id.rv_item),
withParent(withId(R.id.rvIngredientesSeleccionados))
)
),
isDisplayed()
)
)
button2.check(matches(isDisplayed()))

val button3 = onView(
allOf(
withId(R.id.button_item), withText("Adobo sauce"),
withParent(
allOf(
withId(R.id.rv_item),
withParent(withId(R.id.rvIngredientesSeleccionados))
)
),
isDisplayed()
)
)
button3.check(matches(isDisplayed()))
}

private fun childAtPosition(
parentMatcher: Matcher<View>, position: Int
): Matcher<View> {

return object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("Child at position $position in parent ")
parentMatcher.describeTo(description)
}

public override fun matchesSafely(view: View): Boolean {
val parent = view.parent
return parent is ViewGroup && parentMatcher.matches(parent)
&& view == parent.getChildAt(position)
}
}
}
}
Loading

0 comments on commit 32ca628

Please sign in to comment.