Skip to content

Commit

Permalink
Added test for tap zone start screen
Browse files Browse the repository at this point in the history
  • Loading branch information
max-kammerer committed Oct 15, 2023
1 parent 4353828 commit 99b3fd2
Showing 1 changed file with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package universe.constellation.orion.viewer.test.espresso

import android.content.Intent
import android.graphics.Rect
import android.view.View
import androidx.test.espresso.Espresso.*
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
Expand All @@ -11,6 +13,8 @@ import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.hamcrest.Matchers.*
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
Expand All @@ -22,8 +26,10 @@ import universe.constellation.orion.viewer.prefs.GlobalOptions
import universe.constellation.orion.viewer.prefs.OrionApplication
import universe.constellation.orion.viewer.test.framework.BookDescription
import universe.constellation.orion.viewer.test.framework.InstrumentationTestCase
import java.util.concurrent.atomic.AtomicReference

abstract class CheckTapZoneWelcomeScreen(private val showTapHelp: Boolean, intent: Intent) : InstrumentationTestCase() {

abstract class CheckTapZoneStartScreen(private val showTapHelp: Boolean, intent: Intent) : InstrumentationTestCase() {

@get:Rule
var activityScenarioRule = activityScenarioRule<OrionViewerActivity>(intent.apply {
Expand All @@ -33,12 +39,11 @@ abstract class CheckTapZoneWelcomeScreen(private val showTapHelp: Boolean, inten
putExtra(GlobalOptions.SHOW_TAP_HELP, false)
}
})

}
@RunWith(AndroidJUnit4::class)
class NoBookNoWelcome: CheckTapZoneWelcomeScreen(true, BookDescription.SICP.toOpenIntent().apply { data = null;}) {
class NoBookNoStartTapScreen: CheckTapZoneStartScreen(true, BookDescription.SICP.toOpenIntent().apply { data = null;}) {
@Test
fun testWelcome() {
fun testStartScreenAbsent() {
val options =
(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as OrionApplication).options
onView(withId(R.id.tap_help_close)).check(doesNotExist())
Expand All @@ -47,18 +52,41 @@ class NoBookNoWelcome: CheckTapZoneWelcomeScreen(true, BookDescription.SICP.toOp
}

@RunWith(AndroidJUnit4::class)
class BookWithWelcome: CheckTapZoneWelcomeScreen(true, BookDescription.SICP.toOpenIntent()) {
class BookWithStartTapScreen: CheckTapZoneStartScreen(true, BookDescription.SICP.toOpenIntent()) {
@Test
fun testWelcome() {
fun testStartScreen() {
val options =
(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as OrionApplication).options
assertTrue(options.isShowTapHelp)
onView(withId(R.id.tap_help_close)).check(matches(isDisplayed()))
onView(withId(R.id.tap_help_close)).perform(ViewActions.click())
onView(withId(R.id.tap_help_close)).check(matches(isDisplayed()))
onView(withId(R.id.tap_help_close)).check(doesNotExist())
//
// assertFalse(options.isShowTapHelp)
checkSizeAndPosition()

onView(withId(R.id.tap_help_close)).perform(click())
//onView(withId(R.id.tap_help_close)).check(doesNotExist())//TODO
assertFalse(options.isShowTapHelp)
}

private fun checkSizeAndPosition() {
val rect = AtomicReference<Rect>()
val loc = AtomicReference<IntArray>()
activityScenarioRule.scenario.onActivity { it ->
val r = Rect()
(it.view as View).getLocalVisibleRect(r)
rect.set(r)
val l = IntArray(2)
(it.view as View).getLocationOnScreen(l)
loc.set(l)
}

onView(withId(R.id.tap_help_close)).check { view, noViewFoundException ->
val dialogRect = Rect()
val rootView = view.rootView
rootView.getLocalVisibleRect(dialogRect)
assertEquals(rect.get(), dialogRect)

val l = IntArray(2)
rootView.getLocationOnScreen(l)
assertArrayEquals(loc.get(), l)
}
}
}

0 comments on commit 99b3fd2

Please sign in to comment.