Skip to content

Commit

Permalink
plusonelabs#356 Execute and show last played test results in the spec…
Browse files Browse the repository at this point in the history
…ially named widget: its name ending with "Test replay"
  • Loading branch information
yvolk committed Dec 30, 2019
1 parent 87c6917 commit 041c48a
Show file tree
Hide file tree
Showing 17 changed files with 952 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DateTime dateTime(
}

protected void playResults(String tag) {
provider.setPreferences();
provider.updateAppSettings();
factory.onDataSetChanged();
factory.logWidgetEntries(tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BirthdayTest extends BaseWidgetTest {

@Test
public void testBirthdayOneDayOnly() throws IOException, JSONException {
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResultsAndSettings(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.birthday);

provider.startEditing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DuplicateEventsTest extends BaseWidgetTest {
@Test
public void testIssue354() throws IOException, JSONException {
final String method = "testIssue354";
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResultsAndSettings(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.duplicates);
provider.addResults(inputs.getResults());
Log.d(method, "Results executed at " + inputs.getResults().get(0).getExecutedAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MultidayAllDayEventTest extends BaseWidgetTest {
@Test
public void testInsidePeriod() throws IOException, JSONException {
final String method = "testInsidePeriod";
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResultsAndSettings(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.multi_day);
provider.addResults(inputs.getResults());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PastDueHeaderWithTasksTest extends BaseWidgetTest {
@Test
public void testPastDueHeaderWithTasks() throws IOException, JSONException {
final String method = "testPastDueHeaderWithTasks";
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResultsAndSettings(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.past_due_header_with_tasks);
provider.addResults(inputs.getResults());
Log.d(method, "Results executed at " + inputs.getResults().get(0).getExecutedAt());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.andstatus.todoagenda;

import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;

import org.andstatus.todoagenda.provider.QueryResultsStorage;
import org.json.JSONException;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;

/**
* @author [email protected]
*/
public class TasksFilteringAndOrderingTest extends BaseWidgetTest {

/**
* https://github.com/plusonelabs/calendar-widget/issues/356
*/
@Test
public void testNoFilters() throws IOException, JSONException {
final String method = "testNoFilters";
QueryResultsStorage inputs = provider.loadResultsAndSettings(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.filter_tasks_308_no_filters);
provider.addResults(inputs.getResults());
Log.d(method, "Results executed at " + inputs.getResults().get(0).getExecutedAt());

playResults(method);
assertEquals("Number of entries", 35, factory.getWidgetEntries().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TodaysColorsEventsTest extends BaseWidgetTest {
@Test
public void testIssue327() throws IOException, JSONException {
final String method = "testIssue327";
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResultsAndSettings(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.todays_colors);
provider.addResults(inputs.getResults());
Log.d(method, "Results executed at " + inputs.getResults().get(0).getExecutedAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class WrongDatesLostEventsTest extends BaseWidgetTest {
@Test
public void testIssue205() throws IOException, JSONException {
final String method = "testIssue205";
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResultsAndSettings(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.wrong_dates_lost_events);
provider.addResults(inputs.getResults());
Log.d(method, "Results executed at " + inputs.getResults().get(0).getExecutedAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class MockCalendarContentProvider {

private final static AtomicInteger lastWidgetId = new AtomicInteger(TEST_WIDGET_ID_MIN);
private final int widgetId;
private volatile InstanceSettings settings;

public static MockCalendarContentProvider getContentProvider() {
DateTimeZone zone = DateTimeZone.forID(ZONE_IDS[(int)(System.currentTimeMillis() % ZONE_IDS.length)]);
Expand All @@ -55,13 +56,19 @@ public static MockCalendarContentProvider getContentProvider() {

private MockCalendarContentProvider(Context context) {
this.context = context;
widgetId = lastWidgetId.incrementAndGet();
InstanceSettings instanceToReuse = AllSettings.getInstances(context).values().stream()
.filter(settings -> settings.getWidgetInstanceName().endsWith(InstanceSettings.TEST_REPLAY_SUFFIX)).findFirst().orElse(null);

widgetId = instanceToReuse == null ? lastWidgetId.incrementAndGet() : instanceToReuse.getWidgetId();
settings = new InstanceSettings(context, widgetId,
"ToDo Agenda " + widgetId + " " + InstanceSettings.TEST_REPLAY_SUFFIX);
AllSettings.addNew(context, settings);
}

public void setPreferences() {
public void updateAppSettings() {
InstanceSettings settings = AllSettings.instanceFromId(context, widgetId);
settings.setQueryResults(results);
AllSettings.loadFromTestData(context, settings);
settings.setResultsStorage(results);
AllSettings.addNew(context, settings);
}

public static void tearDown() {
Expand Down Expand Up @@ -143,7 +150,7 @@ public void saveSettings() {
ApplicationPreferences.save(getContext(), getWidgetId());
}

public QueryResultsStorage loadResults(Context context, @RawRes int jsonResId)
public QueryResultsStorage loadResultsAndSettings(Context context, @RawRes int jsonResId)
throws IOException, JSONException {
JSONObject json = new JSONObject(RawResourceUtils.getString(context, jsonResId));
json.getJSONObject(KEY_SETTINGS).put(PREF_WIDGET_ID, widgetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testTestMode() {
public void testTwoEventsToday() {
QueryResult input1 = addOneResult("");
QueryResult input2 = addOneResult("SOMETHING=1");
provider.setPreferences();
provider.updateAppSettings();

QueryResultsStorage.setNeedToStoreResults(true, provider.getWidgetId());
MyContentResolver resolver = new MyContentResolver(EventProviderType.CALENDAR, provider.getContext(), provider.getWidgetId());
Expand Down Expand Up @@ -119,7 +119,7 @@ private QueryResult queryList(MyContentResolver resolver, Uri uri, String select

@Test
public void testJsonToAndFrom() throws IOException, JSONException {
QueryResultsStorage inputs1 = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
QueryResultsStorage inputs1 = provider.loadResultsAndSettings(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.birthday);
JSONObject jsonOutput = inputs1.toJson(provider.getContext(), provider.getWidgetId(), true);
QueryResultsStorage inputs2 = QueryResultsStorage.fromTestData(provider.getContext(), jsonOutput);
Expand Down
Loading

0 comments on commit 041c48a

Please sign in to comment.