package se.chalmers.watchmetest.activity;

import se.chalmers.watchme.R;
import se.chalmers.watchme.activity.MainActivity;
import se.chalmers.watchme.activity.MovieDetailsActivity;
import se.chalmers.watchmetest.Constants;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TextView;

import com.jayway.android.robotium.solo.Solo;

public class MovieDetailsActivityTest extends
		ActivityInstrumentationTestCase2<MainActivity> {

	Solo solo;

	public MovieDetailsActivityTest() {
		super(MainActivity.class);
	}

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

	@Override
	public void tearDown() throws Exception {
		// finish all activities that have been opened during test execution.
		solo.finishOpenedActivities();
	}
	
	public void testViewDetails() {
		solo.clickOnText("Movies");
		solo.clickOnActionBarItem(R.id.menu_add_movie);
		solo.enterText(Constants.TITLE_FIELD, "3_TEST_MOVIE");
		solo.setProgressBar(Constants.RATING_BAR, 1);
		solo.clickOnText("Pick");
		solo.setDatePicker(Constants.DATE_PICKER, 2014 - 1, 12, 24);
		solo.clickOnText("Done");
		solo.enterText(Constants.TAG_FIELD, "Action");
		solo.enterText(Constants.NOTE_FIELD, "Mum said I'd like this");
		solo.clickOnButton(Constants.ADD_MOVIE_BUTTON);
		solo.clickOnText("3_TEST_MOVIE");
		solo.assertCurrentActivity("MovieDetailsActivty expected", MovieDetailsActivity.class);
		
		boolean isTitleFound = solo.searchText("3_TEST_MOVIE");
		assertTrue(isTitleFound);
		
		RatingBar ratingBar = (RatingBar) solo.getView(R.id.my_rating_bar);
		assertTrue(ratingBar.getRating() == 1);
		
		TextView releaseDateLabel = (TextView) solo.getView(R.id.releaseDate);
		assertTrue(releaseDateLabel.getText().equals("24 Jan, 2014"));
		
		EditText noteField = (EditText) solo.getView(R.id.note_field_details);
		assertTrue(noteField.getText().toString().equals("Mum said I'd like this"));

		EditText tagField = (EditText) solo.getView(R.id.tag_field_details);
		assertTrue(tagField.getText().toString().equals("action"));
	}
}
@@ -2182,9 +2182,1489 @@
 %22));%0A%09%7D%0A
+%09%0A%09// TODO: add new movie every test or use last movie?%0A%09public void testEditDetails() %7B%0A%09%09solo.clickOnText(%22Movies%22);%0A%09%09solo.clickOnActionBarItem(R.id.menu_add_movie);%0A%09%09solo.enterText(Constants.TITLE_FIELD, %224_TEST_MOVIE%22);%0A%09%09solo.clickOnButton(Constants.ADD_MOVIE_BUTTON);%0A%09%09solo.clickOnText(%224_TEST_MOVIE%22);%0A%09%09%0A%09%09RatingBar ratingBar = (RatingBar) solo.getView(R.id.my_rating_bar);%0A%09%09TextView releaseDateLabel = (TextView) solo.getView(R.id.releaseDate);%0A%09%09EditText noteField = (EditText) solo.getView(R.id.note_field_details);%0A%09%09EditText tagField = (EditText) solo.getView(R.id.tag_field_details);%0A%09%09%0A%09%09assertTrue(ratingBar.getRating() == 0);%0A%09%09assertFalse(releaseDateLabel.getText().equals(%2224 Jan, 2014%22));%0A%09%09assertTrue(noteField.getText().toString().equals(%22%22));%0A%09%09assertTrue(tagField.getText().toString().equals(%22%22));%0A%09%09%0A%09%09solo.clickOnText(%22Edit%22);%0A%09%09solo.setProgressBar(Constants.RATING_BAR, 1);%0A%09%09solo.clickOnText(%22Pick%22);%0A%09%09solo.setDatePicker(Constants.DATE_PICKER, 2014 - 1, 12, 24);%0A%09%09solo.clickOnText(%22Done%22);%0A%09%09solo.enterText(0, %22Action%22);%0A%09%09solo.enterText(1, %22Mum said I'd like this%22);%0A%09%09%0A%09%09solo.clickOnText(%22Save%22);%0A%09%09solo.clickOnActionBarHomeButton();%0A%09%09solo.sleep(2000);%0A%09%09solo.clickOnText(%224_TEST_MOVIE%22);%0A%09%09%0A%09%09assertTrue(ratingBar.getRating() == 1);%0A%09%09assertTrue(releaseDateLabel.getText().equals(%2224 Jan, 2014%22));%0A%09%09assertTrue(noteField.getText().toString().equals(%22Mum said I'd like this%22));%0A%09%09assertTrue(tagField.getText().toString().equals(%22action%22));%0A%09%7D%0A
 %7D

Add new method in MovieDetailsActivityTest: testEditDetails()