/*
 * Copyright 2014 Uwe Trottmann
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.battlelancer.seriesguide.test;

import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import com.battlelancer.seriesguide.R;
import com.battlelancer.seriesguide.ui.ShowsActivity;

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerActions.closeDrawer;
import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerActions.openDrawer;
import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerMatchers.isClosed;
import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerMatchers.isOpen;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

@LargeTest
public class DrawerNavTest extends ActivityInstrumentationTestCase2<ShowsActivity> {

    public DrawerNavTest() {
        super(ShowsActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        // Espresso will not launch our activity for us, we must launch it via getActivity().
        getActivity();
    }

    public void testOpenAndCloseDrawer() {
        // drawer should be closed
        onView(withId(R.id.drawer_layout)).check(matches(isClosed()));

        openDrawer(R.id.drawer_layout);

        onView(withId(R.id.drawer_layout)).check(matches(isOpen()));

        closeDrawer(R.id.drawer_layout);

        onView(withId(R.id.drawer_layout)).check(matches(isClosed()));
    }

}

@@ -823,29 +823,169 @@
 uide.ui.
-ShowsActivity
+BaseNavDrawerActivity;%0Aimport com.battlelancer.seriesguide.ui.ShowsActivity;%0Aimport com.google.android.apps.common.testing.ui.espresso.action.ViewActions
 ;%0A%0Aimpor
@@ -1143,16 +1143,101 @@
 onView;%0A
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.pressBack;%0A
 import s
@@ -1811,16 +1811,115 @@
 isOpen;%0A
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;%0A
 import s
@@ -2578,16 +2578,16 @@
 vity().%0A
-
         
@@ -2604,24 +2604,992 @@
 y();%0A    %7D%0A%0A
+    public void testNavigateToListsAndBack() throws InterruptedException %7B%0A        navigateToAndBack(R.string.lists);%0A    %7D%0A%0A    public void testNavigateToMoviesAndBack() throws InterruptedException %7B%0A        navigateToAndBack(R.string.movies);%0A    %7D%0A%0A    public void testNavigateToStatsAndBack() throws InterruptedException %7B%0A        navigateToAndBack(R.string.statistics);%0A    %7D%0A%0A    public void testNavigateToSearcAndBack() throws InterruptedException %7B%0A        navigateToAndBack(R.string.search_hint);%0A    %7D%0A%0A    private void navigateToAndBack(int drawerItemTitleResId) throws InterruptedException %7B%0A        onView(withId(R.id.drawer_layout)).check(matches(isClosed()));%0A%0A        openDrawer(R.id.drawer_layout);%0A%0A        onView(withText(drawerItemTitleResId)).perform(click());%0A%0A        // let the UI do some loading before going back%0A        Thread.sleep(1500);%0A%0A        pressBack();%0A%0A        onView(withId(R.id.drawer_layout)).check(matches(isClosed()));%0A    %7D%0A%0A
     public v

Add simple tests clicking all nav items and going back.