<commit_before>package org.msf.records.ui.userlogin;

import org.msf.records.R;
import org.msf.records.ui.FunctionalTestCase;
import org.msf.records.ui.ProgressFragment;
import org.msf.records.ui.matchers.UserMatchers;

import java.util.Date;

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasToString;

public class UserLoginActivityTest extends FunctionalTestCase {

    /** Adds a new user and logs in. */
    public void testAddUser() {
        screenshot("Test Start");
        long n = new Date().getTime() % 100000;
        String username = "test" + n;
        String given = "Testgiven" + n;
        String family = "Testfamily" + n;

        // Add new user
        onView(withText("Add User")).perform(click());
        screenshot("After Add User Clicked");
        onView(withId(R.id.add_user_given_name_tv)).perform(typeText(given));
        onView(withId(R.id.add_user_family_name_tv)).perform(typeText(family));
        screenshot("After User Populated");
        onView(withText("OK")).perform(click());
        screenshot("After OK Pressed");

        waitForProgressFragment();

        // Click new user
        onData(allOf(hasToString(equalTo("TT")), isDisplayed()));
        screenshot("In User Selection");
        onData(new UserMatchers.HasFullName(given + " " + family)).perform(click());

        // Should be logged in
        onView(withText("Locations")).check(matches(isDisplayed()));
        screenshot("After User Selected");
        onView(withText("TT")).perform(click());
        onView(withText(given + " " + family)).check(matches(isDisplayed()));
        screenshot("After User Selected in Action Bar");
    }

    /** Logs in as the guest user and logs out. */
    public void testGuestLoginLogout() {
        // Click guest user
        onView(withText("GU")).check(matches(isDisplayed()));
        screenshot("Test Start");
        onView(withText("Guest User")).perform(click());

        // Should be logged in; log out
        onView(withText("Locations")).check(matches(isDisplayed()));
        screenshot("After Guest User Clicked");
        onView(withText("GU")).perform(click());
        onView(withText("Guest User")).check(matches(isDisplayed()));
        screenshot("After Guest User Selected in Action Bar");
        onView(withId(R.id.button_log_out)).perform(click());

        waitForProgressFragment();

        // Should be back at the user list
        onView(withText("Add User")).check(matches(isDisplayed()));
        screenshot("After Logout");
    }
}<commit_msg>Fixing UserLoginActivityTest -- was broken by new title in tent selection, but should now no longer depend on the exact title<commit_after>package org.msf.records.ui.userlogin;

import org.msf.records.R;
import org.msf.records.ui.FunctionalTestCase;
import org.msf.records.ui.ProgressFragment;
import org.msf.records.ui.matchers.UserMatchers;

import java.util.Date;

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasToString;

public class UserLoginActivityTest extends FunctionalTestCase {

    /** Adds a new user and logs in. */
    public void testAddUser() {
        screenshot("Test Start");
        long n = new Date().getTime() % 100000;
        String username = "test" + n;
        String given = "Testgiven" + n;
        String family = "Testfamily" + n;

        // Add new user
        onView(withText("Add User")).perform(click());
        screenshot("After Add User Clicked");
        onView(withId(R.id.add_user_given_name_tv)).perform(typeText(given));
        onView(withId(R.id.add_user_family_name_tv)).perform(typeText(family));
        screenshot("After User Populated");
        onView(withText("OK")).perform(click());
        screenshot("After OK Pressed");

        waitForProgressFragment();

        // Click new user
        onData(allOf(hasToString(equalTo("TT")), isDisplayed()));
        screenshot("In User Selection");
        onData(new UserMatchers.HasFullName(given + " " + family)).perform(click());

        // Should be logged in
        onView(withText(R.string.title_activity_tent_selection)).check(matches(isDisplayed()));
        screenshot("After User Selected");
        onView(withText("TT")).perform(click());
        onView(withText(given + " " + family)).check(matches(isDisplayed()));
        screenshot("After User Selected in Action Bar");
    }

    /** Logs in as the guest user and logs out. */
    public void testGuestLoginLogout() {
        // Click guest user
        onView(withText("GU")).check(matches(isDisplayed()));
        screenshot("Test Start");
        onView(withText("Guest User")).perform(click());

        // Should be logged in; log out
        onView(withText(R.string.title_activity_tent_selection)).check(matches(isDisplayed()));
        screenshot("After Guest User Clicked");
        onView(withText("GU")).perform(click());
        onView(withText("Guest User")).check(matches(isDisplayed()));
        screenshot("After Guest User Selected in Action Bar");
        onView(withId(R.id.button_log_out)).perform(click());

        waitForProgressFragment();

        // Should be back at the user list
        onView(withText("Add User")).check(matches(isDisplayed()));
        screenshot("After Logout");
    }
}
{'fraction_non_alphanumeric': 0.13441330998248688, 'fraction_numerical': 0.0017513134851138354, 'mean_word_length': 3.7360055286800278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3143898', 'n_tokens_mistral': 2068, 'n_tokens_neox': 2034, 'n_words': 379}