mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Reactivate HistoryChart tests; fix IndexOutOfBoundsException
This commit is contained in:
@@ -20,13 +20,11 @@
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import android.graphics.*;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.test.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.annotation.*;
|
||||
import androidx.test.platform.app.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.androidbase.utils.*;
|
||||
@@ -35,10 +33,9 @@ import org.isoron.uhabits.widgets.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Build.VERSION_CODES.KITKAT;
|
||||
import static android.os.Build.VERSION_CODES.LOLLIPOP;
|
||||
import static android.view.View.MeasureSpec.makeMeasureSpec;
|
||||
import static android.os.Build.VERSION.*;
|
||||
import static android.os.Build.VERSION_CODES.*;
|
||||
import static android.view.View.MeasureSpec.*;
|
||||
|
||||
public class BaseViewTest extends BaseAndroidTest
|
||||
{
|
||||
|
||||
@@ -19,17 +19,18 @@
|
||||
|
||||
package org.isoron.uhabits.activities.common.views;
|
||||
|
||||
import androidx.test.ext.junit.runners.*;
|
||||
import androidx.test.filters.*;
|
||||
import androidx.test.runner.*;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@MediumTest
|
||||
public class HistoryChartTest extends BaseViewTest
|
||||
@@ -38,6 +39,12 @@ public class HistoryChartTest extends BaseViewTest
|
||||
|
||||
private HistoryChart chart;
|
||||
|
||||
private Habit habit;
|
||||
|
||||
Timestamp today;
|
||||
|
||||
private HistoryChart.Controller controller;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp()
|
||||
@@ -45,50 +52,59 @@ public class HistoryChartTest extends BaseViewTest
|
||||
super.setUp();
|
||||
|
||||
fixtures.purgeHabits(habitList);
|
||||
Habit habit = fixtures.createLongHabit();
|
||||
habit = fixtures.createLongHabit();
|
||||
today = new Timestamp(DateUtils.getStartOfToday());
|
||||
|
||||
chart = new HistoryChart(targetContext);
|
||||
chart.setCheckmarks(habit.getCheckmarks().getAllValues());
|
||||
chart.setColor(PaletteUtils.getAndroidTestColor(habit.getColor()));
|
||||
measureView(chart, dpToPixels(400), dpToPixels(200));
|
||||
|
||||
controller = mock(HistoryChart.Controller.class);
|
||||
chart.setController(controller);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void tapDate_atInvalidLocations() throws Throwable
|
||||
// {
|
||||
// int expectedCheckmarkValues[] = habit.getCheckmarks().getAllValues();
|
||||
//
|
||||
// chart.setIsEditable(true);
|
||||
// tap(chart, 118, 13); // header
|
||||
// tap(chart, 336, 60); // tomorrow's square
|
||||
// tap(chart, 370, 60); // right axis
|
||||
// waitForAsyncTasks();
|
||||
//
|
||||
// int actualCheckmarkValues[] = habit.getCheckmarks().getAllValues();
|
||||
// assertThat(actualCheckmarkValues, equalTo(expectedCheckmarkValues));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void tapDate_withEditableView() throws Throwable
|
||||
// {
|
||||
// chart.setIsEditable(true);
|
||||
// tap(chart, 340, 40); // today's square
|
||||
// waitForAsyncTasks();
|
||||
//
|
||||
// long today = DateUtils.getStartOfToday();
|
||||
// assertFalse(habit.getRepetitions().containsTimestamp(today));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void tapDate_withReadOnlyView() throws Throwable
|
||||
// {
|
||||
// chart.setIsEditable(false);
|
||||
// tap(chart, 340, 40); // today's square
|
||||
// waitForAsyncTasks();
|
||||
//
|
||||
// long today = DateUtils.getStartOfToday();
|
||||
// assertTrue(habit.getRepetitions().containsTimestamp(today));
|
||||
// }
|
||||
@Test
|
||||
public void tapDate_atInvalidLocations() throws Throwable
|
||||
{
|
||||
chart.setIsEditable(true);
|
||||
chart.tap(dpToPixels(118), dpToPixels(13)); // header
|
||||
chart.tap(dpToPixels(336), dpToPixels(60)); // tomorrow's square
|
||||
chart.tap(dpToPixels(370), dpToPixels(60)); // right axis
|
||||
verifyNoMoreInteractions(controller);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tapDate_withEditableView() throws Throwable
|
||||
{
|
||||
chart.setIsEditable(true);
|
||||
|
||||
chart.tap(dpToPixels(340), dpToPixels(40));
|
||||
verify(controller).onToggleCheckmark(today, Checkmark.SKIPPED);
|
||||
chart.tap(dpToPixels(340), dpToPixels(40));
|
||||
verify(controller).onToggleCheckmark(today, Checkmark.UNCHECKED);
|
||||
chart.tap(dpToPixels(340), dpToPixels(40));
|
||||
verify(controller).onToggleCheckmark(today, Checkmark.CHECKED_EXPLICITLY);
|
||||
verifyNoMoreInteractions(controller);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tapDate_withEmptyHabit()
|
||||
{
|
||||
chart.setIsEditable(true);
|
||||
chart.setCheckmarks(new int[]{});
|
||||
chart.tap(dpToPixels(340), dpToPixels(40));
|
||||
verify(controller).onToggleCheckmark(today, Checkmark.CHECKED_EXPLICITLY);
|
||||
verifyNoMoreInteractions(controller);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tapDate_withReadOnlyView() throws Throwable
|
||||
{
|
||||
chart.setIsEditable(false);
|
||||
chart.tap(dpToPixels(340), dpToPixels(40));
|
||||
verifyNoMoreInteractions(controller);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRender() throws Throwable
|
||||
|
||||
@@ -121,11 +121,7 @@ public class HistoryChart extends ScrollableChart
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e)
|
||||
{
|
||||
if (!isEditable) return false;
|
||||
|
||||
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||
float x, y;
|
||||
|
||||
try
|
||||
{
|
||||
int pointerId = e.getPointerId(0);
|
||||
@@ -139,20 +135,30 @@ public class HistoryChart extends ScrollableChart
|
||||
// e.getPointerId.
|
||||
return false;
|
||||
}
|
||||
return tap(x, y);
|
||||
}
|
||||
|
||||
public boolean tap(float x, float y)
|
||||
{
|
||||
if (!isEditable) return false;
|
||||
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||
|
||||
final Timestamp timestamp = positionToTimestamp(x, y);
|
||||
if (timestamp == null) return false;
|
||||
|
||||
Timestamp today = DateUtils.getToday();
|
||||
int newValue = CHECKED_EXPLICITLY;
|
||||
int offset = timestamp.daysUntil(today);
|
||||
if (offset < checkmarks.length)
|
||||
{
|
||||
checkmarks[offset] = Repetition.nextToggleValue(checkmarks[offset]);
|
||||
newValue = Repetition.nextToggleValue(checkmarks[offset]);
|
||||
checkmarks[offset] = newValue;
|
||||
}
|
||||
|
||||
controller.onToggleCheckmark(timestamp, checkmarks[offset]);
|
||||
controller.onToggleCheckmark(timestamp, newValue);
|
||||
postInvalidate();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public void populateWithRandomData()
|
||||
|
||||
Reference in New Issue
Block a user