diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUserInterfaceTest.java similarity index 98% rename from uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java rename to uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUserInterfaceTest.java index 9994ee62f..a6a79b2da 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUIAutomatorTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUserInterfaceTest.java @@ -34,7 +34,7 @@ import java.io.*; import static android.support.test.InstrumentationRegistry.*; import static android.support.test.uiautomator.UiDevice.*; -public class BaseUIAutomatorTest +public class BaseUserInterfaceTest { private static final String PKG = "org.isoron.uhabits"; diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/AboutTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/AboutTest.java index bf1631667..9ae821e39 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/AboutTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/AboutTest.java @@ -32,7 +32,7 @@ import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.*; @RunWith(AndroidJUnit4.class) @LargeTest -public class AboutTest extends BaseUIAutomatorTest +public class AboutTest extends BaseUserInterfaceTest { @Test public void shouldDisplayAboutScreen() 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 dd9abeffe..e76bae1c2 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 @@ -35,7 +35,7 @@ import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.EDIT; @RunWith(AndroidJUnit4.class) @LargeTest -public class HabitsTest extends BaseUIAutomatorTest +public class HabitsTest extends BaseUserInterfaceTest { @Test public void shouldCreateHabit() throws Exception diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/LinksTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/LinksTest.java index e667e018c..ef5166838 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/LinksTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/LinksTest.java @@ -32,7 +32,7 @@ import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.*; @RunWith(AndroidJUnit4.class) @LargeTest -public class LinksTest extends BaseUIAutomatorTest +public class LinksTest extends BaseUserInterfaceTest { @Test public void shouldLinkToSourceCode() throws Exception diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/WidgetTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/WidgetTest.java new file mode 100644 index 000000000..3035dfd4f --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/WidgetTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2017 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +package org.isoron.uhabits.acceptance; + +import org.isoron.uhabits.*; +import org.junit.*; + +import static org.isoron.uhabits.acceptance.steps.CommonSteps.*; +import static org.isoron.uhabits.acceptance.steps.WidgetSteps.*; +import static org.isoron.uhabits.acceptance.steps.WidgetSteps.clickText; + +public class WidgetTest extends BaseUserInterfaceTest +{ + @Test + public void shouldCreateAndToggleCheckmarkWidget() throws Exception + { + longPressHomeScreen(); + clickWidgets(); + scrollToHabits(); + dragWidgetToHomescreen(); + clickText("Wake up early"); + verifyCheckmarkWidgetIsShown(); + clickCheckmarkWidget(); + + launchApp(); + clickText("Wake up early"); + verifyDisplaysText("5%"); + + pressHome(); + clickCheckmarkWidget(); + + launchApp(); + clickText("Wake up early"); + verifyDisplaysText("0%"); + } +} 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 0cbabda45..b724467bf 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 @@ -36,7 +36,7 @@ import static android.support.test.espresso.matcher.ViewMatchers.*; import static junit.framework.Assert.*; import static org.hamcrest.CoreMatchers.*; -public class CommonSteps extends BaseUIAutomatorTest +public class CommonSteps extends BaseUserInterfaceTest { public static void clickOK() { @@ -73,6 +73,12 @@ public class CommonSteps extends BaseUIAutomatorTest onView(withText(text)).perform(longClick()); } + public static void pressHome() + { + device.pressHome(); + device.waitForIdle(); + } + public static void scrollToText(String text) { try diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.java index 9b4774427..3c45061d3 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.java @@ -26,7 +26,7 @@ import org.isoron.uhabits.*; import static android.support.test.espresso.Espresso.*; import static android.support.test.espresso.action.ViewActions.*; import static android.support.test.espresso.matcher.ViewMatchers.*; -import static org.isoron.uhabits.BaseUIAutomatorTest.device; +import static org.isoron.uhabits.BaseUserInterfaceTest.device; public class EditHabitSteps { 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 0815fa59c..fbee024be 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 @@ -34,7 +34,7 @@ import static android.support.test.espresso.Espresso.*; 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.BaseUserInterfaceTest.device; import static org.isoron.uhabits.acceptance.steps.CommonSteps.*; public abstract class ListHabitsSteps diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/WidgetSteps.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/WidgetSteps.java new file mode 100644 index 000000000..ea3d6ea48 --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/WidgetSteps.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2017 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +package org.isoron.uhabits.acceptance.steps; + +import android.support.test.uiautomator.*; + +import static junit.framework.Assert.*; +import static org.isoron.uhabits.BaseUserInterfaceTest.*; + +public class WidgetSteps +{ + public static void clickCheckmarkWidget() throws Exception + { + device + .findObject( + new UiSelector().resourceId("org.isoron.uhabits:id/imageView")) + .click(); + } + + public static void clickText(String s) throws Exception + { + device.findObject(new UiSelector().text(s)).click(); + } + + public static void clickWidgets() throws Exception + { + device.findObject(new UiSelector().text("WIDGETS")).click(); + } + + public static void dragWidgetToHomescreen() throws Exception + { + int height = device.getDisplayHeight(); + int width = device.getDisplayWidth(); + device + .findObject(new UiSelector().text("Checkmark")) + .dragTo(width / 2, height / 2, 8); + } + + public static void longPressHomeScreen() throws Exception + { + device.pressHome(); + device.waitForIdle(); + device + .findObject(new UiSelector().resourceId( + "com.google.android.apps.nexuslauncher:id/workspace")) + .longClick(); + } + + public static void scrollToHabits() throws Exception + { + new UiScrollable(new UiSelector().resourceId( + "com.google.android.apps.nexuslauncher:id/widgets_list_view")).scrollIntoView( + new UiSelector().text("Habits")); + + } + + public static void verifyCheckmarkWidgetIsShown() throws Exception + { + assertTrue(device + .findObject( + new UiSelector().resourceId("org.isoron.uhabits:id/imageView")) + .exists()); + + assertFalse(device + .findObject(new UiSelector().textStartsWith("Habit deleted")) + .exists()); + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/integration/SavedStateTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/integration/SavedStateTest.java index bb9675813..391e4e37b 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/integration/SavedStateTest.java +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/integration/SavedStateTest.java @@ -32,7 +32,7 @@ import static java.lang.Thread.*; @RunWith(AndroidJUnit4.class) @LargeTest -public class SavedStateTest extends BaseUIAutomatorTest +public class SavedStateTest extends BaseUserInterfaceTest { /** * Make sure that the main activity can be recreated by using