Skip to content

Commit

Permalink
Merge branch 'master' into bug/TeachTravisToBePolite
Browse files Browse the repository at this point in the history
  • Loading branch information
vquelque committed Nov 14, 2018
2 parents 35d932d + 0a98941 commit 6a23afd
Show file tree
Hide file tree
Showing 16 changed files with 605 additions and 101 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -75,7 +75,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.22.0'
testImplementation "android.arch.core:core-testing:1.1.1"

androidTestAnnotationProcessor 'com.google.dagger:dagger-android-processor:2.17'
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:2.17'

Expand Down
@@ -0,0 +1,56 @@
package ch.epfl.sweng.eventmanager;

import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;

import org.hamcrest.Description;
import org.hamcrest.Matcher;

import static org.hamcrest.CoreMatchers.is;

public class TestHelper {
/**
* Stolen from StackOverflow question 36329978.
*/
public static Matcher<View> withToolbarTitle(CharSequence title) {
return withToolbarTitle(is(title));
}

/**
* Stolen from StackOverflow question 36329978.
*/
public static Matcher<View> withToolbarTitle(final Matcher<CharSequence> textMatcher) {
return new BoundedMatcher<View, Toolbar>(Toolbar.class) {
@Override
public boolean matchesSafely(Toolbar toolbar) {
return textMatcher.matches(toolbar.getTitle());
}

@Override
public void describeTo(Description description) {
description.appendText("with toolbar title: ");
textMatcher.describeTo(description);
}
};
}

/**
* Stolen from StackOverflow question 42668617.
*/
public static Matcher<View> hasNoErrorText() {
return new BoundedMatcher<View, EditText>(EditText.class) {

@Override
public void describeTo(Description description) {
description.appendText("has no error text: ");
}

@Override
protected boolean matchesSafely(EditText view) {
return view.getError() == null;
}
};
}
}
Expand Up @@ -32,6 +32,7 @@
import org.junit.runner.RunWith;

import ch.epfl.sweng.eventmanager.R;
import ch.epfl.sweng.eventmanager.TestHelper;
import ch.epfl.sweng.eventmanager.users.Session;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -122,8 +123,8 @@ public void testWrongCredentials() {
public void testInvalidCredentialsInput() {
String email = "al.pha";
String password = "secret";
String emptyPasswordError = getResourceString(R.string.empty_password_activity_login);
String invalidEmailError = getResourceString(R.string.invalid_email_activity_login);
String emptyPasswordError = getResourceString(R.string.empty_password_error);
String invalidEmailError = getResourceString(R.string.invalid_email_error);

// Test empty password
onView(withId(R.id.email_field))
Expand All @@ -142,6 +143,14 @@ public void testInvalidCredentialsInput() {
.check(matches(hasErrorText(invalidEmailError)));
}

@Test
public void testOpenSignUpForm() {
onView(withId(R.id.signup_button))
.perform(click());

TestHelper.withToolbarTitle(getResourceString(R.string.title_activity_sign_up));
}

private String getResourceString(int id) {
Context targetContext = InstrumentationRegistry.getTargetContext();
return targetContext.getResources().getString(id);
Expand Down
@@ -0,0 +1,98 @@
package ch.epfl.sweng.eventmanager.ui.userManager;

import android.content.Context;
import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import junit.framework.AssertionFailedError;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import ch.epfl.sweng.eventmanager.R;
import ch.epfl.sweng.eventmanager.TestHelper;
import ch.epfl.sweng.eventmanager.users.Session;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.hasErrorText;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.containsString;

@RunWith(AndroidJUnit4.class)
public class SignUpActivityTest {

@Before
public void disableFirebaseAuth() {
Session.enforceDummySessions();
}

@Rule
public final ActivityTestRule<SignUpActivity> mActivityRule =
new ActivityTestRule<>(SignUpActivity.class);

@Test
public void testNonMatchingPasswords() {
String email = "al.pha";
String password = "secret";
String passwordMatchError = getResourceString(R.string.password_match_error);

// Test non-matching passwords
onView(withId(R.id.email_field))
.perform(typeText(email))
.perform(closeSoftKeyboard());
onView(withId(R.id.password_field))
.perform(typeText(password))
.perform(closeSoftKeyboard());
onView(withId(R.id.password_confirmation_field))
.perform(typeText("secret+typo"))
.perform(closeSoftKeyboard());
onView(withId(R.id.signup_button)).perform(click());
onView(withId(R.id.password_field))
.check(matches(hasErrorText(passwordMatchError)));
}

@Test
public void testValidInput() {
String email = "al.pha@domain.tld";
String password = "secret";

onView(withId(R.id.email_field))
.perform(typeText(email))
.perform(closeSoftKeyboard());
onView(withId(R.id.password_field))
.perform(typeText(password))
.perform(closeSoftKeyboard());
onView(withId(R.id.password_confirmation_field))
.perform(typeText(password))
.perform(closeSoftKeyboard());
onView(withId(R.id.signup_button)).perform(click());

// Nothing is going to happen since we use the DummyInMemorySession
// Check that everything went fine with the lack of error messages
onView(withId(R.id.email_field))
.check(matches(TestHelper.hasNoErrorText()));
onView(withId(R.id.password_field))
.check(matches(TestHelper.hasNoErrorText()));
onView(withId(R.id.password_confirmation_field))
.check(matches(TestHelper.hasNoErrorText()));
}

private String getResourceString(int id) {
Context targetContext = InstrumentationRegistry.getTargetContext();
return targetContext.getResources().getString(id);
}
}
24 changes: 14 additions & 10 deletions app/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.epfl.sweng.eventmanager">
package="ch.epfl.sweng.eventmanager">

<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Expand Down Expand Up @@ -41,15 +41,20 @@
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key"/>

<activity android:name=".ui.eventSelector.EventPickingActivity"
android:launchMode="singleTop"/>

<activity android:name=".ui.userManager.LoginActivity"
android:label="@string/title_activity_login" />

<activity android:name=".ui.userManager.SignUpActivity"
android:label="@string/title_activity_sign_up" />

<activity
android:name=".ui.userManager.LoginActivity"
android:label="@string/title_activity_login"/>
<activity
android:name=".ui.userManager.DisplayAccountActivity"
android:label="@string/title_activity_account_display"/>
android:name=".ui.userManager.DisplayAccountActivity"
android:label="@string/title_activity_account_display" />

<activity
android:name=".ui.eventShowcase.EventShowcaseActivity"
android:theme="@style/AppTheme.NoActionBar"/>
Expand All @@ -64,9 +69,8 @@
android:resource="@xml/file_paths" />
</provider>

<activity android:name=".ui.eventAdministration.EventAdministrationActivity"></activity>
<activity android:name=".ui.eventAdministration.EventAdministrationActivity" />
<receiver android:name=".repository.impl.NotificationPublisher"/>

</application>

</manifest>
</manifest>
Expand Up @@ -6,6 +6,7 @@
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import ch.epfl.sweng.eventmanager.R;
import ch.epfl.sweng.eventmanager.ui.eventSelector.EventPickingActivity;
import ch.epfl.sweng.eventmanager.users.Session;
Expand All @@ -28,6 +29,12 @@ protected void onCreate(Bundle savedInstanceState) {

public void logoutThenRedirectToEventSelector(View view) {
Session.logout();

Toast toast = Toast.makeText(
this, getString(R.string.logout_toast), Toast.LENGTH_SHORT
);
toast.show();

Intent intent = new Intent(this,EventPickingActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Expand Down

0 comments on commit 6a23afd

Please sign in to comment.