diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneWelcomeScreen.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneStartScreen.kt similarity index 54% rename from orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneWelcomeScreen.kt rename to orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneStartScreen.kt index 4fae1b4d5..b82e14b51 100644 --- a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneWelcomeScreen.kt +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneStartScreen.kt @@ -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 @@ -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 @@ -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(intent.apply { @@ -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()) @@ -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() + val loc = AtomicReference() + 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) + } } } \ No newline at end of file