package se.chalmers.watchmetest.activity;

import se.chalmers.watchme.R;
import se.chalmers.watchme.activity.MainActivity;
import se.chalmers.watchmetest.Constants;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.support.v4.view.ViewPager;
import android.test.ActivityInstrumentationTestCase2;

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

public class MainActivityTest extends
		ActivityInstrumentationTestCase2<MainActivity> {

	private Solo solo;

	public MainActivityTest() {
		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();
	}

	// TODO: Name? testOnCreate()?
	// Testing to basic stuff?
	// API fix
	@TargetApi(11)
	public void testState() {
		MainActivity mainActivity = this.getActivity();
		ActionBar actionBar = mainActivity.getActionBar();

		assertTrue(actionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS);
	}

	public void testSwitchTabs() {
		MainActivity mainActivity = this.getActivity();
		ViewPager viewPager = (ViewPager) mainActivity
				.findViewById(R.id.vPager);
		int viewPagerId = viewPager.getId();

		solo.assertCurrentActivity("Current activity is not MainActivity",
				MainActivity.class);

		boolean tagListFragmentViewed = solo
				.waitForFragmentByTag("android:switcher:" + viewPagerId + ":"
						+ Constants.TAG_LIST_FRAGMENT_VIEW_PAGER_ID);
		solo.clickOnText("Tags");
		assertTrue(tagListFragmentViewed);

		boolean movieListFragmentViewed = solo
				.waitForFragmentByTag("android:switcher:" + viewPagerId + ":"
						+ Constants.MOVIE_LIST_FRAGMENT_VIEW_PAGER_ID);
		solo.clickOnText("Movies");
		assertTrue(movieListFragmentViewed);
	}

}

@@ -369,16 +369,130 @@
 .Solo;%0A%0A
+/**%0A * Class that tests functionality implemented in MainActivity class.%0A * %0A * @author mattiashenriksson%0A * %0A */%0A
 public c
@@ -1022,16 +1022,73 @@
 API fix%0A
+%09/**%0A%09 * Test if main activity is in correct state.%0A%09 */%0A
 %09@Target
@@ -1226,16 +1226,65 @@
 Bar();%0A%0A
+%09%09// Check if the correct navigation mode is set%0A
 %09%09assert
@@ -1358,16 +1358,95 @@
 S);%0A%09%7D%0A%0A
+%09/**%0A%09 * Test if the tab switching functionality is functioning properly.%0A%09 */%0A
 %09public 
@@ -1518,16 +1518,69 @@
 ivity();
+%0A%0A%09%09// Get the id of the view pager handling the tabs
 %0A%09%09ViewP
@@ -1787,17 +1787,64 @@
 class);%0A
+%09%09%0A%09%09// Click Tags-tab and check if it's viewed
 %0A
-
 %09%09boolea
@@ -2058,16 +2058,63 @@
 ewed);%0A%0A
+%09%09// Click Movies-tab and check if it's viewed%0A
 %09%09boolea

Add comments in MainActivityTest class