mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Add tests for HabitFrequencyView
This commit is contained in:
BIN
app/src/androidTest/assets/views/HabitFrequencyView/render.png
Normal file
BIN
app/src/androidTest/assets/views/HabitFrequencyView/render.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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.views;
|
||||||
|
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
import org.isoron.uhabits.unit.HabitFixtures;
|
||||||
|
import org.isoron.uhabits.views.HabitFrequencyView;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@SmallTest
|
||||||
|
public class HabitFrequencyViewTest extends ViewTest
|
||||||
|
{
|
||||||
|
private HabitFrequencyView view;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup()
|
||||||
|
{
|
||||||
|
super.setup();
|
||||||
|
|
||||||
|
HabitFixtures.purgeHabits();
|
||||||
|
Habit habit = HabitFixtures.createLongHabit();
|
||||||
|
|
||||||
|
view = new HabitFrequencyView(targetContext);
|
||||||
|
view.setHabit(habit);
|
||||||
|
measureView(dpToPixels(300), dpToPixels(100), view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void render() throws Throwable
|
||||||
|
{
|
||||||
|
assertRenders(view, "HabitFrequencyView/render.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void render_withDifferentSize() throws Throwable
|
||||||
|
{
|
||||||
|
measureView(dpToPixels(200), dpToPixels(200), view);
|
||||||
|
assertRenders(view, "HabitFrequencyView/renderDifferentSize.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void render_withDataOffset() throws Throwable
|
||||||
|
{
|
||||||
|
view.onScroll(null, null, -dpToPixels(150), 0);
|
||||||
|
view.invalidate();
|
||||||
|
|
||||||
|
assertRenders(view, "HabitFrequencyView/renderDataOffset.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,12 +66,17 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
|
|||||||
private HashMap<Long, Integer[]> frequency;
|
private HashMap<Long, Integer[]> frequency;
|
||||||
private String wdays[];
|
private String wdays[];
|
||||||
|
|
||||||
|
public HabitFrequencyView(Context context)
|
||||||
|
{
|
||||||
|
super(context);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
public HabitFrequencyView(Context context, AttributeSet attrs)
|
public HabitFrequencyView(Context context, AttributeSet attrs)
|
||||||
{
|
{
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
this.primaryColor = ColorHelper.palette[7];
|
this.primaryColor = ColorHelper.palette[7];
|
||||||
this.frequency = new HashMap<>();
|
this.frequency = new HashMap<>();
|
||||||
wdays = DateHelper.getShortDayNames();
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +94,8 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
|
|||||||
createPaints();
|
createPaints();
|
||||||
createColors();
|
createColors();
|
||||||
|
|
||||||
|
wdays = DateHelper.getShortDayNames();
|
||||||
|
|
||||||
dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
|
dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
|
||||||
dfYear = new SimpleDateFormat("yyyy", Locale.getDefault());
|
dfYear = new SimpleDateFormat("yyyy", Locale.getDefault());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user