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 4b93014 commit 65565b0
Showing 1 changed file with 85 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,25 @@ class ShareActivityTest : OrgzlyTest() {

@Test
fun testDefaultBookRemainsSetAfterRotation() {
val scenario = startActivityWithIntent(
startActivityWithIntent(
action = Intent.ACTION_SEND,
type = "text/plain",
extraText = "This is some shared text")
extraText = "This is some shared text").use { scenario ->

scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}

onView(withId(R.id.location_button))
onView(withId(R.id.location_button))
.check(matches(withText(context.getString(R.string.default_share_notebook))))

scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}

onView(withId(R.id.location_button))
onView(withId(R.id.location_button))
.check(matches(withText(context.getString(R.string.default_share_notebook))))
}
}

@Test
Expand All @@ -80,123 +81,126 @@ class ShareActivityTest : OrgzlyTest() {
testUtils.setupBook("book-two", "")
testUtils.setupBook("book-three", "")

val scenario = startActivityWithIntent(
startActivityWithIntent(
action = Intent.ACTION_SEND,
type = "text/plain",
extraText = "This is some shared text")
extraText = "This is some shared text").use { scenario ->

scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}

onView(withId(R.id.location_button)).perform(scroll(), click())
onView(withText("book-two")).perform(click())
onView(withId(R.id.location_button)).check(matches(withText("book-two")))
onView(withId(R.id.location_button)).perform(scroll(), click())
onView(withText("book-two")).perform(click())
onView(withId(R.id.location_button)).check(matches(withText("book-two")))

scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}

onView(withId(R.id.location_button)).check(matches(withText("book-two")))
onView(withId(R.id.location_button)).check(matches(withText("book-two")))
}
}

@Test
fun testDefaultBookName() {
startActivityWithIntent(
action = Intent.ACTION_SEND,
type = "text/plain",
extraText = "This is some shared text")

onView(withId(R.id.location_button))
extraText = "This is some shared text").use {
onView(withId(R.id.location_button))
.check(matches(withText(context.getString(R.string.default_share_notebook))))
}
}

@Test
fun testTextSimple() {
startActivityWithIntent(
action = Intent.ACTION_SEND,
type = "text/plain",
extraText = "This is some shared text")

onView(withId(R.id.done)).perform(click()); // Note done
extraText = "This is some shared text").use {
onView(withId(R.id.done)).perform(click()); // Note done
}
}

@Test
fun testSaveAfterRotation() {
val scenario = startActivityWithIntent(
startActivityWithIntent(
action = Intent.ACTION_SEND,
type = "text/plain",
extraText = "This is some shared text")
extraText = "This is some shared text").use { scenario ->

scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
onView(withId(R.id.done)).perform(click()); // Note done
}

onView(withId(R.id.done)).perform(click()); // Note done
}

@Test
fun testTextEmpty() {
startActivityWithIntent(action = Intent.ACTION_SEND, type = "text/plain", extraText = "")
onView(withId(R.id.done)).perform(click()); // Note done
startActivityWithIntent(action = Intent.ACTION_SEND, type = "text/plain", extraText = "").use {
onView(withId(R.id.done)).perform(click()); // Note done
}
}

@Test
fun testTextNull() {
startActivityWithIntent(action = Intent.ACTION_SEND, type = "text/plain")
onView(withId(R.id.done)).perform(click()); // Note done
startActivityWithIntent(action = Intent.ACTION_SEND, type = "text/plain").use {
onView(withId(R.id.done)).perform(click()); // Note done
}
}

@Test
fun testImage() {
startActivityWithIntent(
action = Intent.ACTION_SEND,
type = "image/png",
extraStreamUri = "content://uri")

onView(withId(R.id.title_view)).check(matches(withText("content://uri")))
onView(withId(R.id.content_view)).check(matches(withText("Cannot find image using this URI.")))

onView(withId(R.id.done)).perform(click()); // Note done
extraStreamUri = "content://uri").use {
onView(withId(R.id.title_view)).check(matches(withText("content://uri")))
onView(withId(R.id.content_view)).check(matches(withText("Cannot find image using this URI.")))
onView(withId(R.id.done)).perform(click()); // Note done
}
}

