Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Tablet layout #71

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.standardnotes.notes.comms.data.Tag;

import java.util.UUID;

Expand All @@ -31,16 +22,17 @@
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItem;
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.not;
import static org.standardnotes.notes.TestHelper.childAtPosition;

@LargeTest
@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -97,12 +89,9 @@ public void signupin() {
Espresso.unregisterIdlingResources(idlingResource);
}



@After
public void logout() {
ViewInteraction actionMenuItemView = onView(
allOf(withId(R.id.settings), withContentDescription("Settings"), isDisplayed()));
ViewInteraction actionMenuItemView = onView(allOf(withId(R.id.settings), isDisplayed()));
actionMenuItemView.perform(click());

ViewInteraction appCompatButton = onView(
Expand All @@ -112,13 +101,8 @@ public void logout() {

@Test
public void createNote() {

ViewInteraction floatingActionButton = onView(
allOf(withId(R.id.fab),
withParent(allOf(withId(R.id.rootView),
withParent(withId(R.id.drawer_layout)))),
isDisplayed()));
floatingActionButton.perform(click());
ViewInteraction newNoteButton = onView(anyOf(withId(R.id.fab_new_note), withId(R.id.new_note)));
newNoteButton.perform(click());

ViewInteraction appCompatEditText = onView(
withId(R.id.titleEdit));
Expand All @@ -132,17 +116,12 @@ public void createNote() {
allOf(withId(R.id.bodyEdit)));
appCompatEditText14.perform(scrollTo(), replaceText("body1"), closeSoftKeyboard());

ViewInteraction upButton = onView(
allOf(withContentDescription("Navigate up"),
withParent(withId(R.id.toolbar)),
isDisplayed()));
upButton.perform(click());
if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) {
pressBack();
}

ViewInteraction recyclerView = onView(
allOf(withId(R.id.list),
withParent(allOf(withId(R.id.noteListFrag),
withParent(withId(R.id.rootView)))),
isDisplayed()));
allOf(withId(R.id.list_note), isDisplayed()));
recyclerView.perform(actionOnItemAtPosition(0, click()));

ViewInteraction actionMenuItemView = onView(
Expand All @@ -153,13 +132,15 @@ public void createNote() {

appCompatEditText14.perform(scrollTo(), replaceText("body1a"), closeSoftKeyboard());

upButton.perform(click());
if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) {
pressBack();
}

ViewInteraction textView = onView(
allOf(withId(R.id.text), withText("body1a"),
childAtPosition(
childAtPosition(
withId(R.id.list),
withId(R.id.list_note),
0),
1),
isDisplayed()));
Expand All @@ -169,7 +150,7 @@ public void createNote() {
allOf(withId(R.id.title), withText("Title1"),
childAtPosition(
childAtPosition(
withId(R.id.list),
withId(R.id.list_note),
0),
0),
isDisplayed()));
Expand All @@ -188,12 +169,8 @@ public void justSignInAndOut() {

@Test
public void tagSomething() {
ViewInteraction floatingActionButton = onView(
allOf(withId(R.id.fab),
withParent(allOf(withId(R.id.rootView),
withParent(withId(R.id.drawer_layout)))),
isDisplayed()));
floatingActionButton.perform(click());
ViewInteraction newNoteButton = onView(anyOf(withId(R.id.fab_new_note), withId(R.id.new_note)));
newNoteButton.perform(click());

ViewInteraction appCompatEditText = onView(
withId(R.id.titleEdit));
Expand All @@ -210,12 +187,12 @@ public void tagSomething() {
ViewInteraction tagsAction = onView(
allOf(withId(R.id.tags), withContentDescription("Tags"), isDisplayed()));
tagsAction.perform(click());
onView(withId(R.id.fab)).perform(click());
onView(withId(R.id.fab_new_tag)).perform(click());
onView(
allOf(withId(R.id.tag), isDisplayed())).perform(replaceText("tag1"), closeSoftKeyboard());
onView(
allOf(withId(android.R.id.button1), withText("OK"))).perform(scrollTo(), click());
onView(withId(R.id.fab)).perform(click());
onView(withId(R.id.fab_new_tag)).perform(click());
onView(
allOf(withId(R.id.tag), isDisplayed())).perform(replaceText("tag2"), closeSoftKeyboard());
onView(
Expand All @@ -225,53 +202,47 @@ public void tagSomething() {

pressBack();

ViewInteraction upButton = onView(
allOf(withContentDescription("Navigate up"),
withParent(withId(R.id.toolbar)),
isDisplayed()));
upButton.perform(click());
if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) {
pressBack();
}

logout();
signupin();

ViewInteraction recyclerView = onView(
allOf(withId(R.id.list),
withParent(allOf(withId(R.id.noteListFrag),
withParent(withId(R.id.rootView)))),
isDisplayed()));
allOf(withId(R.id.list_note), isDisplayed()));
recyclerView.perform(actionOnItemAtPosition(0, click()));
onView(withText("tag1")).check(matches(isDisplayed()));
onView(allOf(withText("tag1"), withId(R.id.tagText))).check(matches(isDisplayed()));

tagsAction.perform(click());
onView(
withText("tag1")).perform(click()); // deselect
onView(
withText("tag2")).perform(click()); // select
pressBack();
onView(withText("tag2")).check(matches(isDisplayed()));
onView(withText("tag1")).check(doesNotExist());
pressBack();
onView(allOf(withText("tag2"), withId(R.id.tagText))).check(matches(isDisplayed()));
onView(withText("tag1")).check(matches(not(isDisplayed())));

if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) {
pressBack();
}

logout();
signupin();

recyclerView.perform(actionOnItemAtPosition(0, click()));
onView(withText("tag2")).check(matches(isDisplayed()));
onView(withText("tag1")).check(doesNotExist());

onView(allOf(withText("tag2"), withId(R.id.tagText))).check(matches(isDisplayed()));
onView(withText("tag1")).check(matches(not(isDisplayed())));

pressBack();
if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) {
pressBack();
}
}

@Test
public void openCloseOpenClose() {

ViewInteraction floatingActionButton = onView(
allOf(withId(R.id.fab),
withParent(allOf(withId(R.id.rootView),
withParent(withId(R.id.drawer_layout)))),
isDisplayed()));
floatingActionButton.perform(click());
ViewInteraction newNoteButton = onView(anyOf(withId(R.id.fab_new_note), withId(R.id.new_note)));
newNoteButton.perform(click());

ViewInteraction appCompatEditText = onView(
withId(R.id.titleEdit));
Expand All @@ -284,57 +255,21 @@ public void openCloseOpenClose() {
ViewInteraction appCompatEditText14 = onView(
allOf(withId(R.id.bodyEdit)));
appCompatEditText14.perform(scrollTo(), replaceText("body2"), closeSoftKeyboard());
pressBack();

ViewInteraction recyclerView = onView(
allOf(withId(R.id.list),
withParent(allOf(withId(R.id.noteListFrag),
withParent(withId(R.id.rootView)))),
isDisplayed()));
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
recyclerView.perform(actionOnItemAtPosition(0, click()));
pressBack();
}

if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) {
pressBack();
}

private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {

return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
ViewInteraction recyclerView = onView(
allOf(withId(R.id.list_note), isDisplayed()));

@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
int i = 0;
do {
recyclerView.perform(actionOnItemAtPosition(0, click()));
if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) {
pressBack();
}
};
i++;
} while (i < 10);
}

}
39 changes: 39 additions & 0 deletions app/src/androidTest/java/org/standardnotes/notes/TestHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.standardnotes.notes;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class TestHelper {

public static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {

return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}

@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}

public static boolean isScreenW600dp(Activity activity) {
DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();
float widthDp = displayMetrics.widthPixels / displayMetrics.density;
return widthDp >= 600;
}
}
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".NoteActivity"
android:label="@string/title_activity_note"
android:windowSoftInputMode="stateHidden|adjustResize"
android:theme="@style/AppTheme.NoActionBar.Transparent"/>
<activity
android:name=".TagListActivity"
android:label="@string/title_tags" />
Expand Down
Loading