mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Implement widget test
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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%");
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user