@Test
fun testNoMatchingType() {
startActivityWithIntent(action = Intent.ACTION_SEND, type = "application/octet-stream")

onView(withId(R.id.title_view)).check(matches(withText("")))
onSnackbar().check(matches(withText(context.getString(R.string.share_type_not_supported, "application/octet-stream"))))
startActivityWithIntent(action = Intent.ACTION_SEND, type = "application/octet-stream").use {
onView(withId(R.id.title_view)).check(matches(withText("")))
onSnackbar().check(matches(withText(context.getString(R.string.share_type_not_supported, "application/octet-stream"))))
}
}

@Test
fun testNoActionSend() {
startActivityWithIntent()

onView(withId(R.id.title_view)).check(matches(withText("")))
startActivityWithIntent().use {
onView(withId(R.id.title_view)).check(matches(withText("")))
}
}

@Test
fun testSettingScheduledTimeRemainsSetAfterRotation() {
val scenario = startActivityWithIntent(
startActivityWithIntent(
action = Intent.ACTION_SEND,
type = "text/plain",
extraText = "This is some shared text")
extraText = "This is some shared text").use { scenario ->

scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}

onView(withId(R.id.scheduled_button)).check(matches(withText("")))
onView(withId(R.id.scheduled_button)).perform(click())
onView(withText(R.string.set)).perform(click())
onView(withId(R.id.scheduled_button)).check(matches(withText(startsWith(defaultDialogUserDate()))))
onView(withId(R.id.scheduled_button)).check(matches(withText("")))
onView(withId(R.id.scheduled_button)).perform(click())
onView(withText(R.string.set)).perform(click())
onView(withId(R.id.scheduled_button)).check(matches(withText(startsWith(defaultDialogUserDate()))))

scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
scenario.onActivity { activity ->
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}

onView(withId(R.id.scheduled_button)).check(matches(withText(startsWith(defaultDialogUserDate()))))
onView(withId(R.id.scheduled_button)).check(matches(withText(startsWith(defaultDialogUserDate()))))
}
}

@Test
Expand All @@ -206,19 +210,19 @@ class ShareActivityTest : OrgzlyTest() {
startActivityWithIntent(
action = Intent.ACTION_SEND,
type = "text/plain",
extraText = "Note 3")

onView(withId(R.id.done)).perform(click()); // Note done

val (_, lft, rgt) = dataRepository.getLastNote("Note 1")!!.position
val (_, lft1, rgt1) = dataRepository.getLastNote("Note 2")!!.position
val (_, lft2, rgt2) = dataRepository.getLastNote("Note 3")!!.position

assertTrue(lft < lft1)
assertTrue(lft1 < rgt1)
assertTrue(rgt1 < rgt)
assertTrue(rgt < lft2)
assertTrue(lft2 < rgt2)
extraText = "Note 3").use {
onView(withId(R.id.done)).perform(click()); // Note done

val (_, lft, rgt) = dataRepository.getLastNote("Note 1")!!.position
val (_, lft1, rgt1) = dataRepository.getLastNote("Note 2")!!.position
val (_, lft2, rgt2) = dataRepository.getLastNote("Note 3")!!.position

assertTrue(lft < lft1)
assertTrue(lft1 < rgt1)
assertTrue(rgt1 < rgt)
assertTrue(rgt < lft2)
assertTrue(lft2 < rgt2)
}
}

@Test
Expand All @@ -229,8 +233,8 @@ class ShareActivityTest : OrgzlyTest() {
action = Intent.ACTION_SEND,
type = "text/plain",
extraText = "This is some shared text",
queryString = "b.foo")

onView(withId(R.id.location_button)).check(matches(withText("foo")))
queryString = "b.foo").use {
onView(withId(R.id.location_button)).check(matches(withText("foo")))
}
}
}

0 comments on commit 65565b0

Please sign in to comment.