Add tests for CheckmarkView

pull/77/merge
Alinson S. Xavier 10 years ago
parent 4f65c8bef1
commit 285f79ed95

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

@ -0,0 +1,87 @@
/*
* 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.helpers.DateHelper;
import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.models.HabitFixtures;
import org.isoron.uhabits.views.CheckmarkView;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class CheckmarkViewTest extends ViewTest
{
private CheckmarkView view;
private Habit habit;
@Before
public void setup()
{
super.setup();
habit = HabitFixtures.createNonDailyHabit();
view = new CheckmarkView(targetContext);
view.setHabit(habit);
measureView(dpToPixels(100), dpToPixels(200), view);
}
@Test
public void render_checked() throws IOException
{
assertRenders(view, "Views/CheckmarkView/checked.png");
}
@Test
public void render_unchecked() throws IOException
{
habit.repetitions.toggle(DateHelper.getStartOfToday());
view.refreshData();
assertRenders(view, "Views/CheckmarkView/unchecked.png");
}
@Test
public void render_implicitlyChecked() throws IOException
{
long today = DateHelper.getStartOfToday();
long day = DateHelper.millisecondsInOneDay;
habit.repetitions.toggle(today);
habit.repetitions.toggle(today - day);
habit.repetitions.toggle(today - 2 * day);
view.refreshData();
assertRenders(view, "Views/CheckmarkView/implicitly_checked.png");
}
@Test
public void render_largeSize() throws IOException
{
measureView(dpToPixels(300), dpToPixels(300), view);
assertRenders(view, "Views/CheckmarkView/large_size.png");
}
}

@ -32,8 +32,8 @@ import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;
import org.isoron.uhabits.helpers.ColorHelper;
import org.isoron.uhabits.R;
import org.isoron.uhabits.helpers.ColorHelper;
import org.isoron.uhabits.models.Habit;
public class CheckmarkView extends View
@ -65,6 +65,7 @@ public class CheckmarkView extends View
private Rect rect;
private TextPaint textPaint;
private StaticLayout labelLayout;
private Habit habit;
public CheckmarkView(Context context)
{
@ -114,11 +115,8 @@ public class CheckmarkView extends View
public void setHabit(Habit habit)
{
this.check_status = habit.checkmarks.getTodayValue();
this.star_status = habit.scores.getTodayStarStatus();
this.primaryColor = Color.argb(230, Color.red(habit.color), Color.green(habit.color), Color.blue(habit.color));
this.label = habit.name;
updateLabel();
this.habit = habit;
refreshData();
}
@Override
@ -193,11 +191,17 @@ public class CheckmarkView extends View
padding = 8 * leftMargin;
textPaint.setTextSize(0.15f * width);
updateLabel();
refreshData();
}
private void updateLabel()
public void refreshData()
{
this.check_status = habit.checkmarks.getTodayValue();
this.star_status = habit.scores.getTodayStarStatus();
this.primaryColor = Color.argb(230, Color.red(habit.color), Color.green(habit.color),
Color.blue(habit.color));
this.label = habit.name;
textPaint.setColor(Color.WHITE);
labelLayout = new StaticLayout(label, textPaint, width - 2 * leftMargin - 2 * padding,
Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);

Loading…
Cancel
Save