Skip to content

Commit

Permalink
Merge branch 'feature/506398-FiltrarPorPrecioMaximo' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
“Hector” committed Nov 6, 2024
2 parents e4113a5 + 5353470 commit 31b5b2f
Show file tree
Hide file tree
Showing 9 changed files with 598 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anything;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.not;
import static es.unican.gasolineras.model.TipoCombustible.GASOLEO_A;
import static es.unican.gasolineras.utils.MockRepositories.getTestRepository;

import android.content.Context;
import android.view.View;

import androidx.test.espresso.DataInteraction;
import androidx.test.espresso.matcher.RootMatchers;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.platform.app.InstrumentationRegistry;

Expand All @@ -30,6 +35,7 @@
import dagger.hilt.android.testing.UninstallModules;
import es.unican.gasolineras.R;
import es.unican.gasolineras.injection.RepositoriesModule;
import es.unican.gasolineras.model.TipoCombustible;
import es.unican.gasolineras.repository.IGasolinerasRepository;

@UninstallModules(RepositoriesModule.class)
Expand All @@ -48,9 +54,11 @@ public class FiltrarPorPrecioMaximoUITest {
@BindValue
public final IGasolinerasRepository repository = getTestRepository(context, R.raw.gasolineras_ccaa_06);

View decorView;

@Before
public void inicializa(){
activityRule.getScenario().onActivity(activity -> decorView = activity.getWindow().getDecorView());
}

@Test
Expand All @@ -62,14 +70,14 @@ public void testFiltarGasolinerasPorPrecioMaximoCasoExito() {
//clicka en el selector de combustible
onView(withId(R.id.spinnerCombustible)).perform(click());

//elige la opcion gasolina 95 E5
onData(allOf(is(instanceOf(String.class)),
is("Gasoleo_A"))).inRoot(isPlatformPopup()).perform(click());
//elige la opcion gasoleo A
onData(allOf(is(instanceOf(TipoCombustible.class)),
is(GASOLEO_A))).inRoot(isPlatformPopup()).perform(click());

//clicka en el campo de precio máximo
onView(withId(R.id.etPrecioMax)).perform(click());

//escribe 1.512 en el campo de precio máximo
//escribe 1.4 en el campo de precio máximo
onView(withId(R.id.etPrecioMax)).perform(typeText("1.4"));

//clicka el boton filtrar
Expand All @@ -81,17 +89,47 @@ public void testFiltarGasolinerasPorPrecioMaximoCasoExito() {

//comprueba la direccion de la segunda gasolinera
DataInteraction g2 = onData(anything()).inAdapterView(withId(R.id.lvStations)).atPosition(1);
g2.onChildView(withId(R.id.tvAddress)).check(matches(withText("P.I. CROS km CENTRO COMERCIAL M")));
g2.onChildView(withId(R.id.tvAddress)).check(matches(withText("CALLE SANTIAGO-LA LLANADA, 1")));
}

@Test
public void testFiltrarGasolinerasPorPrecioMaximoError(){
public void testFiltrarGasolinerasPorPrecioMaximoNoIntroducidoError() throws InterruptedException {

//clicka en filtrar
onView(withId(R.id.menuFiltrar)).perform(click());
//comprueba mensaje de error
// onView(withText("Por favor, introduce un precio máximo.")).inRoot(RootMatchers.withDecorView(not(decorView))).check(matches(isDisplayed()));
}

@Test
public void testFiltrarGasolinerasPorPrecioMaximoNoNumericoError() throws InterruptedException {

//clicka en filtrar
onView(withId(R.id.menuFiltrar)).perform(click());

//clicka en el campo de precio máximo
onView(withId(R.id.etPrecioMax)).perform(click());

//escribe "Uno punto cuatro" en el campo de precio máximo
onView(withId(R.id.etPrecioMax)).perform(typeText("Uno punto cuatro"));

//comprueba mensaje de error
// onView(withText("Por favor, introduce un número válido para el precio máximo.")).inRoot(RootMatchers.withDecorView(not(decorView))).check(matches(isDisplayed()));
}

@Test
public void testFiltrarGasolinerasPorPrecioMaximoNegativoError() throws InterruptedException {

//clicka en filtrar
onView(withId(R.id.menuFiltrar)).perform(click());

//clicka en el campo de precio máximo
onView(withId(R.id.etPrecioMax)).perform(click());

//escribe -1.4 en el campo de precio máximo
onView(withId(R.id.etPrecioMax)).perform(typeText("-1.4"));

//comprueba mensaje de error
onView(withId(R.id.tvListaVacia)).
check(matches(withText("Error: No hay ningun punto de interes añadido")));
// onView(withText("Por favor, el precio máximo debe ser positivo.")).inRoot(RootMatchers.withDecorView(not(decorView))).check(matches(isDisplayed()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public interface Presenter {
* The presenter is informed that the Filtrar item in the menu has been clicked
*/
public void onMenuAnhadirPuntoInteresClicked();

public void ordenarGasolinerasCercanasPtoInteres(PuntoInteres p);

public void filtraGasolinerasPorPrecioMaximo(double precioMax, TipoCombustible combustible);
}

/**
Expand Down

This file was deleted.

Loading

0 comments on commit 31b5b2f

Please sign in to comment.