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 14aee88 commit cb75a86
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.orgzly.android.OrgzlyTest;
import com.orgzly.android.ui.main.MainActivity;

import org.junit.After;
import org.junit.Test;

import static androidx.test.espresso.Espresso.onView;
Expand All @@ -24,10 +25,19 @@
import static org.hamcrest.Matchers.endsWith;

public class NewNoteTest extends OrgzlyTest {
private ActivityScenario<MainActivity> scenario;

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

@Test
public void testNewNoteInEmptyNotebook() {
testUtils.setupBook("notebook", "");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

onBook(0).perform(click());

Expand All @@ -43,7 +53,7 @@ public void testNewNoteInEmptyNotebook() {
@Test
public void testNewNoteUnder() {
testUtils.setupBook("notebook", "description\n* 1\n** 2\n*** 3\n*** 4\n** 5\n* 6");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

onBook(0).perform(click());

Expand All @@ -62,7 +72,7 @@ public void testNewNoteUnder() {
@Test
public void testNewNoteAbove() {
testUtils.setupBook("notebook", "description\n* 1\n** 2\n*** 3\n*** 4\n** 5\n* 6");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

onBook(0).perform(click());

Expand All @@ -86,7 +96,7 @@ public void testNewNoteBelow() {
"*** 4\n" +
"** 5\n" +
"* 6");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

onBook(0).perform(click());

Expand Down Expand Up @@ -115,7 +125,7 @@ public void testNewNoteBelow() {
@Test
public void testNewNoteAfterMovingNotesAround() {
testUtils.setupBook("notebook-1", "");
ActivityScenario.launch(MainActivity.class);
scenario = ActivityScenario.launch(MainActivity.class);

onBook(0).perform(click());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import com.orgzly.android.ui.main.MainActivity
import com.orgzly.org.datetime.OrgDateTime
import org.hamcrest.Matchers.not
import org.hamcrest.Matchers.startsWith
import org.junit.After
import org.junit.Test


class NoteEventsTest : OrgzlyTest() {
private lateinit var scenario: ActivityScenario<MainActivity>
private val now: String
get() = OrgDateTime(true).toString()

Expand Down Expand Up @@ -55,10 +57,16 @@ class NoteEventsTest : OrgzlyTest() {
.build()
.toString()

@After
override fun tearDown() {
super.tearDown()
scenario.close()
}

@Test
fun search_OneInTitle() {
testUtils.setupBook("book-a", "* Note $now")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.ge.today")
onNotesInSearch().check(matches(recyclerViewItemCount(1)))
Expand All @@ -67,7 +75,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun search_OneInContent() {
testUtils.setupBook("book-a", "* Note\n$now")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.ge.today")
onNotesInSearch().check(matches(recyclerViewItemCount(1)))
Expand All @@ -76,7 +84,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun search_TwoSameInContent() {
testUtils.setupBook("book-a", "* Note\n$now $now")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.ge.today")
onNotesInSearch().check(matches(recyclerViewItemCount(1)))
Expand All @@ -85,7 +93,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun agenda_OneInTitle() {
testUtils.setupBook("book-a", "* Note $now")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.1")
onNotesInAgenda().check(matches(recyclerViewItemCount(2)))
Expand All @@ -94,7 +102,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun agenda_TwoInTitle() {
testUtils.setupBook("book-a", "* Note $now $tomorrow")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.2")
onNotesInAgenda().check(matches(recyclerViewItemCount(4)))
Expand All @@ -103,7 +111,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun agenda_OneInContent() {
testUtils.setupBook("book-a", "* Note\n$now")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.1")
onNotesInAgenda().check(matches(recyclerViewItemCount(2)))
Expand All @@ -112,7 +120,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun agenda_TwoInContent() {
testUtils.setupBook("book-a", "* Note\n$now $tomorrow")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.2")
onNotesInAgenda().check(matches(recyclerViewItemCount(4)))
Expand All @@ -138,7 +146,7 @@ class NoteEventsTest : OrgzlyTest() {
Tomorrow: ${time(1000 * 60 * 60 * 24, hasTime = true)}"
""".trimIndent())

ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.5")

Expand Down Expand Up @@ -182,7 +190,7 @@ class NoteEventsTest : OrgzlyTest() {
Tomorrow: ${time(1000 * 60 * 60 * 24, hasTime = true)}"
""".trimIndent())

ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("b.book-a")

Expand All @@ -198,7 +206,7 @@ class NoteEventsTest : OrgzlyTest() {
testUtils.setupBook(
"book-a",
"* Today $today\n* In few days $inFewDays\n* Today & In few days $today $inFewDays")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.gt.1d")
onNotesInSearch().check(matches(recyclerViewItemCount(2)))
Expand All @@ -207,7 +215,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun agenda_PastEvent() {
testUtils.setupBook("book-a", "* Few days ago\n$fewDaysAgo")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("ad.2")
onNotesInAgenda().check(matches(recyclerViewItemCount(2)))
Expand All @@ -216,7 +224,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun agendaSearch_TwoWithScheduledTime() {
testUtils.setupBook("book-a", "* $yesterday $fewDaysAgo\nSCHEDULED: $tomorrow")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.lt.now ad.3")
onNotesInAgenda().check(matches(recyclerViewItemCount(4)))
Expand All @@ -230,7 +238,7 @@ class NoteEventsTest : OrgzlyTest() {
* Note A-01
$today $tomorrow
""".trimIndent())
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.today")
onNotesInSearch().check(matches(recyclerViewItemCount(1)))
Expand All @@ -247,7 +255,7 @@ class NoteEventsTest : OrgzlyTest() {
* Note A-02
<2000-01-12>
""".trimIndent())
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.lt.now o.e")
onNotesInSearch().check(matches(recyclerViewItemCount(2)))
Expand All @@ -265,7 +273,7 @@ class NoteEventsTest : OrgzlyTest() {
* Note A-02
<2000-01-12>
""".trimIndent())
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText("e.lt.now .o.e")
onNotesInSearch().check(matches(recyclerViewItemCount(2)))
Expand All @@ -276,7 +284,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun shiftFromList() {
testUtils.setupBook("Book A", "* Note A-01 <2000-01-10 +1d>")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

onBook(0).perform(click())
onNoteInBook(1, R.id.item_head_title_view).check(matches(withText("Note A-01 <2000-01-10 +1d>")))
Expand All @@ -288,7 +296,7 @@ class NoteEventsTest : OrgzlyTest() {
@Test
fun shiftFromNote() {
testUtils.setupBook("Book A", "* Note A-01 <2000-01-10 +1d>")
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

onBook(0).perform(click())
onNoteInBook(1).perform(click())
Expand All @@ -306,7 +314,7 @@ class NoteEventsTest : OrgzlyTest() {
* Note A-01
SCHEDULED: $tomorrow
""".trimIndent())
ActivityScenario.launch(MainActivity::class.java)
scenario = ActivityScenario.launch(MainActivity::class.java)

searchForText(".it.done ad.7 o.e")

Expand Down
Loading

0 comments on commit cb75a86

Please sign in to comment.