diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java index df43bad68..9994ee62f 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java @@ -93,7 +93,7 @@ public class BaseUIAutomatorTest h1.setColor(5); habitList.update(h1); - Habit h2 = fixtures.createEmptyHabit(); + Habit h2 = fixtures.createShortHabit(); h2.setName("Track time"); h2.setDescription("Did you track your time?"); h2.setColor(5); diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.java index cfa5916b1..dd9abeffe 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.java @@ -26,10 +26,12 @@ import org.isoron.uhabits.*; import org.junit.*; import org.junit.runner.*; +import static org.isoron.uhabits.acceptance.steps.CommonSteps.Screen.*; import static org.isoron.uhabits.acceptance.steps.CommonSteps.*; import static org.isoron.uhabits.acceptance.steps.EditHabitSteps.*; import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.*; import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.*; +import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.EDIT; @RunWith(AndroidJUnit4.class) @LargeTest @@ -39,12 +41,18 @@ public class HabitsTest extends BaseUIAutomatorTest public void shouldCreateHabit() throws Exception { launchApp(); - clickMenu(CREATE_HABIT); + + verifyShowsScreen(LIST_HABITS); + clickMenu(ADD); + + verifyShowsScreen(EDIT_HABIT); typeName("Hello world"); typeQuestion("Did you say hello to the world today?"); pickFrequency("Every week"); pickColor(5); clickSave(); + + verifyShowsScreen(LIST_HABITS); verifyDisplaysText("Hello world"); } @@ -52,7 +60,10 @@ public class HabitsTest extends BaseUIAutomatorTest public void shouldShowHabitStatistics() throws Exception { launchApp(); + verifyShowsScreen(LIST_HABITS); clickText("Track time"); + + verifyShowsScreen(SHOW_HABIT); verifyDisplayGraphs(); } @@ -60,6 +71,8 @@ public class HabitsTest extends BaseUIAutomatorTest public void shouldDeleteHabit() throws Exception { launchApp(); + + verifyShowsScreen(LIST_HABITS); longClickText("Track time"); clickMenu(DELETE); clickOK(); @@ -70,11 +83,17 @@ public class HabitsTest extends BaseUIAutomatorTest public void shouldEditHabit() throws Exception { launchApp(); + + verifyShowsScreen(LIST_HABITS); longClickText("Track time"); - clickMenu(EDIT_HABIT); + clickMenu(EDIT); + + verifyShowsScreen(EDIT_HABIT); typeName("Take a walk"); typeQuestion("Did you take a walk today?"); clickSave(); + + verifyShowsScreen(LIST_HABITS); verifyDisplaysText("Take a walk"); verifyDoesNotDisplayText("Track time"); } @@ -83,14 +102,24 @@ public class HabitsTest extends BaseUIAutomatorTest public void shouldEditHabit_fromStatisticsScreen() throws Exception { launchApp(); + + verifyShowsScreen(LIST_HABITS); clickText("Track time"); - clickMenu(EDIT_HABIT); + + verifyShowsScreen(SHOW_HABIT); + clickMenu(EDIT); + + verifyShowsScreen(EDIT_HABIT); typeName("Take a walk"); typeQuestion("Did you take a walk today?"); pickColor(10); clickSave(); + + verifyShowsScreen(SHOW_HABIT); verifyDisplaysText("Take a walk"); pressBack(); + + verifyShowsScreen(LIST_HABITS); verifyDisplaysText("Take a walk"); verifyDoesNotDisplayText("Track time"); } @@ -99,15 +128,49 @@ public class HabitsTest extends BaseUIAutomatorTest public void shouldArchiveAndUnarchiveHabits() throws Exception { launchApp(); + + verifyShowsScreen(LIST_HABITS); longClickText("Track time"); clickMenu(ARCHIVE); verifyDoesNotDisplayText("Track time"); - clickMenu(HIDE_ARCHIVED); + clickMenu(TOGGLE_ARCHIVED); verifyDisplaysText("Track time"); longClickText("Track time"); clickMenu(UNARCHIVE); - clickMenu(HIDE_ARCHIVED); + clickMenu(TOGGLE_ARCHIVED); + verifyDisplaysText("Track time"); + } + + @Test + public void shouldToggleCheckmarksAndUpdateScore() throws Exception + { + launchApp(); + verifyShowsScreen(LIST_HABITS); + longPressCheckmarks("Wake up early", 2); + clickText("Wake up early"); + + verifyShowsScreen(SHOW_HABIT); + verifyDisplaysText("10%"); + } + + @Test + public void shouldHideCompleted() throws Exception + { + launchApp(); + verifyShowsScreen(LIST_HABITS); + verifyDisplaysText("Track time"); + verifyDisplaysText("Wake up early"); + + clickMenu(TOGGLE_COMPLETED); + verifyDoesNotDisplayText("Track time"); + verifyDisplaysText("Wake up early"); + + longPressCheckmarks("Wake up early", 1); + verifyDoesNotDisplayText("Wake up early"); + + clickMenu(TOGGLE_COMPLETED); verifyDisplaysText("Track time"); + verifyDisplaysText("Wake up early"); } } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.java index d41d6f5c0..0cbabda45 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.java @@ -26,6 +26,7 @@ import android.support.test.uiautomator.*; import android.support.v7.widget.*; import org.isoron.uhabits.*; +import org.isoron.uhabits.R; import org.isoron.uhabits.activities.habits.list.*; import static android.support.test.espresso.Espresso.*; @@ -124,4 +125,27 @@ public class CommonSteps extends BaseUIAutomatorTest device.waitForIdle(); assertTrue(device.findObject(new UiSelector().text(url)).exists()); } + + public enum Screen + { + LIST_HABITS, SHOW_HABIT, EDIT_HABIT + } + + public static void verifyShowsScreen(Screen screen) + { + switch(screen) + { + case LIST_HABITS: + onView(withId(R.id.header)).check(matches(isDisplayed())); + break; + + case SHOW_HABIT: + onView(withId(R.id.subtitleCard)).check(matches(isDisplayed())); + break; + + case EDIT_HABIT: + onView(withId(R.id.tvDescription)).check(matches(isDisplayed())); + break; + } + } } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/ListHabitsSteps.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/ListHabitsSteps.java index f3328d146..0815fa59c 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/ListHabitsSteps.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/ListHabitsSteps.java @@ -35,7 +35,7 @@ import static android.support.test.espresso.action.ViewActions.*; import static android.support.test.espresso.matcher.ViewMatchers.*; import static org.hamcrest.CoreMatchers.*; import static org.isoron.uhabits.BaseUIAutomatorTest.device; -import static org.isoron.uhabits.acceptance.steps.CommonSteps.clickText; +import static org.isoron.uhabits.acceptance.steps.CommonSteps.*; public abstract class ListHabitsSteps { @@ -55,11 +55,11 @@ public abstract class ListHabitsSteps clickTextInsideOverflowMenu(R.string.settings); break; - case CREATE_HABIT: + case ADD: clickViewWithId(R.id.actionAdd); break; - case EDIT_HABIT: + case EDIT: clickViewWithId(R.id.action_edit_habit); break; @@ -75,10 +75,15 @@ public abstract class ListHabitsSteps clickTextInsideOverflowMenu(R.string.unarchive); break; - case HIDE_ARCHIVED: + case TOGGLE_ARCHIVED: clickViewWithId(R.id.action_filter); clickText(R.string.hide_archived); break; + + case TOGGLE_COMPLETED: + clickViewWithId(R.id.action_filter); + clickText(R.string.hide_completed); + break; } } @@ -86,10 +91,10 @@ public abstract class ListHabitsSteps { UiObject toolbar = device.findObject( new UiSelector().resourceId("org.isoron.uhabits:id/toolbar")); - if(toolbar.exists()) + if (toolbar.exists()) { - onView(allOf(withContentDescription("More options"), withParent - (withParent(withId(R.id.toolbar))))).perform(click()); + onView(allOf(withContentDescription("More options"), + withParent(withParent(withId(R.id.toolbar))))).perform(click()); } else { @@ -104,7 +109,7 @@ public abstract class ListHabitsSteps onView(withId(id)).perform(click()); } - private static ViewAction longClickEveryDescendantWithClass(Class cls) + private static ViewAction longClickDescendantWithClass(Class cls, int count) { return new ViewAction() { @@ -126,6 +131,7 @@ public abstract class ListHabitsSteps { LinkedList stack = new LinkedList<>(); if (view instanceof ViewGroup) stack.push((ViewGroup) view); + int countRemaining = count; while (!stack.isEmpty()) { @@ -134,10 +140,11 @@ public abstract class ListHabitsSteps { View v = vg.getChildAt(i); if (v instanceof ViewGroup) stack.push((ViewGroup) v); - if (cls.isInstance(v)) + if (cls.isInstance(v) && countRemaining > 0) { v.performLongClick(); uiController.loopMainThreadUntilIdle(); + countRemaining--; } } } @@ -145,17 +152,18 @@ public abstract class ListHabitsSteps }; } - public static void longPressCheckmarks(String habit) + public static void longPressCheckmarks(String habit, int count) { CommonSteps.scrollToText(habit); onView(allOf(hasDescendant(withText(habit)), withClassName(endsWith("HabitCardView")))).perform( - longClickEveryDescendantWithClass(CheckmarkButtonView.class)); + longClickDescendantWithClass(CheckmarkButtonView.class, count)); + device.waitForIdle(); } public enum MenuItem { - ABOUT, HELP, SETTINGS, EDIT_HABIT, DELETE, ARCHIVE, HIDE_ARCHIVED, - UNARCHIVE, CREATE_HABIT + ABOUT, HELP, SETTINGS, EDIT, DELETE, ARCHIVE, TOGGLE_ARCHIVED, + UNARCHIVE, TOGGLE_COMPLETED, ADD } } diff --git a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java index 229959fca..fc1fc4cd5 100644 --- a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java +++ b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java @@ -33,8 +33,6 @@ public abstract class ScoreList implements Iterable protected ModelObservable observable; - protected Double todayValue = null; - /** * Creates a new ScoreList for the given habit. *

@@ -71,8 +69,7 @@ public abstract class ScoreList implements Iterable */ public double getTodayValue() { - if(todayValue == null) todayValue = getValue(DateUtils.getStartOfToday()); - return todayValue; + return getValue(DateUtils.getStartOfToday()); } /** diff --git a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/memory/MemoryScoreList.java b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/memory/MemoryScoreList.java index 66e228d3f..3c335ca1f 100644 --- a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/memory/MemoryScoreList.java +++ b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/memory/MemoryScoreList.java @@ -78,7 +78,6 @@ public class MemoryScoreList extends ScoreList list.removeAll(discard); - todayValue = null; getObservable().notifyListeners(); }