package se.chalmers.watchmetest.ui;

import se.chalmers.watchme.R;
import se.chalmers.watchme.activity.AddMovieActivity;
import se.chalmers.watchme.activity.MainActivity;
import android.test.ActivityInstrumentationTestCase2;

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

public class TagListFragmentTest extends
		ActivityInstrumentationTestCase2<MainActivity> {
	
	// TODO: make public static?
	final int ADD_MOVIE_BUTTON = 1;
	final int TITLE_FIELD = 0;
	final int TAG_FIELD = 1;

	Solo solo;

	public TagListFragmentTest() {
		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 testAddTag() {
		
		solo.clickOnText("Movies");
		solo.clickOnActionBarItem(R.id.menu_add_movie);
		solo.enterText(TITLE_FIELD, "Batman");
		solo.enterText(TAG_FIELD, "Action");
		solo.clickOnButton(ADD_MOVIE_BUTTON);
		solo.clickOnText("Tags");
		boolean wasTagFound = solo.searchText("action");
		assertTrue(wasTagFound);
	}

	public void testClickTag() {
		solo.clickOnText("Movies");
		solo.clickOnActionBarItem(R.id.menu_add_movie);
		solo.enterText(TITLE_FIELD, "Batman");
		solo.enterText(TAG_FIELD, "Action");
		solo.clickOnButton(ADD_MOVIE_BUTTON);
		
		solo.clickOnActionBarItem(R.id.menu_add_movie);
		solo.enterText(0, "Dead poet society");
		solo.enterText(1, "Drama");
		solo.clickOnButton(ADD_MOVIE_BUTTON);
		
		solo.clickOnText("Tags");
		solo.clickOnText("drama");
		
		solo.assertCurrentActivity("MainActivity expected", MainActivity.class);
		boolean wasDramaMoviesFound = solo.searchText("Dead poet society");
		boolean wasActionMoviesFound = solo.searchText("Batman");
		assertTrue(wasDramaMoviesFound);
		assertFalse(wasActionMoviesFound);
	}

}

@@ -100,16 +100,12 @@
 ity.
-AddMovie
+Main
 Acti
@@ -138,36 +138,44 @@
 atchme.activity.
-Main
+TagMovieList
 Activity;%0Aimport
@@ -882,18 +882,16 @@
 dTag() %7B
-%0A%09
 %09%0A%09%09solo
@@ -1419,32 +1419,62 @@
 VIE_BUTTON);%0A%09%09%0A
+%09%09solo.clickOnText(%22Movies%22);%0A
 %09%09solo.clickOnAc
@@ -1524,17 +1524,27 @@
 terText(
-0
+TITLE_FIELD
 , %22Dead 
@@ -1576,17 +1576,25 @@
 terText(
-1
+TAG_FIELD
 , %22Drama
@@ -1730,20 +1730,28 @@
 tivity(%22
-Main
+TagMovieList
 Activity
@@ -1762,20 +1762,28 @@
 ected%22, 
-Main
+TagMovieList
 Activity
@@ -1993,14 +1993,795 @@
 Found);%0A
-
 %09%7D
+%0A%09%0A%09public void testDeleteTag() %7B%0A%09%09solo.clickOnText(%22Movies%22);%0A%09%09solo.clickOnActionBarItem(R.id.menu_add_movie);%0A%09%09solo.enterText(TITLE_FIELD, %22Batman%22);%0A%09%09solo.enterText(TAG_FIELD, %22Action%22);%0A%09%09solo.clickOnButton(ADD_MOVIE_BUTTON);%0A%09%09%0A%09%09solo.clickOnText(%22Tags%22);%0A%09%09solo.clickLongOnText(%22action%22);%0A%09%09%0A%09%09boolean dialogAppeared = solo%0A%09%09%09%09.searchText(%22Are you sure you want to delete %5C%22action%5C%22?%22);%0A%09%09assertTrue(dialogAppeared);%0A%09%09%0A%09%09solo.clickOnText(%22Cancel%22);%0A%09%09boolean expected = true;%0A%09%09boolean actual = solo.searchText(%22action%22);%0A%09%09assertEquals(%22action-tag was not found%22, expected, actual);%0A%09%09%0A%09%09solo.clickLongOnText(%22action%22);%0A%09%09solo.clickOnText(%22Yes%22);%0A%09%09expected = true;%0A%09%09actual = solo.searchText(%22action%22);%0A%09%09assertEquals(%22action-tag was found%22, expected, actual);%0A%09%7D%0A%09%0A%09
 %0A%0A%7D%0A

Add new test in TagListFragment: testDeleteTag()