diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index af26af30d..4f65f92a9 100755 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -38,6 +38,10 @@ android:theme="@style/Theme.AppCompat.NoActionBar" android:name="android.support.design.widget.BottomSheetBehaviorActivity"/> + + diff --git a/tests/res/layout/design_navigation_view.xml b/tests/res/layout/design_navigation_view.xml new file mode 100644 index 000000000..3f4e03b43 --- /dev/null +++ b/tests/res/layout/design_navigation_view.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + diff --git a/tests/res/menu/navigation_view_content.xml b/tests/res/menu/navigation_view_content.xml new file mode 100644 index 000000000..24fd83069 --- /dev/null +++ b/tests/res/menu/navigation_view_content.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tests/res/values/colors.xml b/tests/res/values/colors.xml new file mode 100644 index 000000000..d1a6a1cd3 --- /dev/null +++ b/tests/res/values/colors.xml @@ -0,0 +1,21 @@ + + + + + #8020A060 + #30B050 + #F0E020 + diff --git a/tests/res/values/dimens.xml b/tests/res/values/dimens.xml index c20e4f8cd..c402941a0 100644 --- a/tests/res/values/dimens.xml +++ b/tests/res/values/dimens.xml @@ -18,4 +18,6 @@ 100dip 120dip 128dp + + 20sp \ No newline at end of file diff --git a/tests/res/values/strings.xml b/tests/res/values/strings.xml index 854e711a1..05dd55e9f 100644 --- a/tests/res/values/strings.xml +++ b/tests/res/values/strings.xml @@ -15,4 +15,9 @@ --> Tab text! + + Home + Profile + People + Settings \ No newline at end of file diff --git a/tests/res/values/styles.xml b/tests/res/values/styles.xml new file mode 100644 index 000000000..1fda2e6a8 --- /dev/null +++ b/tests/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/tests/src/android/support/design/testutils/DrawerLayoutActions.java b/tests/src/android/support/design/testutils/DrawerLayoutActions.java new file mode 100755 index 000000000..e4ea8673f --- /dev/null +++ b/tests/src/android/support/design/testutils/DrawerLayoutActions.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * 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 android.support.design.testutils; + +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.v4.widget.DrawerLayout; +import android.view.View; +import org.hamcrest.Matcher; + +import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; + +public class DrawerLayoutActions { + /** + * Opens the drawer at the specified edge gravity. + */ + public static ViewAction openDrawer(final int drawerEdgeGravity) { + return new ViewAction() { + @Override + public Matcher getConstraints() { + return isAssignableFrom(DrawerLayout.class); + } + + @Override + public String getDescription() { + return "Opens the drawer"; + } + + @Override + public void perform(UiController uiController, View view) { + uiController.loopMainThreadUntilIdle(); + + DrawerLayout drawerLayout = (DrawerLayout) view; + drawerLayout.openDrawer(drawerEdgeGravity); + + // Wait for a full second to let the inner ViewDragHelper complete the operation + uiController.loopMainThreadForAtLeast(1000); + } + }; + } + + /** + * Closes the drawer at the specified edge gravity. + */ + public static ViewAction closeDrawer(final int drawerEdgeGravity) { + return new ViewAction() { + @Override + public Matcher getConstraints() { + return isAssignableFrom(DrawerLayout.class); + } + + @Override + public String getDescription() { + return "Closes the drawer"; + } + + @Override + public void perform(UiController uiController, View view) { + uiController.loopMainThreadUntilIdle(); + + DrawerLayout drawerLayout = (DrawerLayout) view; + drawerLayout.closeDrawer(drawerEdgeGravity); + + // Wait for a full second to let the inner ViewDragHelper complete the operation + uiController.loopMainThreadForAtLeast(1000); + } + }; + } +} diff --git a/tests/src/android/support/design/widget/NavigationViewActivity.java b/tests/src/android/support/design/widget/NavigationViewActivity.java new file mode 100644 index 000000000..c3e810cf7 --- /dev/null +++ b/tests/src/android/support/design/widget/NavigationViewActivity.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * 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 android.support.design.widget; + +import android.support.design.test.R; + +public class NavigationViewActivity extends BaseTestActivity { + @Override + protected int getContentViewLayoutResId() { + return R.layout.design_navigation_view; + } +} diff --git a/tests/src/android/support/design/widget/NavigationViewTest.java b/tests/src/android/support/design/widget/NavigationViewTest.java new file mode 100755 index 000000000..0f99cb517 --- /dev/null +++ b/tests/src/android/support/design/widget/NavigationViewTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * 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 android.support.design.widget; + +import android.content.res.Resources; +import android.support.design.test.R; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.test.suitebuilder.annotation.SmallTest; +import org.junit.Before; +import org.junit.Test; + +import static android.support.design.testutils.DrawerLayoutActions.closeDrawer; +import static android.support.design.testutils.DrawerLayoutActions.openDrawer; +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.*; +import static org.hamcrest.core.AllOf.allOf; + +public class NavigationViewTest + extends BaseInstrumentationTestCase { + private DrawerLayout mDrawerLayout; + + private NavigationView mNavigationView; + + public NavigationViewTest() { + super(NavigationViewActivity.class); + } + + @Before + public void setUp() throws Exception { + final NavigationViewActivity activity = mActivityTestRule.getActivity(); + mDrawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout); + mNavigationView = (NavigationView) mDrawerLayout.findViewById(R.id.start_drawer); + + // Close the drawer to reset the state for the next test + onView(withId(R.id.drawer_layout)).perform(closeDrawer(GravityCompat.START)); + } + + @Test + @SmallTest + public void testBasics() { + // Open our drawer + onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START)); + + final Resources res = mActivityTestRule.getActivity().getResources(); + + // Check that we have the expected menu items in our NavigationView + onView(allOf(withText(res.getString(R.string.navigate_home)), + isDescendantOfA(withId(R.id.start_drawer)))).check(matches(isDisplayed())); + onView(allOf(withText(res.getString(R.string.navigate_profile)), + isDescendantOfA(withId(R.id.start_drawer)))).check(matches(isDisplayed())); + onView(allOf(withText(res.getString(R.string.navigate_people)), + isDescendantOfA(withId(R.id.start_drawer)))).check(matches(isDisplayed())); + onView(allOf(withText(res.getString(R.string.navigate_settings)), + isDescendantOfA(withId(R.id.start_drawer)))).check(matches(isDisplayed())); + } +}