mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Test unarchiving habits
This commit is contained in:
@@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Á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;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.test.InstrumentationRegistry;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static android.support.test.espresso.Espresso.onData;
|
||||||
|
import static android.support.test.espresso.Espresso.onView;
|
||||||
|
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
|
||||||
|
import static android.support.test.espresso.Espresso.pressBack;
|
||||||
|
import static android.support.test.espresso.action.ViewActions.click;
|
||||||
|
import static android.support.test.espresso.action.ViewActions.longClick;
|
||||||
|
import static android.support.test.espresso.action.ViewActions.replaceText;
|
||||||
|
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||||
|
import static org.hamcrest.Matchers.allOf;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.isoron.uhabits.HabitMatchers.containsHabit;
|
||||||
|
import static org.isoron.uhabits.HabitMatchers.withName;
|
||||||
|
|
||||||
|
public class MainActivityActions
|
||||||
|
{
|
||||||
|
public static String addHabit()
|
||||||
|
{
|
||||||
|
return addHabit(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addHabit(boolean openDialogs)
|
||||||
|
{
|
||||||
|
String name = "New Habit " + new Random().nextInt(1000000);
|
||||||
|
String description = "Did you perform your new habit today?";
|
||||||
|
String num = "4";
|
||||||
|
String den = "8";
|
||||||
|
|
||||||
|
onView(withId(R.id.action_add))
|
||||||
|
.perform(click());
|
||||||
|
|
||||||
|
typeHabitData(name, description, num, den);
|
||||||
|
|
||||||
|
if(openDialogs)
|
||||||
|
{
|
||||||
|
onView(withId(R.id.buttonPickColor))
|
||||||
|
.perform(click());
|
||||||
|
pressBack();
|
||||||
|
onView(withId(R.id.inputReminderTime))
|
||||||
|
.perform(click());
|
||||||
|
onView(withText("Done"))
|
||||||
|
.perform(click());
|
||||||
|
onView(withId(R.id.inputReminderDays))
|
||||||
|
.perform(click());
|
||||||
|
onView(withText("OK"))
|
||||||
|
.perform(click());
|
||||||
|
}
|
||||||
|
|
||||||
|
onView(withId(R.id.buttonSave))
|
||||||
|
.perform(click());
|
||||||
|
|
||||||
|
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
||||||
|
.onChildView(withId(R.id.label));
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void typeHabitData(String name, String description, String num, String den)
|
||||||
|
{
|
||||||
|
onView(withId(R.id.input_name))
|
||||||
|
.perform(replaceText(name));
|
||||||
|
onView(withId(R.id.input_description))
|
||||||
|
.perform(replaceText(description));
|
||||||
|
onView(withId(R.id.input_freq_num))
|
||||||
|
.perform(replaceText(num));
|
||||||
|
onView(withId(R.id.input_freq_den))
|
||||||
|
.perform(replaceText(den));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void selectHabits(List<String> names)
|
||||||
|
{
|
||||||
|
boolean first = true;
|
||||||
|
for(String name : names)
|
||||||
|
{
|
||||||
|
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
||||||
|
.onChildView(withId(R.id.label))
|
||||||
|
.perform(first ? longClick() : click());
|
||||||
|
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertHabitsDontExist(List<String> names)
|
||||||
|
{
|
||||||
|
for(String name : names)
|
||||||
|
onView(withId(R.id.listView))
|
||||||
|
.check(matches(not(containsHabit(withName(name)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertHabitExists(String name)
|
||||||
|
{
|
||||||
|
List<String> names = new LinkedList<>();
|
||||||
|
names.add(name);
|
||||||
|
assertHabitsExist(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertHabitsExist(List<String> names)
|
||||||
|
{
|
||||||
|
for(String name : names)
|
||||||
|
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
||||||
|
.check(matches(isDisplayed()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteHabit(String name)
|
||||||
|
{
|
||||||
|
LinkedList<String> names = new LinkedList<>();
|
||||||
|
names.add(name);
|
||||||
|
deleteHabits(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteHabits(List<String> names)
|
||||||
|
{
|
||||||
|
Context context = InstrumentationRegistry.getTargetContext();
|
||||||
|
|
||||||
|
selectHabits(names);
|
||||||
|
|
||||||
|
openActionBarOverflowOrOptionsMenu(context);
|
||||||
|
|
||||||
|
onView(withText(R.string.delete))
|
||||||
|
.perform(click());
|
||||||
|
onView(withText("OK"))
|
||||||
|
.perform(click());
|
||||||
|
|
||||||
|
assertHabitsDontExist(names);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,10 +20,8 @@ import java.util.Random;
|
|||||||
import static android.support.test.espresso.Espresso.onData;
|
import static android.support.test.espresso.Espresso.onData;
|
||||||
import static android.support.test.espresso.Espresso.onView;
|
import static android.support.test.espresso.Espresso.onView;
|
||||||
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
|
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
|
||||||
import static android.support.test.espresso.Espresso.pressBack;
|
|
||||||
import static android.support.test.espresso.action.ViewActions.click;
|
import static android.support.test.espresso.action.ViewActions.click;
|
||||||
import static android.support.test.espresso.action.ViewActions.longClick;
|
import static android.support.test.espresso.action.ViewActions.longClick;
|
||||||
import static android.support.test.espresso.action.ViewActions.replaceText;
|
|
||||||
import static android.support.test.espresso.action.ViewActions.scrollTo;
|
import static android.support.test.espresso.action.ViewActions.scrollTo;
|
||||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
@@ -35,10 +33,16 @@ import static org.hamcrest.Matchers.allOf;
|
|||||||
import static org.hamcrest.Matchers.endsWith;
|
import static org.hamcrest.Matchers.endsWith;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
import static org.isoron.uhabits.HabitMatchers.containsHabit;
|
|
||||||
import static org.isoron.uhabits.HabitMatchers.withName;
|
import static org.isoron.uhabits.HabitMatchers.withName;
|
||||||
import static org.isoron.uhabits.HabitViewActions.toggleAllCheckmarks;
|
import static org.isoron.uhabits.HabitViewActions.toggleAllCheckmarks;
|
||||||
|
import static org.isoron.uhabits.MainActivityActions.addHabit;
|
||||||
|
import static org.isoron.uhabits.MainActivityActions.assertHabitExists;
|
||||||
|
import static org.isoron.uhabits.MainActivityActions.assertHabitsDontExist;
|
||||||
|
import static org.isoron.uhabits.MainActivityActions.assertHabitsExist;
|
||||||
|
import static org.isoron.uhabits.MainActivityActions.deleteHabit;
|
||||||
|
import static org.isoron.uhabits.MainActivityActions.deleteHabits;
|
||||||
|
import static org.isoron.uhabits.MainActivityActions.selectHabits;
|
||||||
|
import static org.isoron.uhabits.MainActivityActions.typeHabitData;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@@ -63,116 +67,6 @@ public class MainActivityTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String addHabit()
|
|
||||||
{
|
|
||||||
return addHabit(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String addHabit(boolean openDialogs)
|
|
||||||
{
|
|
||||||
String name = "New Habit " + new Random().nextInt(1000000);
|
|
||||||
String description = "Did you perform your new habit today?";
|
|
||||||
String num = "4";
|
|
||||||
String den = "8";
|
|
||||||
|
|
||||||
onView(withId(R.id.action_add))
|
|
||||||
.perform(click());
|
|
||||||
|
|
||||||
typeHabitData(name, description, num, den);
|
|
||||||
|
|
||||||
if(openDialogs)
|
|
||||||
{
|
|
||||||
onView(withId(R.id.buttonPickColor))
|
|
||||||
.perform(click());
|
|
||||||
pressBack();
|
|
||||||
onView(withId(R.id.inputReminderTime))
|
|
||||||
.perform(click());
|
|
||||||
onView(withText("Done"))
|
|
||||||
.perform(click());
|
|
||||||
onView(withId(R.id.inputReminderDays))
|
|
||||||
.perform(click());
|
|
||||||
onView(withText("OK"))
|
|
||||||
.perform(click());
|
|
||||||
}
|
|
||||||
|
|
||||||
onView(withId(R.id.buttonSave))
|
|
||||||
.perform(click());
|
|
||||||
|
|
||||||
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
|
||||||
.onChildView(withId(R.id.label));
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void typeHabitData(String name, String description, String num, String den)
|
|
||||||
{
|
|
||||||
onView(withId(R.id.input_name))
|
|
||||||
.perform(replaceText(name));
|
|
||||||
onView(withId(R.id.input_description))
|
|
||||||
.perform(replaceText(description));
|
|
||||||
onView(withId(R.id.input_freq_num))
|
|
||||||
.perform(replaceText(num));
|
|
||||||
onView(withId(R.id.input_freq_den))
|
|
||||||
.perform(replaceText(den));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void selectHabits(List<String> names)
|
|
||||||
{
|
|
||||||
boolean first = true;
|
|
||||||
for(String name : names)
|
|
||||||
{
|
|
||||||
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
|
||||||
.onChildView(withId(R.id.label))
|
|
||||||
.perform(first ? longClick() : click());
|
|
||||||
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertHabitsDontExist(List<String> names)
|
|
||||||
{
|
|
||||||
for(String name : names)
|
|
||||||
onView(withId(R.id.listView))
|
|
||||||
.check(matches(not(containsHabit(withName(name)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertHabitExists(String name)
|
|
||||||
{
|
|
||||||
List<String> names = new LinkedList<>();
|
|
||||||
names.add(name);
|
|
||||||
assertHabitsExist(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertHabitsExist(List<String> names)
|
|
||||||
{
|
|
||||||
for(String name : names)
|
|
||||||
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
|
||||||
.check(matches(isDisplayed()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteHabit(String name)
|
|
||||||
{
|
|
||||||
LinkedList<String> names = new LinkedList<>();
|
|
||||||
names.add(name);
|
|
||||||
deleteHabits(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteHabits(List<String> names)
|
|
||||||
{
|
|
||||||
Context context = InstrumentationRegistry.getTargetContext();
|
|
||||||
|
|
||||||
selectHabits(names);
|
|
||||||
|
|
||||||
openActionBarOverflowOrOptionsMenu(context);
|
|
||||||
|
|
||||||
onView(withText(R.string.delete))
|
|
||||||
.perform(click());
|
|
||||||
onView(withText("OK"))
|
|
||||||
.perform(click());
|
|
||||||
|
|
||||||
assertHabitsDontExist(names);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testArchiveHabits()
|
public void testArchiveHabits()
|
||||||
{
|
{
|
||||||
@@ -187,6 +81,15 @@ public class MainActivityTest
|
|||||||
.perform(click());
|
.perform(click());
|
||||||
assertHabitsDontExist(names);
|
assertHabitsDontExist(names);
|
||||||
|
|
||||||
|
openActionBarOverflowOrOptionsMenu(context);
|
||||||
|
onView(withText(R.string.show_archived))
|
||||||
|
.perform(click());
|
||||||
|
|
||||||
|
assertHabitsExist(names);
|
||||||
|
selectHabits(names);
|
||||||
|
onView(withContentDescription(R.string.unarchive))
|
||||||
|
.perform(click());
|
||||||
|
|
||||||
openActionBarOverflowOrOptionsMenu(context);
|
openActionBarOverflowOrOptionsMenu(context);
|
||||||
onView(withText(R.string.show_archived))
|
onView(withText(R.string.show_archived))
|
||||||
.perform(click());
|
.perform(click());
|
||||||
@@ -198,28 +101,24 @@ public class MainActivityTest
|
|||||||
@Test
|
@Test
|
||||||
public void testAddInvalidHabit()
|
public void testAddInvalidHabit()
|
||||||
{
|
{
|
||||||
|
onView(withId(R.id.action_add))
|
||||||
|
.perform(click());
|
||||||
|
|
||||||
typeHabitData("", "", "15", "7");
|
typeHabitData("", "", "15", "7");
|
||||||
|
|
||||||
onView(withId(R.id.buttonSave)).perform(click());
|
onView(withId(R.id.buttonSave)).perform(click());
|
||||||
onView(withId(R.id.input_name)).check(matches(isDisplayed()));
|
onView(withId(R.id.input_name)).check(matches(isDisplayed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToggleCheckmarks()
|
public void testAddHabitAndToggleCheckmarks()
|
||||||
{
|
{
|
||||||
String name = addHabit();
|
String name = addHabit(true);
|
||||||
|
|
||||||
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
||||||
.onChildView(withId(R.id.llButtons))
|
.onChildView(withId(R.id.llButtons))
|
||||||
.perform(toggleAllCheckmarks());
|
.perform(toggleAllCheckmarks());
|
||||||
|
|
||||||
deleteHabit(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAddHabit()
|
|
||||||
{
|
|
||||||
String name = addHabit(true);
|
|
||||||
|
|
||||||
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
|
||||||
.onChildView(withId(R.id.label))
|
.onChildView(withId(R.id.label))
|
||||||
.perform(click());
|
.perform(click());
|
||||||
|
|||||||
Reference in New Issue
Block a user