Major refactoring of ListHabitsActivity

This commit is contained in:
2016-05-29 11:40:42 -04:00
parent 3ffa079e24
commit 7e8a2a0c1c
123 changed files with 5764 additions and 2701 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,32 @@
/*
* 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 javax.inject.Singleton;
import dagger.Component;
@Singleton
@Component(modules = {AndroidModule.class})
public interface AndroidTestComponent extends BaseComponent
{
void inject(BaseAndroidTest baseAndroidTest);
}

View File

@@ -27,11 +27,14 @@ import android.support.test.InstrumentationRegistry;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.utils.InterfaceUtils;
import org.isoron.uhabits.tasks.BaseTask;
import org.isoron.uhabits.utils.Preferences;
import org.junit.Before;
import java.util.concurrent.TimeoutException;
public class BaseTest
import javax.inject.Inject;
public class BaseAndroidTest
{
protected Context testContext;
protected Context targetContext;
@@ -39,8 +42,12 @@ public class BaseTest
public static final long FIXED_LOCAL_TIME = 1422172800000L; // 8:00am, January 25th, 2015 (UTC)
@Inject
protected Preferences prefs;
protected AndroidTestComponent androidTestComponent;
@Before
public void setup()
public void setUp()
{
if(!isLooperPrepared)
{
@@ -53,6 +60,10 @@ public class BaseTest
InterfaceUtils.setFixedTheme(R.style.AppBaseTheme);
DateUtils.setFixedLocalTime(FIXED_LOCAL_TIME);
androidTestComponent = DaggerAndroidTestComponent.builder().build();
HabitsApplication.setComponent(androidTestComponent);
androidTestComponent.inject(this);
}
protected void waitForAsyncTasks() throws InterruptedException, TimeoutException

View File

@@ -61,7 +61,7 @@ public class HabitViewActions
@Override
public void perform(UiController uiController, View view)
{
if (view.getId() != R.id.llButtons)
if (view.getId() != R.id.checkmarkPanel)
throw new InvalidParameterException("View must have id llButtons");
LinearLayout llButtons = (LinearLayout) view;

View File

@@ -191,7 +191,7 @@ public class MainTest
String name = addHabit(true);
onData(allOf(is(instanceOf(Habit.class)), withName(name)))
.onChildView(withId(R.id.llButtons))
.onChildView(withId(R.id.checkmarkPanel))
.perform(toggleAllCheckmarks());
Thread.sleep(1200);

View File

@@ -23,8 +23,9 @@ import android.os.Build;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.HabitsApplication;
import org.isoron.uhabits.ui.BaseSystem;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,7 +36,7 @@ import static org.hamcrest.Matchers.containsString;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class HabitsApplicationTest extends BaseTest
public class HabitsApplicationTest extends BaseAndroidTest
{
@Test
public void test_getLogcat() throws IOException
@@ -49,7 +50,8 @@ public class HabitsApplicationTest extends BaseTest
HabitsApplication app = HabitsApplication.getInstance();
assert(app != null);
String log = app.getLogcat();
BaseSystem system = new BaseSystem(targetContext);
String log = system.getLogcat();
assertThat(log, containsString(msg));
}
}

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.commands;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.commands.ArchiveHabitsCommand;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -37,16 +37,16 @@ import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ArchiveHabitsCommandTest extends BaseTest
public class ArchiveHabitsCommandTest extends BaseAndroidTest
{
private ArchiveHabitsCommand command;
private Habit habit;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
habit = HabitFixtures.createShortHabit();
command = new ArchiveHabitsCommand(Collections.singletonList(habit));

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.commands;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.commands.ChangeHabitColorCommand;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -37,15 +37,15 @@ import static org.hamcrest.Matchers.equalTo;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ChangeHabitColorCommandTest extends BaseTest
public class ChangeHabitColorCommandTest extends BaseAndroidTest
{
private ChangeHabitColorCommand command;
private LinkedList<Habit> habits;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
habits = new LinkedList<>();

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.commands;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.commands.CreateHabitCommand;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -38,16 +38,16 @@ import static org.hamcrest.Matchers.equalTo;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class CreateHabitCommandTest extends BaseTest
public class CreateHabitCommandTest extends BaseAndroidTest
{
private CreateHabitCommand command;
private Habit model;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
model = new Habit();
model.name = "New habit";

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.commands;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.commands.DeleteHabitsCommand;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.equalTo;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class DeleteHabitsCommandTest extends BaseTest
public class DeleteHabitsCommandTest extends BaseAndroidTest
{
private DeleteHabitsCommand command;
private LinkedList<Habit> habits;
@@ -48,9 +48,9 @@ public class DeleteHabitsCommandTest extends BaseTest
public ExpectedException thrown = ExpectedException.none();
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
habits = new LinkedList<>();

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.commands;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.commands.EditHabitCommand;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -37,7 +37,7 @@ import static org.hamcrest.Matchers.greaterThan;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class EditHabitCommandTest extends BaseTest
public class EditHabitCommandTest extends BaseAndroidTest
{
private EditHabitCommand command;
@@ -46,9 +46,9 @@ public class EditHabitCommandTest extends BaseTest
private Long id;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
habit = HabitFixtures.createShortHabit();
habit.name = "original";

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.commands;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.commands.ToggleRepetitionCommand;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.models.Habit;
@@ -36,7 +36,7 @@ import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ToggleRepetitionCommandTest extends BaseTest
public class ToggleRepetitionCommandTest extends BaseAndroidTest
{
private ToggleRepetitionCommand command;
@@ -44,9 +44,9 @@ public class ToggleRepetitionCommandTest extends BaseTest
private long today;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
habit = HabitFixtures.createShortHabit();

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.commands;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.commands.UnarchiveHabitsCommand;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -37,16 +37,16 @@ import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class UnarchiveHabitsCommandTest extends BaseTest
public class UnarchiveHabitsCommandTest extends BaseAndroidTest
{
private UnarchiveHabitsCommand command;
private Habit habit;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
habit = HabitFixtures.createShortHabit();
Habit.archive(Collections.singletonList(habit));

View File

@@ -24,7 +24,7 @@ import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.utils.FileUtils;
import org.isoron.uhabits.io.HabitsCSVExporter;
import org.isoron.uhabits.models.Habit;
@@ -45,14 +45,14 @@ import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class HabitsCSVExporterTest extends BaseTest
public class HabitsCSVExporterTest extends BaseAndroidTest
{
private File baseDir;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
HabitFixtures.createShortHabit();

View File

@@ -24,7 +24,7 @@ import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.utils.FileUtils;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.io.GenericImporter;
@@ -49,15 +49,15 @@ import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ImportTest extends BaseTest
public class ImportTest extends BaseAndroidTest
{
private File baseDir;
private Context context;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
DateUtils.setFixedLocalTime(null);
HabitFixtures.purgeHabits();

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.models;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -42,15 +42,15 @@ import static org.isoron.uhabits.models.Checkmark.UNCHECKED;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class CheckmarkListTest extends BaseTest
public class CheckmarkListTest extends BaseAndroidTest
{
Habit nonDailyHabit;
private Habit emptyHabit;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
nonDailyHabit = HabitFixtures.createShortHabit();

View File

@@ -23,7 +23,7 @@ import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.hamcrest.MatcherAssert;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -45,12 +45,12 @@ import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class HabitTest extends BaseTest
public class HabitTest extends BaseAndroidTest
{
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
}

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.models;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.Repetition;
@@ -44,15 +44,15 @@ import static org.hamcrest.Matchers.equalTo;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class RepetitionListTest extends BaseTest
public class RepetitionListTest extends BaseAndroidTest
{
private Habit habit;
private Habit emptyHabit;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
habit = HabitFixtures.createShortHabit();

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.models;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.utils.DateUtils;
import org.isoron.uhabits.utils.DatabaseUtils;
import org.isoron.uhabits.models.Habit;
@@ -41,14 +41,14 @@ import static org.hamcrest.Matchers.equalTo;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ScoreListTest extends BaseTest
public class ScoreListTest extends BaseAndroidTest
{
private Habit habit;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
habit = HabitFixtures.createEmptyHabit();

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.models;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.models.Checkmark;
import org.isoron.uhabits.models.Score;
import org.junit.Before;
@@ -34,12 +34,12 @@ import static org.junit.Assert.assertThat;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ScoreTest extends BaseTest
public class ScoreTest extends BaseAndroidTest
{
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
}
@Test

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.tasks;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.tasks.ExportCSVTask;
import org.isoron.uhabits.unit.HabitFixtures;
@@ -41,12 +41,12 @@ import static org.hamcrest.core.IsNot.not;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ExportCSVTaskTest extends BaseTest
public class ExportCSVTaskTest extends BaseAndroidTest
{
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
}
@Test

View File

@@ -22,7 +22,7 @@ package org.isoron.uhabits.unit.tasks;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.tasks.ExportDBTask;
import org.junit.Before;
import org.junit.Test;
@@ -38,12 +38,12 @@ import static org.hamcrest.core.IsNot.not;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ExportDBTaskTest extends BaseTest
public class ExportDBTaskTest extends BaseAndroidTest
{
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
}
@Test

View File

@@ -23,7 +23,7 @@ import android.support.annotation.NonNull;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.tasks.ImportDataTask;
import org.isoron.uhabits.utils.FileUtils;
import org.junit.Before;
@@ -40,14 +40,14 @@ import static org.junit.Assert.fail;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ImportDataTaskTest extends BaseTest
public class ImportDataTaskTest extends BaseAndroidTest
{
private File baseDir;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
baseDir = FileUtils.getFilesDir("Backups");
if(baseDir == null) fail("baseDir should not be null");

View File

@@ -0,0 +1,187 @@
/*
* 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.unit.ui.habits.list.view;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.models.Checkmark;
import org.isoron.uhabits.ui.habits.list.views.CheckmarkButtonView;
import org.isoron.uhabits.unit.views.ViewTest;
import org.isoron.uhabits.utils.ColorUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class CheckmarkButtonViewTest extends ViewTest
{
public static final String PATH = "ui/habits/list/CheckmarkButtonView/";
private CountDownLatch latch;
private CheckmarkButtonView view;
@Before
public void setUp()
{
super.setUp();
setSimilarityCutoff(0.03f);
latch = new CountDownLatch(1);
view = new CheckmarkButtonView(targetContext);
view.setValue(Checkmark.UNCHECKED);
view.setColor(ColorUtils.CSV_PALETTE[7]);
measureView(dpToPixels(40), dpToPixels(40), view);
}
protected void assertRendersCheckedExplicitly() throws IOException
{
assertRenders(view, PATH + "render_explicit_check.png");
}
protected void assertRendersUnchecked() throws IOException
{
assertRenders(view, PATH + "render_unchecked.png");
}
protected void assertRendersCheckedImplicitly() throws IOException
{
assertRenders(view, PATH + "render_implicit_check.png");
}
@Test
public void testRender_unchecked() throws Exception
{
view.setValue(Checkmark.UNCHECKED);
assertRendersUnchecked();
}
@Test
public void testRender_explicitCheck() throws Exception
{
view.setValue(Checkmark.CHECKED_EXPLICITLY);
assertRendersCheckedExplicitly();
}
@Test
public void testRender_implicitCheck() throws Exception
{
view.setValue(Checkmark.CHECKED_IMPLICITLY);
assertRendersCheckedImplicitly();
}
// @Test
// public void testLongClick() throws Exception
// {
// setOnToggleListener();
// view.performLongClick();
// waitForLatch();
// assertRendersCheckedExplicitly();
// }
//
// @Test
// public void testClick_withShortToggle_fromUnchecked() throws Exception
// {
// Preferences.getInstance().setShortToggleEnabled(true);
// view.setValue(Checkmark.UNCHECKED);
// setOnToggleListenerAndPerformClick();
// assertRendersCheckedExplicitly();
// }
//
// @Test
// public void testClick_withShortToggle_fromChecked() throws Exception
// {
// Preferences.getInstance().setShortToggleEnabled(true);
// view.setValue(Checkmark.CHECKED_EXPLICITLY);
// setOnToggleListenerAndPerformClick();
// assertRendersUnchecked();
// }
//
// @Test
// public void testClick_withShortToggle_withoutListener() throws Exception
// {
// Preferences.getInstance().setShortToggleEnabled(true);
// view.setValue(Checkmark.CHECKED_EXPLICITLY);
// view.setController(null);
// view.performClick();
// assertRendersUnchecked();
// }
//
// protected void setOnToggleListenerAndPerformClick() throws InterruptedException
// {
// setOnToggleListener();
// view.performClick();
// waitForLatch();
// }
//
// @Test
// public void testClick_withoutShortToggle() throws Exception
// {
// Preferences.getInstance().setShortToggleEnabled(false);
// setOnInvalidToggleListener();
// view.performClick();
// waitForLatch();
// assertRendersUnchecked();
// }
// protected void setOnInvalidToggleListener()
// {
// view.setController(new CheckmarkButtonView.Controller()
// {
// @Override
// public void onToggleCheckmark(CheckmarkButtonView view, long timestamp)
// {
// fail();
// }
//
// @Override
// public void onInvalidToggle(CheckmarkButtonView v)
// {
// assertThat(v, equalTo(view));
// latch.countDown();
// }
// });
// }
// protected void setOnToggleListener()
// {
// view.setController(new CheckmarkButtonView.Controller()
// {
// @Override
// public void onToggleCheckmark(CheckmarkButtonView v, long t)
// {
// assertThat(v, equalTo(view));
// assertThat(t, equalTo(DateUtils.getStartOfToday()));
// latch.countDown();
// }
//
// @Override
// public void onInvalidToggle(CheckmarkButtonView view)
// {
// fail();
// }
// });
// }
}

View File

@@ -0,0 +1,97 @@
/*
* 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.unit.ui.habits.list.view;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.models.Checkmark;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.ui.habits.list.views.CheckmarkPanelView;
import org.isoron.uhabits.unit.views.ViewTest;
import org.isoron.uhabits.utils.ColorUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.concurrent.CountDownLatch;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class CheckmarkPanelViewTest extends ViewTest
{
public static final String PATH = "ui/habits/list/CheckmarkPanelView/";
private CountDownLatch latch;
private CheckmarkPanelView view;
private int checkmarks[];
@Override
@Before
public void setUp()
{
super.setUp();
setSimilarityCutoff(0.03f);
prefs.setShouldReverseCheckmarks(false);
Habit habit = new Habit();
latch = new CountDownLatch(1);
checkmarks = new int[]{Checkmark.CHECKED_EXPLICITLY, Checkmark.UNCHECKED,
Checkmark.CHECKED_IMPLICITLY, Checkmark.CHECKED_EXPLICITLY};
view = new CheckmarkPanelView(targetContext);
view.setHabit(habit);
view.setCheckmarkValues(checkmarks);
view.setColor(ColorUtils.CSV_PALETTE[7]);
measureView(dpToPixels(200), dpToPixels(200), view);
}
// protected void waitForLatch() throws InterruptedException
// {
// assertTrue("Latch timeout", latch.await(1, TimeUnit.SECONDS));
// }
@Test
public void testRender() throws Exception
{
assertRenders(view, PATH + "render.png");
}
// @Test
// public void testToggleCheckmark_withLeftToRight() throws Exception
// {
// setToggleListener();
// view.getButton(1).performToggle();
// waitForLatch();
// }
//
// @Test
// public void testToggleCheckmark_withReverseCheckmarks() throws Exception
// {
// prefs.setShouldReverseCheckmarks(true);
// view.setCheckmarkValues(checkmarks); // refresh after preference change
//
// setToggleListener();
// view.getButton(2).performToggle();
// waitForLatch();
// }
}

View File

@@ -42,9 +42,9 @@ public class CheckmarkWidgetViewTest extends ViewTest
private Habit habit;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
InterfaceUtils.setFixedTheme(R.style.TransparentWidgetTheme);
habit = HabitFixtures.createShortHabit();

View File

@@ -36,9 +36,9 @@ public class HabitFrequencyViewTest extends ViewTest
private HabitFrequencyView view;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
Habit habit = HabitFixtures.createLongHabit();

View File

@@ -43,9 +43,9 @@ public class HabitHistoryViewTest extends ViewTest
private HabitHistoryView view;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
habit = HabitFixtures.createLongHabit();

View File

@@ -38,9 +38,9 @@ public class HabitScoreViewTest extends ViewTest
private HabitScoreView view;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
habit = HabitFixtures.createLongHabit();

View File

@@ -36,9 +36,9 @@ public class HabitStreakViewTest extends ViewTest
private HabitStreakView view;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
HabitFixtures.purgeHabits();
Habit habit = HabitFixtures.createLongHabit();

View File

@@ -38,9 +38,9 @@ public class NumberViewTest extends ViewTest
private NumberView view;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
view = new NumberView(targetContext);
view.setLabel("Hello world");

View File

@@ -38,9 +38,9 @@ public class RingViewTest extends ViewTest
private RingView view;
@Before
public void setup()
public void setUp()
{
super.setup();
super.setUp();
view = new RingView(targetContext);
view.setPercentage(0.6f);

View File

@@ -26,7 +26,7 @@ import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import org.isoron.uhabits.BaseTest;
import org.isoron.uhabits.BaseAndroidTest;
import org.isoron.uhabits.utils.FileUtils;
import org.isoron.uhabits.utils.InterfaceUtils;
import org.isoron.uhabits.tasks.BaseTask;
@@ -39,10 +39,23 @@ import java.io.InputStream;
import static junit.framework.Assert.fail;
public class ViewTest extends BaseTest
public class ViewTest extends BaseAndroidTest
{
protected static final double SIMILARITY_CUTOFF = 0.09;
protected static final double DEFAULT_SIMILARITY_CUTOFF = 0.09;
public static final int HISTOGRAM_BIN_SIZE = 8;
private double similarityCutoff;
@Override
public void setUp()
{
super.setUp();
similarityCutoff = DEFAULT_SIMILARITY_CUTOFF;
}
protected void setSimilarityCutoff(double similarityCutoff)
{
this.similarityCutoff = similarityCutoff;
}
protected void measureView(int width, int height, View view)
{
@@ -70,7 +83,8 @@ public class ViewTest extends BaseTest
double distance;
boolean similarEnough = true;
if ((distance = compareHistograms(getHistogram(actual), getHistogram(scaledExpected))) > SIMILARITY_CUTOFF)
if ((distance = compareHistograms(getHistogram(actual), getHistogram(scaledExpected))) >
similarityCutoff)
{
similarEnough = false;
errorMessage.append(String.format(