diff --git a/app/src/androidTest/kotlin/info/appdev/chartexample/StartTest.kt b/app/src/androidTest/kotlin/info/appdev/chartexample/StartTest.kt index ac45839743..24bdb4eef7 100644 --- a/app/src/androidTest/kotlin/info/appdev/chartexample/StartTest.kt +++ b/app/src/androidTest/kotlin/info/appdev/chartexample/StartTest.kt @@ -10,15 +10,23 @@ import androidx.test.core.graphics.writeToTestStorage import androidx.test.espresso.Espresso import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu +import androidx.test.espresso.ViewAction +import androidx.test.espresso.action.GeneralClickAction +import androidx.test.espresso.action.Press +import androidx.test.espresso.action.Tap import androidx.test.espresso.action.ViewActions.captureToBitmap import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.activityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation +import info.appdev.chartexample.compose.HorizontalBarComposeActivity +import info.appdev.chartexample.fragments.ViewPagerSimpleChartDemo +import info.appdev.chartexample.notimportant.ContentItem import info.appdev.chartexample.notimportant.DemoBase import info.appdev.chartexample.notimportant.DemoBase.Companion.optionMenus import info.appdev.chartexample.notimportant.DemoBaseCompose @@ -64,11 +72,16 @@ class StartTest { onView(ViewMatchers.isRoot()) .perform(captureToBitmap { bitmap: Bitmap -> bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") }) + var compose: Boolean var optionMenu = "" // iterate samples - only items with classes (not section headers) MainActivity.menuItems.forEachIndexed { index, contentItem -> contentItem.clazz?.let { contentClass -> - Timber.d("Intended #${index} ${contentClass.simpleName}: '${contentItem.name}'") + compose = false + Timber.d("Intended ${index}-${contentClass.simpleName}: ${contentItem.name}") + + if (contentItem.clazz == ViewPagerSimpleChartDemo::class.java || contentItem.clazz == ListViewBarChartActivity::class.java) + return@forEachIndexed try { // Use description to uniquely identify items since names can be duplicated @@ -124,6 +137,7 @@ class StartTest { ) } } else if (DemoBaseCompose::class.java.isAssignableFrom(contentClass)) { + compose = true // Test Compose dropdown menu for DemoBaseCompose activities Timber.d("Testing Compose menu for: ${contentClass.simpleName}") optionMenu = "" @@ -206,6 +220,9 @@ class StartTest { Timber.d("Unknown activity type: ${contentClass.simpleName}") } + if (!compose) + doClickTest(index, contentClass, contentItem) + //Thread.sleep(100) Espresso.pressBack() @@ -226,6 +243,47 @@ class StartTest { } } + private fun doClickTest(index: Int, contentClass: Class, contentItem: ContentItem) { + if (contentItem.clazz == ScrollViewActivity::class.java || + contentItem.clazz == DynamicalAddingActivity::class.java || + contentItem.clazz == RealtimeLineChartActivity::class.java || + contentItem.clazz == LineChartTimeActivity::class.java || + contentItem.clazz == HorizontalBarComposeActivity::class.java || + contentItem.clazz == GradientActivity::class.java || + contentItem.clazz == TimeLineActivity::class.java + ) { + // These charts have less clickable area, so skip further clicks + return + } + + onView(withId(R.id.chart1)).perform(click()) + onView(ViewMatchers.isRoot()) + .perform(captureToBitmap { bitmap: Bitmap -> + bitmap.writeToTestStorage( + "${javaClass.simpleName}_${nameRule.methodName}-${index}-${contentClass.simpleName}-${contentItem.name}-click" + .replace(" ", "") + ) + }) + + onView(withId(R.id.chart1)).perform(clickXY(20, 20)) + onView(ViewMatchers.isRoot()) + .perform(captureToBitmap { bitmap: Bitmap -> + bitmap.writeToTestStorage( + "${javaClass.simpleName}_${nameRule.methodName}-${index}-${contentClass.simpleName}-${contentItem.name}-click2020" + .replace(" ", "") + ) + }) + + onView(withId(R.id.chart1)).perform(clickXY(70, 70)) + onView(ViewMatchers.isRoot()) + .perform(captureToBitmap { bitmap: Bitmap -> + bitmap.writeToTestStorage( + "${javaClass.simpleName}_${nameRule.methodName}-${index}-${contentClass.simpleName}-${contentItem.name}-click7070" + .replace(" ", "") + ) + }) + } + private fun screenshotOfOptionMenu(simpleName: String, menuTitle: String) { onView(withText(menuTitle)).perform(click()) Timber.d("screenshotOfOptionMenu ${menuTitle}-${simpleName}") @@ -236,4 +294,20 @@ class StartTest { ) } + fun clickXY(x: Int, y: Int): ViewAction { + return GeneralClickAction( + Tap.SINGLE, + { view -> + val location = IntArray(2) + view!!.getLocationOnScreen(location) + val screenX = (location[0] + x).toFloat() + val screenY = (location[1] + y).toFloat() + floatArrayOf(screenX, screenY) + }, + Press.FINGER, + 0, // inputDevice + 0 // deviceState + ) + } + } diff --git a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt index ca7f75e02c..dca2a35e89 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/ListViewMultiChartActivity.kt @@ -61,7 +61,14 @@ class ListViewMultiChartActivity : DemoBase() { /** adapter that supports 3 different item types */ private class ChartDataAdapter(context: Context, chartItems: MutableList>) : ArrayAdapter>(context, 0, chartItems) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - return getItem(position)!!.getView(position, convertView, context)!! + return getItem(position)!!.getView(position, convertView, context)!!.apply { + // to find chart in Espresso test + when (position) { + 0 -> id = R.id.chart1 + 1 -> id = R.id.chart2 + 2 -> id = R.id.chart3 + } + } } override fun getItemViewType(position: Int): Int { diff --git a/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt b/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt index 728228526d..f90fe2b56f 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/data/CombinedData.kt @@ -140,7 +140,7 @@ class CombinedData : BarLineScatterCandleBubbleData