Skip to content

Commit

Permalink
creating UI test for blank description
Browse files Browse the repository at this point in the history
  • Loading branch information
Rechee committed Jan 9, 2020
1 parent 1714cf8 commit 47edea4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public class BaseUserInterfaceTest
{
private static final String PKG = "org.isoron.uhabits";
public static final String EMPTY_DESCRIPTION_HABIT_NAME = "Read books";

public static UiDevice device;

Expand Down Expand Up @@ -97,24 +98,28 @@ private void resetState() throws Exception
Habit h1 = fixtures.createEmptyHabit();
h1.setName("Wake up early");
h1.setQuestion("Did you wake up early today?");
h1.setDescription("test description 1");
h1.setColor(5);
habitList.update(h1);

Habit h2 = fixtures.createShortHabit();
h2.setName("Track time");
h2.setQuestion("Did you track your time?");
h2.setDescription("test description 2");
h2.setColor(5);
habitList.update(h2);

Habit h3 = fixtures.createLongHabit();
h3.setName("Meditate");
h3.setQuestion("Did meditate today?");
h3.setDescription("test description 3");
h3.setColor(10);
habitList.update(h3);

Habit h4 = fixtures.createEmptyHabit();
h4.setName("Read books");
h4.setName(EMPTY_DESCRIPTION_HABIT_NAME);
h4.setQuestion("Did you read books today?");
h4.setDescription("");
h4.setColor(2);
habitList.update(h4);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,12 @@ public void shouldHideCompleted() throws Exception
verifyDisplaysText("Track time");
verifyDisplaysText("Wake up early");
}

@Test
public void shouldHideNotesCard() throws Exception
{
launchApp();
clickText(EMPTY_DESCRIPTION_HABIT_NAME);
verifyShowsScreen(SHOW_HABIT, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,40 @@

package org.isoron.uhabits.acceptance.steps;

import androidx.annotation.StringRes;
import androidx.test.espresso.*;
import androidx.test.espresso.contrib.*;
import androidx.test.uiautomator.*;
import android.view.View;

import androidx.annotation.StringRes;
import androidx.recyclerview.widget.RecyclerView;

import org.isoron.uhabits.*;
import androidx.test.espresso.PerformException;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiSelector;
import androidx.test.uiautomator.Until;

import org.hamcrest.Matcher;
import org.isoron.uhabits.BaseUserInterfaceTest;
import org.isoron.uhabits.R;
import org.isoron.uhabits.activities.habits.list.*;

import static android.os.Build.VERSION.*;
import static androidx.test.espresso.Espresso.*;
import static androidx.test.espresso.action.ViewActions.*;
import static androidx.test.espresso.assertion.PositionAssertions.*;
import static androidx.test.espresso.assertion.ViewAssertions.*;
import static androidx.test.espresso.matcher.ViewMatchers.*;
import static junit.framework.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.isoron.uhabits.activities.habits.list.ListHabitsActivity;

import static android.os.Build.VERSION.SDK_INT;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.PositionAssertions.isBelow;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.Visibility;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.instanceOf;

public class CommonSteps extends BaseUserInterfaceTest
{
Expand Down Expand Up @@ -152,7 +167,11 @@ public enum Screen
LIST_HABITS, SHOW_HABIT, EDIT_HABIT
}

public static void verifyShowsScreen(Screen screen)
public static void verifyShowsScreen(Screen screen) {
verifyShowsScreen(screen, true);
}

public static void verifyShowsScreen(Screen screen, boolean notesCardVisibleExpected)
{
switch(screen)
{
Expand All @@ -162,11 +181,15 @@ public static void verifyShowsScreen(Screen screen)
break;

case SHOW_HABIT:
Matcher<View> noteCardViewMatcher = notesCardVisibleExpected ? isDisplayed() :
withEffectiveVisibility(Visibility.GONE);
onView(withId(R.id.subtitleCard)).check(matches(isDisplayed()));
onView(withId(R.id.notesCard)).check(matches(noteCardViewMatcher));
break;

case EDIT_HABIT:
onView(withId(R.id.tvQuestion)).check(matches(isDisplayed()));
onView(withId(R.id.tvDescription)).check(matches(isDisplayed()));
break;
}
}
Expand Down

0 comments on commit 47edea4

Please sign in to comment.