Skip to content

Commit

Permalink
fixup! Ensure that activities are fully deleted between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amberin committed Mar 17, 2024
1 parent fbdab3b commit 14aee88
Showing 1 changed file with 79 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import com.orgzly.android.ui.main.MainActivity;

import org.joda.time.DateTime;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;

public class AgendaFragmentTest extends OrgzlyTest {
private ActivityScenario<MainActivity> scenario;
private ActivityScenario<MainActivity> defaultSetUp() {
testUtils.setupBook("book-one",
"First book used for testing\n" +
Expand All @@ -62,26 +64,32 @@ private ActivityScenario<MainActivity> defaultSetUp() {
return ActivityScenario.launch(MainActivity.class);
}

@After
@Override
public void tearDown() throws Exception {
super.tearDown();
scenario.close();
}

@Test
public void testAgendaSavedSearch() {
try (ActivityScenario<MainActivity> ignored = defaultSetUp()) {
searchForText(".it.done ad.7");
/*
* 1 Overdue
* 1 Note B
* 1 Note C
* 1 Note 2
* 7 Day
* 7 Note C
* 7 Note 2
*/
onView(withId(R.id.fragment_query_agenda_recycler_view)).check(matches(recyclerViewItemCount(25)));
}
scenario = defaultSetUp();
searchForText(".it.done ad.7");
/*
* 1 Overdue
* 1 Note B
* 1 Note C
* 1 Note 2
* 7 Day
* 7 Note C
* 7 Note 2
*/
onView(withId(R.id.fragment_query_agenda_recycler_view)).check(matches(recyclerViewItemCount(25)));
}

@Test
public void testWithNoBook() {
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);
searchForText(".it.done (s.7d or d.7d) ad.7");
onNotesInAgenda().check(matches(recyclerViewItemCount(7)));
searchForText(".it.done (s.7d or d.7d) ad.3");
Expand All @@ -90,17 +98,16 @@ public void testWithNoBook() {

@Test
public void testDayAgenda() {
try (ActivityScenario<MainActivity> ignored = defaultSetUp()) {
searchForText(".it.done (s.7d or d.7d) ad.1");
onNotesInAgenda().check(matches(recyclerViewItemCount(7)));
onItemInAgenda(0, R.id.item_agenda_divider_text).check(matches(allOf(withText(R.string.overdue), isDisplayed())));
onItemInAgenda(1, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note B")), isDisplayed())));
onItemInAgenda(2, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note C")), isDisplayed())));
onItemInAgenda(3, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note 2")), isDisplayed())));
// Day 1
onItemInAgenda(5, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note C")), isDisplayed())));
onItemInAgenda(6, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note 2")), isDisplayed())));
}
scenario = defaultSetUp();
searchForText(".it.done (s.7d or d.7d) ad.1");
onNotesInAgenda().check(matches(recyclerViewItemCount(7)));
onItemInAgenda(0, R.id.item_agenda_divider_text).check(matches(allOf(withText(R.string.overdue), isDisplayed())));
onItemInAgenda(1, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note B")), isDisplayed())));
onItemInAgenda(2, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note C")), isDisplayed())));
onItemInAgenda(3, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note 2")), isDisplayed())));
// Day 1
onItemInAgenda(5, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note C")), isDisplayed())));
onItemInAgenda(6, R.id.item_head_title_view).check(matches(allOf(withText(endsWith("Note 2")), isDisplayed())));
}

@Test
Expand All @@ -111,73 +118,68 @@ public void testAgendaRangeEvent() {
"* Event A.\n" +
"<" + start.toString() + ">--<" + end.toString() + ">\n");

ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.5");
onNotesInAgenda().check(matches(recyclerViewItemCount(10)));
}

@Test
public void testOneTimeTaskMarkedDone() {
try (ActivityScenario<MainActivity> ignored = defaultSetUp()) {
searchForText(".it.done ad.7");
/*
* 1 Overdue
* 1 Note B <- Mark as done
* 1 Note C
* 1 Note 2
* 7 Day
* 7 Note C
* 7 Note 2
*/
onItemInAgenda(1).perform(longClick());
onView(withId(R.id.toggle_state)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(24)));
}
scenario = defaultSetUp();
searchForText(".it.done ad.7");
/*
* 1 Overdue
* 1 Note B <- Mark as done
* 1 Note C
* 1 Note 2
* 7 Day
* 7 Note C
* 7 Note 2
*/
onItemInAgenda(1).perform(longClick());
onView(withId(R.id.toggle_state)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(24)));
}

@Test
public void testRepeaterTaskMarkedDone() {
try (ActivityScenario<MainActivity> ignored = defaultSetUp()) {
searchForText(".it.done ad.7");
onItemInAgenda(2).perform(longClick());
onView(withId(R.id.toggle_state)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(23)));
}
scenario = defaultSetUp();
searchForText(".it.done ad.7");
onItemInAgenda(2).perform(longClick());
onView(withId(R.id.toggle_state)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(23)));
}

@Test
public void testRangeTaskMarkedDone() {
try (ActivityScenario<MainActivity> ignored = defaultSetUp()) {
searchForText(".it.done ad.7");
onItemInAgenda(3).perform(longClick());
onView(withId(R.id.toggle_state)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(17)));

}
scenario = defaultSetUp();
searchForText(".it.done ad.7");
onItemInAgenda(3).perform(longClick());
onView(withId(R.id.toggle_state)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(17)));
}

@Test
public void testMoveTaskWithRepeaterToTomorrow() {
DateTime tomorrow = DateTime.now().withTimeAtStartOfDay().plusDays(1);
try (ActivityScenario<MainActivity> ignored = defaultSetUp()) {
searchForText(".it.done ad.7");
onItemInAgenda(2).perform(longClick());
onView(withId(R.id.schedule)).perform(click());
onView(withId(R.id.date_picker_button)).perform(click());
onView(withClassName(equalTo(DatePicker.class.getName())))
.perform(PickerActions.setDate(
tomorrow.getYear(),
tomorrow.getMonthOfYear(),
tomorrow.getDayOfMonth()));
onView(withText(android.R.string.ok)).perform(click());
onView(withText(R.string.set)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(23)));
}
scenario = defaultSetUp();
searchForText(".it.done ad.7");
onItemInAgenda(2).perform(longClick());
onView(withId(R.id.schedule)).perform(click());
onView(withId(R.id.date_picker_button)).perform(click());
onView(withClassName(equalTo(DatePicker.class.getName())))
.perform(PickerActions.setDate(
tomorrow.getYear(),
tomorrow.getMonthOfYear(),
tomorrow.getDayOfMonth()));
onView(withText(android.R.string.ok)).perform(click());
onView(withText(R.string.set)).perform(click());
onNotesInAgenda().check(matches(recyclerViewItemCount(23)));
}

@Test
public void testPersistedSpinnerSelection() {
ActivityScenario<MainActivity> scenario = defaultSetUp();
scenario = defaultSetUp();

searchForText(".it.done ad.7");
onNotesInAgenda().check(matches(recyclerViewItemCount(25)));
Expand All @@ -186,7 +188,6 @@ public void testPersistedSpinnerSelection() {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE));

onNotesInAgenda().check(matches(recyclerViewItemCount(25)));
scenario.close();
}

@Test
Expand All @@ -196,7 +197,7 @@ public void testDeselectRemovedNoteInAgenda() {
"* TODO Note A\nSCHEDULED: <2018-01-01 +1d>\n" +
"* TODO Note B\nSCHEDULED: <2018-01-01 .+1d>\n");

ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

searchForText("i.todo ad.3");

Expand All @@ -223,7 +224,7 @@ public void testDeselectRemovedNoteInAgenda() {
@Test
public void testPreselectedStateOfSelectedNote() {
testUtils.setupBook("notebook", "* TODO Note A\nSCHEDULED: <2018-01-01 +1d>");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

searchForText("ad.3");

Expand All @@ -236,7 +237,7 @@ public void testPreselectedStateOfSelectedNote() {
@Test
public void testSwipeDivider() {
testUtils.setupBook("notebook", "* TODO Note A\nSCHEDULED: <2018-01-01 +1d>");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.3");
onItemInAgenda(0).perform(swipeLeft());
onItemInAgenda(2).perform(swipeLeft());
Expand All @@ -246,7 +247,7 @@ public void testSwipeDivider() {
@Test
public void testOpenCorrectNote() {
testUtils.setupBook("notebook", "* TODO Note A\nSCHEDULED: <2018-01-01 +1d>");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

searchForText("ad.3");

Expand All @@ -261,7 +262,7 @@ public void testChangeStateWithReverseNoteClick() {
testUtils.setupBook("book-1","* DONE Note A");
testUtils.setupBook("book-2","* TODO Note B\nSCHEDULED: <2014-01-01>\n* TODO Note C\nSCHEDULED: <2014-01-02>\n");
AppPreferences.isReverseNoteClickAction(context, false);
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

searchForText(".it.done ad.7");
onItemInAgenda(1).perform(longClick());
Expand All @@ -272,7 +273,7 @@ public void testChangeStateWithReverseNoteClick() {
@Test
public void testInactiveScheduled() {
testUtils.setupBook("notebook-1", "* Note A\nSCHEDULED: [2020-07-01]\nDEADLINE: <2020-07-01>");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.1");
// Overdue, note (deadline), today
onNotesInAgenda().check(matches(recyclerViewItemCount(3)));
Expand All @@ -281,7 +282,7 @@ public void testInactiveScheduled() {
@Test
public void testInactiveDeadline() {
testUtils.setupBook("notebook-1", "* Note A\nDEADLINE: [2020-07-01]\nSCHEDULED: <2020-07-01>");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.1");
// Overdue, note (scheduled), today
onNotesInAgenda().check(matches(recyclerViewItemCount(3)));
Expand All @@ -290,7 +291,7 @@ public void testInactiveDeadline() {
@Test
public void testInactiveScheduledAndDeadline() {
testUtils.setupBook("notebook-1", "* Note A\nSCHEDULED: [2020-07-01]\nDEADLINE: [2020-07-01]");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);
searchForText("ad.1");
// Today
onNotesInAgenda().check(matches(recyclerViewItemCount(1)));
Expand Down

0 comments on commit 14aee88

Please sign in to comment.