package thundersquadron.thundercab.userinterfacetest;

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;

import com.robotium.solo.Solo;
import com.thundersquadron.thundercab.R;
import com.thundersquadron.thundercab.activities.nav.NavActivity;
import com.thundersquadron.thundercab.activities.startup.StartUpActivity;


/**
 * UI test for the initial screen.
 *
 * Tests Use Case
 * UC 03.02.01 - LoginToUserProfile
 */
public class StartUpActivityTest extends ActivityInstrumentationTestCase2<StartUpActivity> {

    private Solo solo;

    /**
     * Instantiates a new Start up activity test.
     */
    public StartUpActivityTest() {
        super(StartUpActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        solo = new Solo(getInstrumentation(), getActivity());
    }

    /**
     * Test start.
     *
     * @throws Exception the exception
     */
    public void testStart() throws Exception {
        Activity activity = getActivity();
    }

    /**
     * Test the UI for the login workflow.
     *
     * @throws Exception the exception
     */
    public void testLogin() throws Exception {
        solo.assertCurrentActivity("Wrong Startup Activity", StartUpActivity.class);
        solo.enterText((EditText) solo.getView(R.id.usernameEditText), "inexistinguser");

        solo.clickOnButton("Login");
        solo.waitForText(solo.getCurrentActivity().getResources().getString(R.string.user_does_not_exist));
        solo.waitForDialogToClose();

        solo.clearEditText((EditText) solo.getView(R.id.usernameEditText));
        solo.enterText((EditText) solo.getView(R.id.usernameEditText), "testRider");
        solo.clickOnButton("Login");

        solo.waitForActivity(NavActivity.class);
        solo.assertCurrentActivity("Not Nav Activity", NavActivity.class);
    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
    }
}
