From 9604c2697359b1ce1d36f6d6d3ee5e0749ca8794 Mon Sep 17 00:00:00 2001 From: Alinson Xavier Date: Fri, 21 Apr 2017 12:03:55 -0400 Subject: [PATCH] Remove inactive espresso tests; fix other tests --- .../render_explicit_check.png | Bin 551 -> 574 bytes .../render_implicit_check.png | Bin 505 -> 544 bytes .../CheckmarkButtonView/render_unchecked.png | Bin 559 -> 652 bytes .../list/views/CheckmarkButtonViewTest.java | 6 +- .../uhabits/espresso/HabitMatchers.java | 100 ------ .../uhabits/espresso/HabitViewActions.java | 131 -------- .../uhabits/espresso/MainActivityActions.java | 199 ----------- .../org/isoron/uhabits/espresso/MainTest.java | 317 ------------------ .../espresso/ShowHabitActivityActions.java | 37 -- .../isoron/uhabits/espresso/SystemHelper.java | 124 ------- .../commands/UnarchiveHabitsCommandTest.java | 2 +- 11 files changed, 2 insertions(+), 914 deletions(-) delete mode 100644 app/src/androidTest/java/org/isoron/uhabits/espresso/HabitMatchers.java delete mode 100644 app/src/androidTest/java/org/isoron/uhabits/espresso/HabitViewActions.java delete mode 100644 app/src/androidTest/java/org/isoron/uhabits/espresso/MainActivityActions.java delete mode 100644 app/src/androidTest/java/org/isoron/uhabits/espresso/MainTest.java delete mode 100644 app/src/androidTest/java/org/isoron/uhabits/espresso/ShowHabitActivityActions.java delete mode 100644 app/src/androidTest/java/org/isoron/uhabits/espresso/SystemHelper.java diff --git a/app/src/androidTest/assets/views/habits/list/CheckmarkButtonView/render_explicit_check.png b/app/src/androidTest/assets/views/habits/list/CheckmarkButtonView/render_explicit_check.png index 1f53b9ae5523ae670b07036b24f0c951af0bfbb5..16e6d1f04bc582d32b36b0a63eed7a57fea8b6d9 100644 GIT binary patch literal 574 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGoEX7WqAsj$Z!;#X#z`*#`)5S5Q zV$R!}8?%KIWsZG(zq)s0ljvXXKkO{(7oCh(JP5Gn3}X-H_H2`$qQ=L^b;~to4o^ve z2fMquy1VRLmDvh20%p&1mbo>{I%xK{cWdvTpLY86$KB6&em^TPLB(?tCi97#lG-Ko}*LM;JnegMq+P<>AIL- zr+)L#?~=-%^LRV+t={Sbr+f0vUxuHXtYY6^w8TceOD^JlnpVGdvdZ%E z*j}3&joW+~Yv(ARsW~5cacTTc$4NXDmv(rclDc_5;Ma$RIjjs@UeCRFbN)(isa-8! zEGM?}8w7u0sGs?_aQ4BNsZ&~eL_fEb*gfaF*utNBhtc4dqTHF%BCiudp+5qyF+GU) z>d>pvC}!L+UuY4J{HZtwpCG3#51n~f9pX3x+xa(&Fg*6^u&e2K`M;sJ-&ss=-R4kR s=FI-YT^_Yxy)PzX3x1Wq^Xr&5nQxAMy6CDbFhMYQy85}Sb4q9e0N|zl6951J delta 544 zcmdnTvYbV+Gr-TCmrII^fq{Y7)59eQNC$v02OE&=6a2JxqM~s9Jx>?Mkcv5PZ*24z zPLw$Q@qO?D*2zgv^gqfg7$!Ql@i{$e$WwW7per--9&4sJyU!6<^%#|lM;7|{%z5$x&v5eav$cJ_}es;5Ik^a;vIz?w*Q!+jqRs zdvxa~hnjTM9Nj&;10R)qlRaki!$0L{yTx_69sA;9kJodpXOH{7&-MEK#oInVRXcW8 z*zUnQx6Ugyyw6FDl%|ssMjTHi)y`RJ@t4Z)D)t};(HoRCNV6E`SHtEnu zh1LcGizJ|ZQyU6wA4wc(p7M|1#%AY&qVLM-OQUDxU;MiIO4+_+a^5Z&An6C|yPrp6 ULu!&dfsxMO>FVdQ&MBb@0C~azKmY&$ diff --git a/app/src/androidTest/assets/views/habits/list/CheckmarkButtonView/render_implicit_check.png b/app/src/androidTest/assets/views/habits/list/CheckmarkButtonView/render_implicit_check.png index 2570ca8571bcc47206b480342b19ef2ed645ba0d..25a6b0a1efb312d8cacfb42955fe3d11e6be3d81 100644 GIT binary patch literal 544 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGoEX7WqAsj$Z!;#X#z`%Ij)5S5Q zV$R!ZhFQ{%46P5%C*~ytu_`Jmui<97^n;~sOJ-4*NMSNhW5Z+NClYy+jy*Uw_2ACN zrnK;!RU(FbtI}qACLYyE44;;K(>nQo{PL?}{_iuxCIM~20zy(Fw@pvIx!vY``R#L; zj%<;AurDH;zt`}+xPJ4J{^o-T`_KB6&f6;c!0u1*zLKx5w>Mv_%g_#<>|V~4b!xqq z_1tp{uD||UaUsClW|eS(^Uq0NvhC)_+eIu8b+J8AVs$s_Yh3o*<jJsCi)vUzT{k|QV{LRS$J?s-++Mj}H~ZP|;-~C?Gyh!c_kU*#ENtTHZ|&~PYgnXV zc52ffrI%OlXDhaR-lS9h%FSbEjpiZu3B~U`rhZaADe-yJ?YDJvebmmcz8OGNH!SmX!%SSiw594@vN1|BkijA>?P!5@wJ8rcOmqy#@Id?q;>9oSv>E?+}&Ql5%>wkc2~&mD8oC z-km%OSNkT^{0wqp_PDNGGwsVEiOu)lfA_z2js;67Gkh@l%P6<-^UaIQS9gHqJzf1= J);T3K0RX41>P!Ft delta 498 zcmZ3$@{?JyGr-TCmrII^fq{Y7)59eQNC$v02OE&=6a2JxqM~s922U5qkcv5PuiJVt zJIb_uEZ^k1ZMul#Cq}V(4jV2Ab8Iu4cgTs`{(#d3;R+tzErK~~S}Ir)%@n=4xSP!y zTY6dp#XOU)Y%o6b`SmyEZ|4u6(bHxG8jk=Cm0pvcD0oh4Puslnc{bbQ*9YrU*V-B% zd(+1^cgf`Xs=akHzRR@kk+pXFtQW zKg_NuI%j*l@Xw^@K5@*;GI!a$-h1uV<;;&NrHeIg=}q-oUo4TE7PqZn_uV)N9=7R| zuBqG=?>>6AXy+f3m;VCyWX9jhTNrR-RoH6tV)<{ab)D_wqBGxdDCod2mx)@@O1mp&}`Vezu6Of~IZ<>a(4 za{iw-w65J+er(29&+BuGd6Un~T_VdW=g;*-_J{MqBa{Eswblz8uBe!F+xmEA*&(kf(--80#)78&qol`;+06#0(`2YX_ diff --git a/app/src/androidTest/assets/views/habits/list/CheckmarkButtonView/render_unchecked.png b/app/src/androidTest/assets/views/habits/list/CheckmarkButtonView/render_unchecked.png index 841cc20e0a7833d5ed27c3e829d3a213191c53e0..5a932660d6f7dc804057f9493ddd35b287490639 100644 GIT binary patch literal 652 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGoEX7WqAsj$Z!;#X#z`*3}>Eakt zG3V_~!~9zg630G1XH{<9=z6z_Bj^WP=H-o9%a(Yzg}gLBbD?$V+kmY}Jh}TACvt4s z-j%Ypzz#Jl5#H3}>5=9ty% zOWl6|ygCG9#x~->hKEc4kYtoZTXY|gj5q1sK&CU^VH8p-chH0&Kg0V zmonuX3A&n9y64P}pp{SN?V5Hxq(gGT=ehqKuBDxIzsJ5I>vOOx=fT$u*K+GtaVSG^8Qb5rya(di{t&BRQs7H zEOA@>@#>j#U-Q*UHk(Cea_q9NnY<+0xcYvE$-dlG_ev{vbNK(BU+;-6Y8y=dGNx%V Vd`^6Oc?KxjJzf1=);T3K0RUCTA(j9D literal 559 zcmeAS@N?(olHy`uVBq!ia0vp^0U*r51|<6gKdl8)EX7WqAsj$Z!;#X#z`*#-)5S5Q zV$RzehS|3rB#wQ2zScBDSFxE*k>@7|=i7)6FOGVD5;ZRQILYvVq0&zdMrD%>j?Qpi zq3a8cIKnsGk@_w2>%Z?azZ3fW<;$l}23mjwBxFCwHmE$UtP2gjx^>CZ5-Z*Bw!7oj zJ9~C3aKt^bsI&EN{k!jnp2F!(k+IiT&b;d#CF)vu^Lvi*cB9R|cdeVhNoV%l^_TME z!V{*Y8b80|?-{>6`P|Ou20YILMfPr;uiN!#lg?>&XT2F$KSU6@NxO15THwD{uP|3GV`WysQ@Aiy(-a?*- zp2{2nzkUlG7n)}>iDBtsXPMxNOB_-!&*zC~PtdJlu~Twi&}->byn55C>?KR@GkUU{ zUb1h?EA%`1+&#rmBu=93Gte8i6?U7vkC?OM5OW2$0Y{U#r+jSj+qIIe7jHXs$e-Q4 z=Yv>+%<=VUW$Kxi<=$Ie|JJg@aI^J%@zrs^52$#`oqZE_)~n>)(pve}u#QaQFYkWq o1xPtcE7!i$u0@Ik28I`3xKox2GI>Vjd - * - * 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.espresso; - -import android.preference.Preference; -import android.view.View; -import android.widget.Adapter; -import android.widget.AdapterView; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; -import org.isoron.uhabits.models.Habit; - -public class HabitMatchers -{ - public static Matcher withName(final String name) - { - return new TypeSafeMatcher() - { - @Override - public boolean matchesSafely(Habit habit) - { - return habit.getName().equals(name); - } - - @Override - public void describeTo(Description description) - { - description.appendText("name should be ").appendText(name); - } - - @Override - public void describeMismatchSafely(Habit habit, Description description) - { - description.appendText("was ").appendText(habit.getName()); - } - }; - } - - public static Matcher containsHabit(final Matcher matcher) - { - return new TypeSafeMatcher() - { - @Override - protected boolean matchesSafely(View view) - { - Adapter adapter = ((AdapterView) view).getAdapter(); - for (int i = 0; i < adapter.getCount(); i++) - if (matcher.matches(adapter.getItem(i))) return true; - - return false; - } - - @Override - public void describeTo(Description description) - { - description.appendText("with class name: "); - matcher.describeTo(description); - } - }; - } - - public static Matcher isPreferenceWithText(final String text) - { - return (Matcher) new BaseMatcher() - { - @Override - public boolean matches(Object o) - { - if(!(o instanceof Preference)) return false; - return o.toString().contains(text); - } - - @Override - public void describeTo(Description description) - { - description.appendText(String.format("is preference with text '%s'", text)); - } - }; - } -} diff --git a/app/src/androidTest/java/org/isoron/uhabits/espresso/HabitViewActions.java b/app/src/androidTest/java/org/isoron/uhabits/espresso/HabitViewActions.java deleted file mode 100644 index 156e3bea8..000000000 --- a/app/src/androidTest/java/org/isoron/uhabits/espresso/HabitViewActions.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2016 Á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.espresso; - -import android.support.test.espresso.UiController; -import android.support.test.espresso.ViewAction; -import android.support.test.espresso.action.CoordinatesProvider; -import android.support.test.espresso.action.GeneralClickAction; -import android.support.test.espresso.action.GeneralLocation; -import android.support.test.espresso.action.Press; -import android.support.test.espresso.action.Tap; -import android.support.test.espresso.matcher.ViewMatchers; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.TextView; - -import org.hamcrest.Matcher; -import org.isoron.uhabits.R; - -import java.security.InvalidParameterException; -import java.util.Random; - -public class HabitViewActions -{ - public static ViewAction toggleAllCheckmarks() - { - final GeneralClickAction clickAction = - new GeneralClickAction(Tap.LONG, GeneralLocation.CENTER, Press.FINGER); - - return new ViewAction() - { - @Override - public Matcher getConstraints() - { - return ViewMatchers.isDisplayed(); - } - - @Override - public String getDescription() - { - return "toggleAllCheckmarks"; - } - - @Override - public void perform(UiController uiController, View view) - { - if (view.getId() != R.id.checkmarkPanel) - throw new InvalidParameterException("View must have id llButtons"); - - LinearLayout llButtons = (LinearLayout) view; - int count = llButtons.getChildCount(); - - for (int i = 0; i < count; i++) - { - TextView tvButton = (TextView) llButtons.getChildAt(i); - clickAction.perform(uiController, tvButton); - } - } - }; - } - - public static ViewAction clickAt(final int x, final int y) - { - return new GeneralClickAction(Tap.SINGLE, new CoordinatesProvider() - { - @Override - public float[] calculateCoordinates(View view) - { - int[] locations = new int[2]; - view.getLocationOnScreen(locations); - - final float locationX = locations[0] + x; - final float locationY = locations[1] + y; - - return new float[]{locationX, locationY}; - } - }, Press.FINGER); - } - - public static ViewAction clickAtRandomLocations(final int count) - { - return new ViewAction() - { - @Override - public Matcher getConstraints() - { - return ViewMatchers.isDisplayed(); - } - - @Override - public String getDescription() - { - return "clickAtRandomLocations"; - } - - @Override - public void perform(UiController uiController, View view) - { - int width = view.getWidth(); - int height = view.getHeight(); - Random random = new Random(); - - for(int i = 0; i < count; i++) - { - int x = random.nextInt(width); - int y = random.nextInt(height); - - ViewAction action = clickAt(x, y); - action.perform(uiController, view); - } - } - }; - } -} diff --git a/app/src/androidTest/java/org/isoron/uhabits/espresso/MainActivityActions.java b/app/src/androidTest/java/org/isoron/uhabits/espresso/MainActivityActions.java deleted file mode 100644 index 2fdd59c19..000000000 --- a/app/src/androidTest/java/org/isoron/uhabits/espresso/MainActivityActions.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2016 Á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.espresso; - -import android.support.test.espresso.*; -import android.support.test.espresso.contrib.*; - -import org.hamcrest.*; -import org.isoron.uhabits.R; -import org.isoron.uhabits.models.*; - -import java.util.*; - -import static android.support.test.espresso.Espresso.*; -import static android.support.test.espresso.Espresso.pressBack; -import static android.support.test.espresso.action.ViewActions.*; -import static android.support.test.espresso.assertion.ViewAssertions.*; -import static android.support.test.espresso.matcher.RootMatchers.*; -import static android.support.test.espresso.matcher.ViewMatchers.Visibility.*; -import static android.support.test.espresso.matcher.ViewMatchers.*; -import static org.hamcrest.Matchers.*; - -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.actionAdd)).perform(click()); - - typeHabitData(name, description, num, den); - - if (openDialogs) - { - onView(withId(R.id.buttonPickColor)).perform(click()); - pressBack(); - onView(withId(R.id.tvReminderTime)).perform(click()); - onView(withText("Done")).perform(click()); - onView(withId(R.id.tvReminderDays)).perform(click()); - onView(withText("OK")).perform(click()); - } - - onView(withId(R.id.buttonSave)).perform(click()); - - onData(Matchers.allOf(is(instanceOf(Habit.class)), - HabitMatchers.withName(name))).onChildView(withId(R.id.label)); - - return name; - } - - public static void assertHabitExists(String name) - { - List names = new LinkedList<>(); - names.add(name); - assertHabitsExist(names); - } - - public static void assertHabitsDontExist(List names) - { - for (String name : names) - onView(withId(R.id.listView)).check(matches(Matchers.not( - HabitMatchers.containsHabit(HabitMatchers.withName(name))))); - } - - public static void assertHabitsExist(List names) - { - for (String name : names) - onData(Matchers.allOf(is(instanceOf(Habit.class)), - HabitMatchers.withName(name))).check(matches(isDisplayed())); - } - - private static void clickHiddenMenuItem(int stringId) - { - try - { - // Try the ActionMode overflow menu first - onView(allOf(withContentDescription("More options"), withParent( - withParent(withClassName(containsString("Action")))))).perform( - click()); - } - catch (Exception e1) - { - // Try the toolbar overflow menu - onView(allOf(withContentDescription("More options"), withParent( - withParent(withClassName(containsString("Toolbar")))))).perform( - click()); - } - - onView(withText(stringId)).perform(click()); - } - - public static void clickMenuItem(int stringId) - { - try - { - onView(withText(stringId)).perform(click()); - } - catch (Exception e1) - { - try - { - onView(withContentDescription(stringId)).perform(click()); - } - catch (Exception e2) - { - clickHiddenMenuItem(stringId); - } - } - } - - public static void clickSettingsItem(String text) - { - onView(withClassName(containsString("RecyclerView"))).perform( - RecyclerViewActions.actionOnItem( - hasDescendant(withText(containsString(text))), click())); - } - - public static void deleteHabit(String name) - { - deleteHabits(Collections.singletonList(name)); - } - - public static void deleteHabits(List names) - { - selectHabits(names); - clickMenuItem(R.string.delete); - onView(withText("OK")).perform(click()); - assertHabitsDontExist(names); - } - - public static void selectHabit(String name) - { - selectHabits(Collections.singletonList(name)); - } - - public static void selectHabits(List names) - { - boolean first = true; - for (String name : names) - { - onData(Matchers.allOf(is(instanceOf(Habit.class)), - HabitMatchers.withName(name))) - .onChildView(withId(R.id.label)) - .perform(first ? longClick() : click()); - - first = false; - } - } - - public static void typeHabitData(String name, - String description, - String num, - String den) - { - onView(withId(R.id.tvName)).perform(replaceText(name)); - onView(withId(R.id.tvDescription)).perform(replaceText(description)); - - try - { - onView(allOf(withId(R.id.spinner), - withEffectiveVisibility(VISIBLE))).perform(click()); - onData(allOf(instanceOf(String.class), startsWith("Custom"))) - .inRoot(isPlatformPopup()) - .perform(click()); - } - catch (NoMatchingViewException e) - { - // ignored - } - - onView(withId(R.id.numerator)).perform(replaceText(num)); - onView(withId(R.id.denominator)).perform(replaceText(den)); - } -} diff --git a/app/src/androidTest/java/org/isoron/uhabits/espresso/MainTest.java b/app/src/androidTest/java/org/isoron/uhabits/espresso/MainTest.java deleted file mode 100644 index f9284b58e..000000000 --- a/app/src/androidTest/java/org/isoron/uhabits/espresso/MainTest.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (C) 2016 Á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.espresso; - -import android.app.*; -import android.content.*; -import android.support.test.*; -import android.support.test.espresso.*; -import android.support.test.espresso.intent.rule.*; -import android.support.test.runner.*; -import android.test.suitebuilder.annotation.*; - -import org.hamcrest.*; -import org.isoron.uhabits.R; -import org.isoron.uhabits.activities.habits.list.*; -import org.isoron.uhabits.models.*; -import org.isoron.uhabits.utils.*; -import org.junit.*; -import org.junit.runner.*; - -import java.util.*; - -import static android.support.test.espresso.Espresso.*; -import static android.support.test.espresso.Espresso.pressBack; -import static android.support.test.espresso.action.ViewActions.*; -import static android.support.test.espresso.assertion.ViewAssertions.*; -import static android.support.test.espresso.intent.Intents.*; -import static android.support.test.espresso.intent.matcher.IntentMatchers.*; -import static android.support.test.espresso.matcher.ViewMatchers.*; -import static org.hamcrest.Matchers.*; -import static org.isoron.uhabits.espresso.HabitViewActions.*; -import static org.isoron.uhabits.espresso.MainActivityActions.*; -import static org.isoron.uhabits.espresso.ShowHabitActivityActions.*; - -@RunWith(AndroidJUnit4.class) -@LargeTest -public class MainTest -{ - private SystemHelper sys; - - @Rule - public IntentsTestRule activityRule = - new IntentsTestRule<>(ListHabitsActivity.class); - - @Before - public void setup() - { - Context context = - InstrumentationRegistry.getInstrumentation().getContext(); - sys = new SystemHelper(context); - sys.disableAllAnimations(); - sys.acquireWakeLock(); - sys.unlockScreen(); - - Instrumentation.ActivityResult okResult = - new Instrumentation.ActivityResult(Activity.RESULT_OK, - new Intent()); - - intending(hasAction(equalTo(Intent.ACTION_SEND))).respondWith(okResult); - intending(hasAction(equalTo(Intent.ACTION_SENDTO))).respondWith( - okResult); - intending(hasAction(equalTo(Intent.ACTION_VIEW))).respondWith(okResult); - - skipTutorial(); - } - - public void skipTutorial() - { - try - { - for (int i = 0; i < 10; i++) - onView(allOf(withClassName(endsWith("AppCompatImageButton")), - isDisplayed())).perform(click()); - } - catch (NoMatchingViewException e) - { - // ignored - } - } - - @After - public void tearDown() - { - sys.releaseWakeLock(); - } - - /** - * User opens menu, clicks about, sees about screen. - */ - @Test - public void testAbout() - { - clickMenuItem(R.string.about); - onView(isRoot()).perform(swipeUp()); - } - - /** - * User creates a habit, toggles a bunch of checkmarks, clicks the habit to - * open the statistics screen, scrolls down to some views, then scrolls the - * views backwards and forwards in time. - */ - @Test - public void testAddHabitAndViewStats() throws InterruptedException - { - String name = addHabit(true); - - onData(Matchers.allOf(is(instanceOf(Habit.class)), - HabitMatchers.withName(name))) - .onChildView(withId(R.id.checkmarkPanel)) - .perform(toggleAllCheckmarks()); - - Thread.sleep(1200); - - onData(Matchers.allOf(is(instanceOf(Habit.class)), - HabitMatchers.withName(name))) - .onChildView(withId(R.id.label)) - .perform(click()); - - onView(withId(R.id.scoreView)).perform(scrollTo(), swipeRight()); - - onView(withId(R.id.frequencyChart)).perform(scrollTo(), swipeRight()); - } - - /** - * User opens the app, clicks the add button, types some bogus information, - * tries to save, dialog displays an error. - */ - @Test - public void testAddInvalidHabit() - { - onView(withId(R.id.actionAdd)).perform(click()); - - typeHabitData("", "", "15", "7"); - - onView(withId(R.id.buttonSave)).perform(click()); - onView(withId(R.id.tvName)).check(matches(isDisplayed())); - } - - /** - * User opens the app, creates some habits, selects them, archives them, - * select 'show archived' on the menu, selects the previously archived - * habits and then deletes them. - */ - @Test - public void testArchiveHabits() - { - List names = new LinkedList<>(); - - for (int i = 0; i < 3; i++) - names.add(addHabit()); - - selectHabits(names); - - clickMenuItem(R.string.archive); - assertHabitsDontExist(names); - - clickMenuItem(R.string.show_archived); - - assertHabitsExist(names); - selectHabits(names); - clickMenuItem(R.string.unarchive); - - clickMenuItem(R.string.show_archived); - - assertHabitsExist(names); - deleteHabits(names); - } - - /** - * User creates a habit, selects the habit, clicks edit button, changes some - * information about the habit, click save button, sees changes on the main - * window, selects habit again, changes color, then deletes the habit. - */ - @Test - public void testEditHabit() - { - String name = addHabit(); - - onData(Matchers.allOf(is(instanceOf(Habit.class)), - HabitMatchers.withName(name))) - .onChildView(withId(R.id.label)) - .perform(longClick()); - - clickMenuItem(R.string.edit); - - String modifiedName = "Modified " + new Random().nextInt(10000); - typeHabitData(modifiedName, "", "1", "1"); - - onView(withId(R.id.buttonSave)).perform(click()); - - assertHabitExists(modifiedName); - - selectHabit(modifiedName); - clickMenuItem(R.string.color_picker_default_title); - pressBack(); - - deleteHabit(modifiedName); - } - - /** - * User creates a habit, opens statistics page, clicks button to edit - * history, adds some checkmarks, closes dialog, sees the modified history - * calendar. - */ - @Test - public void testEditHistory() - { - String name = addHabit(); - - onData(Matchers.allOf(is(instanceOf(Habit.class)), - HabitMatchers.withName(name))) - .onChildView(withId(R.id.label)) - .perform(click()); - - openHistoryEditor(); - onView(withClassName(endsWith("HabitHistoryView"))).perform( - clickAtRandomLocations(20)); - - pressBack(); - onView(withId(R.id.historyChart)).perform(scrollTo(), swipeRight(), - swipeLeft()); - } - - /** - * User creates a habit, opens settings, clicks export as CSV, is asked what - * activity should handle the file. - */ - @Test - public void testExportCSV() - { - addHabit(); - clickMenuItem(R.string.settings); - clickSettingsItem("Export as CSV"); - intended(hasAction(Intent.ACTION_SEND)); - } - - /** - * User creates a habit, exports full backup, deletes the habit, restores - * backup, sees that the previously created habit has appeared back. - */ - @Test - public void testExportImportDB() - { - String name = addHabit(); - - clickMenuItem(R.string.settings); - - String date = - DateFormats.getBackupDateFormat().format(DateUtils.getLocalTime()); - date = date.substring(0, date.length() - 2); - - clickSettingsItem("Export full backup"); - intended(hasAction(Intent.ACTION_SEND)); - - deleteHabit(name); - - clickMenuItem(R.string.settings); - clickSettingsItem("Import data"); - - onData( - allOf(is(instanceOf(String.class)), startsWith("Backups"))).perform( - click()); - - onData( - allOf(is(instanceOf(String.class)), containsString(date))).perform( - click()); - - selectHabit(name); - } - - /** - * User opens the settings and generates a bug report. - */ - @Test - public void testGenerateBugReport() - { - clickMenuItem(R.string.settings); - clickSettingsItem("Generate bug report"); - intended(hasAction(Intent.ACTION_SEND)); - } - - /** - * User opens menu, clicks Help, sees website. - */ - @Test - public void testHelp() - { - clickMenuItem(R.string.help); - intended(hasAction(Intent.ACTION_VIEW)); - } - - /** - * User opens menu, clicks settings, sees settings screen. - */ - @Test - public void testSettings() - { - clickMenuItem(R.string.settings); - } -} diff --git a/app/src/androidTest/java/org/isoron/uhabits/espresso/ShowHabitActivityActions.java b/app/src/androidTest/java/org/isoron/uhabits/espresso/ShowHabitActivityActions.java deleted file mode 100644 index 6475b0890..000000000 --- a/app/src/androidTest/java/org/isoron/uhabits/espresso/ShowHabitActivityActions.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2016 Á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.espresso; - -import android.support.test.espresso.matcher.ViewMatchers; - -import org.isoron.uhabits.R; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.action.ViewActions.scrollTo; - -public class ShowHabitActivityActions -{ - public static void openHistoryEditor() - { - onView(ViewMatchers.withId(R.id.edit)) - .perform(scrollTo(), click()); - } -} diff --git a/app/src/androidTest/java/org/isoron/uhabits/espresso/SystemHelper.java b/app/src/androidTest/java/org/isoron/uhabits/espresso/SystemHelper.java deleted file mode 100644 index 6fb12fede..000000000 --- a/app/src/androidTest/java/org/isoron/uhabits/espresso/SystemHelper.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2016 Á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.espresso; - -import android.app.KeyguardManager; -import android.content.Context; -import android.content.pm.PackageManager; -import android.os.IBinder; -import android.os.PowerManager; -import android.support.test.runner.AndroidJUnitRunner; -import android.util.Log; - -import java.lang.reflect.Method; - -public final class SystemHelper extends AndroidJUnitRunner -{ - private static final String ANIMATION_PERMISSION = "android.permission.SET_ANIMATION_SCALE"; - private static final float DISABLED = 0.0f; - private static final float DEFAULT = 1.0f; - - private final Context context; - private PowerManager.WakeLock wakeLock; - - SystemHelper(Context context) - { - this.context = context; - } - - void acquireWakeLock() - { - PowerManager power = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - wakeLock = power.newWakeLock(PowerManager.FULL_WAKE_LOCK | - PowerManager.ACQUIRE_CAUSES_WAKEUP | - PowerManager.ON_AFTER_RELEASE, getClass().getSimpleName()); - wakeLock.acquire(); - } - - void releaseWakeLock() - { - if(wakeLock != null) - wakeLock.release(); - } - - void unlockScreen() - { - Log.i("SystemHelper", "Trying to unlock screen"); - try - { - KeyguardManager mKeyGuardManager = - (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); - KeyguardManager.KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("lock"); - mLock.disableKeyguard(); - Log.e("SystemHelper", "Successfully unlocked screen"); - } catch (Exception e) - { - Log.e("SystemHelper", "Could not unlock screen"); - e.printStackTrace(); - } - } - - void disableAllAnimations() - { - Log.i("SystemHelper", "Trying to disable animations"); - int permStatus = context.checkCallingOrSelfPermission(ANIMATION_PERMISSION); - if (permStatus == PackageManager.PERMISSION_GRANTED) setSystemAnimationsScale(DISABLED); - else Log.e("SystemHelper", "Permission denied"); - - } - - void enableAllAnimations() - { - int permStatus = context.checkCallingOrSelfPermission(ANIMATION_PERMISSION); - if (permStatus == PackageManager.PERMISSION_GRANTED) - { - setSystemAnimationsScale(DEFAULT); - } - } - - private void setSystemAnimationsScale(float animationScale) - { - try - { - Class windowManagerStubClazz = Class.forName("android.view.IWindowManager$Stub"); - Method asInterface = - windowManagerStubClazz.getDeclaredMethod("asInterface", IBinder.class); - Class serviceManagerClazz = Class.forName("android.os.ServiceManager"); - Method getService = serviceManagerClazz.getDeclaredMethod("getService", String.class); - Class windowManagerClazz = Class.forName("android.view.IWindowManager"); - Method setAnimationScales = - windowManagerClazz.getDeclaredMethod("setAnimationScales", float[].class); - Method getAnimationScales = windowManagerClazz.getDeclaredMethod("getAnimationScales"); - - IBinder windowManagerBinder = (IBinder) getService.invoke(null, "window"); - Object windowManagerObj = asInterface.invoke(null, windowManagerBinder); - float[] currentScales = (float[]) getAnimationScales.invoke(windowManagerObj); - for (int i = 0; i < currentScales.length; i++) - currentScales[i] = animationScale; - - setAnimationScales.invoke(windowManagerObj, new Object[]{currentScales}); - Log.i("SystemHelper", "All animations successfully disabled"); - } - catch (Exception e) - { - Log.e("SystemHelper", "Could not change animation scale to " + animationScale + " :'("); - } - } -} \ No newline at end of file diff --git a/app/src/test/java/org/isoron/uhabits/commands/UnarchiveHabitsCommandTest.java b/app/src/test/java/org/isoron/uhabits/commands/UnarchiveHabitsCommandTest.java index 9485962d8..09b9004e3 100644 --- a/app/src/test/java/org/isoron/uhabits/commands/UnarchiveHabitsCommandTest.java +++ b/app/src/test/java/org/isoron/uhabits/commands/UnarchiveHabitsCommandTest.java @@ -42,7 +42,7 @@ public class UnarchiveHabitsCommandTest extends BaseUnitTest habit = fixtures.createShortHabit(); habit.setArchived(true); - habitList.update(habit); + habitList.add(habit); command = new UnarchiveHabitsCommand(habitList, Collections .singletonList