|
| 1 | +package com.xxmassdeveloper.mpchartexample |
| 2 | + |
| 3 | +import android.view.View |
| 4 | +import android.widget.SeekBar |
| 5 | +import androidx.test.core.graphics.writeToTestStorage |
| 6 | +import androidx.test.espresso.Espresso.onView |
| 7 | +import androidx.test.espresso.UiController |
| 8 | +import androidx.test.espresso.ViewAction |
| 9 | +import androidx.test.espresso.matcher.ViewMatchers |
| 10 | +import androidx.test.espresso.matcher.ViewMatchers.withId |
| 11 | +import androidx.test.espresso.screenshot.captureToBitmap |
| 12 | +import androidx.test.ext.junit.rules.activityScenarioRule |
| 13 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 14 | +import org.hamcrest.Matcher |
| 15 | +import org.junit.Rule |
| 16 | +import org.junit.Test |
| 17 | +import org.junit.rules.TestName |
| 18 | +import org.junit.runner.RunWith |
| 19 | + |
| 20 | + |
| 21 | +@RunWith(AndroidJUnit4::class) |
| 22 | +class PieTest { |
| 23 | + |
| 24 | + @get:Rule |
| 25 | + val activityScenarioRule = activityScenarioRule<PiePolylineChartActivity>() |
| 26 | + |
| 27 | + @get:Rule |
| 28 | + var nameRule = TestName() |
| 29 | + |
| 30 | + @Test |
| 31 | + fun piePolyline() { |
| 32 | + onView(ViewMatchers.isRoot()) |
| 33 | + .captureToBitmap() |
| 34 | + .writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}") |
| 35 | + |
| 36 | + for(x in 10..50 step 10) { |
| 37 | + onView(withId(R.id.seekBar1)).perform(setProgress(x)) |
| 38 | + onView(ViewMatchers.isRoot()) |
| 39 | + .captureToBitmap() |
| 40 | + .writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}1-${x}") |
| 41 | + } |
| 42 | + |
| 43 | + for(x in 50..200 step 50) { |
| 44 | + onView(withId(R.id.seekBar2)).perform(setProgress(x)) |
| 45 | + onView(ViewMatchers.isRoot()) |
| 46 | + .captureToBitmap() |
| 47 | + .writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}2-${x}") |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + private fun setProgress(progress: Int): ViewAction { |
| 52 | + return object : ViewAction { |
| 53 | + override fun perform(uiController: UiController?, view: View) { |
| 54 | + val seekBar = view as SeekBar |
| 55 | + seekBar.progress = progress |
| 56 | + } |
| 57 | + |
| 58 | + override fun getDescription(): String { |
| 59 | + return "Set a progress on a SeekBar" |
| 60 | + } |
| 61 | + |
| 62 | + override fun getConstraints(): Matcher<View> { |
| 63 | + return ViewMatchers.isAssignableFrom(SeekBar::class.java) |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments