Skip to content

Commit 13f4981

Browse files
authored
Merge pull request #547 from recheej/rechee/add_notes
Add Notes to Habits.
2 parents 58d8c79 + 849b91d commit 13f4981

File tree

39 files changed

+429
-102
lines changed

39 files changed

+429
-102
lines changed

android/uhabits-android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ dependencies {
8787
implementation "com.google.code.gson:gson:2.8.5"
8888
implementation "com.google.code.findbugs:jsr305:3.0.2"
8989
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
90+
implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4"
9091

9192
compileOnly "javax.annotation:jsr250-api:1.0"
9293
compileOnly "com.google.auto.factory:auto-factory:$AUTO_FACTORY_VERSION"
1.13 KB
Loading
5.71 KB
Loading

android/uhabits-android/src/androidTest/java/org/isoron/uhabits/BaseUserInterfaceTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
public class BaseUserInterfaceTest
4040
{
4141
private static final String PKG = "org.isoron.uhabits";
42+
public static final String EMPTY_DESCRIPTION_HABIT_NAME = "Read books";
4243

4344
public static UiDevice device;
4445

@@ -96,25 +97,29 @@ private void resetState() throws Exception
9697

9798
Habit h1 = fixtures.createEmptyHabit();
9899
h1.setName("Wake up early");
99-
h1.setDescription("Did you wake up early today?");
100+
h1.setQuestion("Did you wake up early today?");
101+
h1.setDescription("test description 1");
100102
h1.setColor(5);
101103
habitList.update(h1);
102104

103105
Habit h2 = fixtures.createShortHabit();
104106
h2.setName("Track time");
105-
h2.setDescription("Did you track your time?");
107+
h2.setQuestion("Did you track your time?");
108+
h2.setDescription("test description 2");
106109
h2.setColor(5);
107110
habitList.update(h2);
108111

109112
Habit h3 = fixtures.createLongHabit();
110113
h3.setName("Meditate");
111-
h3.setDescription("Did meditate today?");
114+
h3.setQuestion("Did meditate today?");
115+
h3.setDescription("test description 3");
112116
h3.setColor(10);
113117
habitList.update(h3);
114118

115119
Habit h4 = fixtures.createEmptyHabit();
116-
h4.setName("Read books");
117-
h4.setDescription("Did you read books today?");
120+
h4.setName(EMPTY_DESCRIPTION_HABIT_NAME);
121+
h4.setQuestion("Did you read books today?");
122+
h4.setDescription("");
118123
h4.setColor(2);
119124
habitList.update(h4);
120125
}

android/uhabits-android/src/androidTest/java/org/isoron/uhabits/HabitFixtures.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public Habit createEmptyHabit(Long id)
5252
{
5353
Habit habit = modelFactory.buildHabit();
5454
habit.setName("Meditate");
55-
habit.setDescription("Did you meditate this morning?");
55+
habit.setQuestion("Did you meditate this morning?");
56+
habit.setDescription("This is a test description");
5657
habit.setColor(5);
5758
habit.setFrequency(Frequency.DAILY);
5859
habit.setId(id);
@@ -81,7 +82,7 @@ public Habit createLongNumericalHabit()
8182
{
8283
Habit habit = modelFactory.buildHabit();
8384
habit.setName("Take a walk");
84-
habit.setDescription("How many steps did you walk today?");
85+
habit.setQuestion("How many steps did you walk today?");
8586
habit.setType(Habit.NUMBER_HABIT);
8687
habit.setTargetType(Habit.AT_LEAST);
8788
habit.setTargetValue(200.0);
@@ -103,7 +104,7 @@ public Habit createShortHabit()
103104
{
104105
Habit habit = modelFactory.buildHabit();
105106
habit.setName("Wake up early");
106-
habit.setDescription("Did you wake up before 6am?");
107+
habit.setQuestion("Did you wake up before 6am?");
107108
habit.setFrequency(new Frequency(2, 3));
108109
habitList.add(habit);
109110

android/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/HabitsTest.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.isoron.uhabits.acceptance;
2121

2222
import androidx.test.filters.*;
23-
import androidx.test.runner.*;
2423

2524
import androidx.test.ext.junit.runners.AndroidJUnit4;
2625

@@ -39,22 +38,33 @@
3938
public class HabitsTest extends BaseUserInterfaceTest
4039
{
4140
@Test
42-
public void shouldCreateHabit() throws Exception
41+
public void shouldCreateHabit() throws Exception {
42+
shouldCreateHabit("this is a test description");
43+
}
44+
45+
@Test
46+
public void shouldCreateHabitBlankDescription() throws Exception {
47+
shouldCreateHabit("");
48+
}
49+
50+
private void shouldCreateHabit(String description) throws Exception
4351
{
4452
launchApp();
4553

4654
verifyShowsScreen(LIST_HABITS);
4755
clickMenu(ADD);
4856

4957
verifyShowsScreen(EDIT_HABIT);
50-
typeName("Hello world");
58+
String testName = "Hello world";
59+
typeName(testName);
5160
typeQuestion("Did you say hello to the world today?");
61+
typeDescription(description);
5262
pickFrequency("Every week");
5363
pickColor(5);
5464
clickSave();
5565

5666
verifyShowsScreen(LIST_HABITS);
57-
verifyDisplaysText("Hello world");
67+
verifyDisplaysText(testName);
5868
}
5969

6070
@Test
@@ -81,7 +91,16 @@ public void shouldDeleteHabit() throws Exception
8191
}
8292

8393
@Test
84-
public void shouldEditHabit() throws Exception
94+
public void shouldEditHabit() throws Exception {
95+
shouldEditHabit("this is a test description");
96+
}
97+
98+
@Test
99+
public void shouldEditHabitBlankDescription() throws Exception {
100+
shouldEditHabit("");
101+
}
102+
103+
private void shouldEditHabit(String description) throws Exception
85104
{
86105
launchApp();
87106

@@ -92,6 +111,7 @@ public void shouldEditHabit() throws Exception
92111
verifyShowsScreen(EDIT_HABIT);
93112
typeName("Take a walk");
94113
typeQuestion("Did you take a walk today?");
114+
typeDescription(description);
95115
clickSave();
96116

97117
verifyShowsScreen(LIST_HABITS);
@@ -174,4 +194,12 @@ public void shouldHideCompleted() throws Exception
174194
verifyDisplaysText("Track time");
175195
verifyDisplaysText("Wake up early");
176196
}
197+
198+
@Test
199+
public void shouldHideNotesCard() throws Exception
200+
{
201+
launchApp();
202+
clickText(EMPTY_DESCRIPTION_HABIT_NAME);
203+
verifyShowsScreen(SHOW_HABIT, false);
204+
}
177205
}

android/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/CommonSteps.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919

2020
package org.isoron.uhabits.acceptance.steps;
2121

22+
import android.view.View;
23+
2224
import androidx.annotation.StringRes;
2325
import androidx.test.espresso.*;
2426
import androidx.test.espresso.contrib.*;
2527
import androidx.test.uiautomator.*;
26-
import androidx.appcompat.widget.*;
2728

2829
import androidx.recyclerview.widget.RecyclerView;
2930

31+
import org.hamcrest.Matcher;
3032
import org.isoron.uhabits.*;
3133
import org.isoron.uhabits.R;
3234
import org.isoron.uhabits.activities.habits.list.*;
@@ -153,7 +155,11 @@ public enum Screen
153155
LIST_HABITS, SHOW_HABIT, EDIT_HABIT
154156
}
155157

156-
public static void verifyShowsScreen(Screen screen)
158+
public static void verifyShowsScreen(Screen screen) {
159+
verifyShowsScreen(screen, true);
160+
}
161+
162+
public static void verifyShowsScreen(Screen screen, boolean notesCardVisibleExpected)
157163
{
158164
switch(screen)
159165
{
@@ -163,10 +169,14 @@ public static void verifyShowsScreen(Screen screen)
163169
break;
164170

165171
case SHOW_HABIT:
172+
Matcher<View> noteCardViewMatcher = notesCardVisibleExpected ? isDisplayed() :
173+
withEffectiveVisibility(Visibility.GONE);
166174
onView(withId(R.id.subtitleCard)).check(matches(isDisplayed()));
175+
onView(withId(R.id.notesCard)).check(matches(noteCardViewMatcher));
167176
break;
168177

169178
case EDIT_HABIT:
179+
onView(withId(R.id.tvQuestion)).check(matches(isDisplayed()));
170180
onView(withId(R.id.tvDescription)).check(matches(isDisplayed()));
171181
break;
172182
}

android/uhabits-android/src/androidTest/java/org/isoron/uhabits/acceptance/steps/EditHabitSteps.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ public static void typeName(String name)
5555

5656
public static void typeQuestion(String name)
5757
{
58-
typeTextWithId(R.id.tvDescription, name);
58+
typeTextWithId(R.id.tvQuestion, name);
59+
}
60+
61+
public static void typeDescription(String description)
62+
{
63+
typeTextWithId(R.id.tvDescription, description);
5964
}
6065

6166
public static void setReminder()
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2016 Álinson Santos Xavier <[email protected]>
3+
*
4+
* This file is part of Loop Habit Tracker.
5+
*
6+
* Loop Habit Tracker is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by the
8+
* Free Software Foundation, either version 3 of the License, or (at your
9+
* option) any later version.
10+
*
11+
* Loop Habit Tracker is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package org.isoron.uhabits.activities.habits.show.views;
21+
22+
import android.view.LayoutInflater;
23+
24+
import androidx.test.ext.junit.runners.AndroidJUnit4;
25+
import androidx.test.filters.MediumTest;
26+
27+
import org.isoron.uhabits.BaseViewTest;
28+
import org.isoron.uhabits.R;
29+
import org.isoron.uhabits.core.models.Habit;
30+
import org.isoron.uhabits.core.models.Reminder;
31+
import org.isoron.uhabits.core.models.WeekdayList;
32+
import org.junit.Before;
33+
import org.junit.Test;
34+
import org.junit.runner.RunWith;
35+
36+
@RunWith(AndroidJUnit4.class)
37+
@MediumTest
38+
public class NotesCardTest extends BaseViewTest
39+
{
40+
public static final String PATH = "habits/show/NotesCard/";
41+
42+
private NotesCard view;
43+
44+
private Habit habit;
45+
46+
@Before
47+
@Override
48+
public void setUp()
49+
{
50+
super.setUp();
51+
52+
habit = fixtures.createLongHabit();
53+
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
54+
55+
view = LayoutInflater
56+
.from(targetContext)
57+
.inflate(R.layout.show_habit, null)
58+
.findViewById(R.id.notesCard);
59+
60+
view.setHabit(habit);
61+
view.refreshData();
62+
63+
measureView(view, 800, 200);
64+
}
65+
66+
@Test
67+
public void testRender() throws Exception
68+
{
69+
assertRenders(view, PATH + "render.png");
70+
}
71+
72+
@Test
73+
public void testRenderEmptyDescription() throws Exception
74+
{
75+
habit.setDescription("");
76+
view.refreshData();
77+
assertRenders(view, PATH + "render-empty-description.png");
78+
}
79+
}

android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/show/views/SubtitleCardTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void setUp()
4949
habit = fixtures.createLongHabit();
5050
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
5151

52-
view = (SubtitleCard) LayoutInflater
52+
view = LayoutInflater
5353
.from(targetContext)
5454
.inflate(R.layout.show_habit, null)
5555
.findViewById(R.id.subtitleCard);

0 commit comments

Comments
 (0)