package com.daksh.tmdbsample.movielist;

import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.daksh.tmdbsample.R;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.RootMatchers.isDialog;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

/**
 * Created by daksh on 08-09-2016.
 */

@RunWith(AndroidJUnit4.class)
@LargeTest
public class MovieListActivityTest extends TestCase {

    MovieListActivity activity;

    @Rule
    public final ActivityTestRule<MovieListActivity> rule =
            new ActivityTestRule<>(MovieListActivity.class);

    @Before
    public void init() {
        activity = rule.getActivity();
    }

    @Test
    public void testShouldOpenSortingAlertDialogWhenSortMenuItemClicked() {
        onView(withId(R.id.menu_sort))
                .perform(click());

        onView(withText(R.string.dialog_sort_order_title))
                .inRoot(isDialog())
                .check(matches(isDisplayed()));
    }
}

@@ -1562,11 +1562,745 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testShouldReloadListAfterSelectingOtherRadioButton() %7B%0A        //Reset check to Popular%0A        onView(withId(R.id.menu_sort))%0A                .perform(click());%0A%0A        onView(withId(R.id.radioPopular))%0A                .perform(click());%0A%0A        onView(withText(R.string.save))%0A                .perform(click());%0A%0A        //Test loading Top Rated%0A        onView(withId(R.id.menu_sort))%0A                .perform(click());%0A%0A        onView(withId(R.id.radioTopRated))%0A                .perform(click());%0A%0A        onView(withText(R.string.save))%0A                .perform(click());%0A%0A        //Requires Internet to pass%0A        onView(withId(R.id.content))%0A                .check(matches(isDisplayed()));%0A    %7D
 %0A%7D%0A

Add Espresso test for loading the list after selecting a Sort Order