Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand All @@ -44,6 +45,8 @@ import org.catrobat.paintroid.R
import org.catrobat.paintroid.colorpicker.HSVColorPickerView
import org.catrobat.paintroid.colorpicker.PresetSelectorView
import org.catrobat.paintroid.colorpicker.RgbSelectorView
import org.catrobat.paintroid.test.espresso.util.EspressoUtils
import org.catrobat.paintroid.test.espresso.util.UiInteractions.waitFor
import org.catrobat.paintroid.test.espresso.util.UiMatcher.withBackground
import org.catrobat.paintroid.test.espresso.util.UiMatcher.withBackgroundColor
import org.catrobat.paintroid.test.espresso.util.wrappers.BottomNavigationViewInteraction.Companion.onBottomNavigationView
Expand All @@ -57,7 +60,6 @@ import org.catrobat.paintroid.tools.ToolType
import org.catrobat.paintroid.tools.options.ToolOptionsViewController
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.not
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
Expand Down Expand Up @@ -97,26 +99,30 @@ class LandscapeIntegrationTest {
}

@Test
fun testTools() {
fun testIfClickingOnCurrentToolTogglesToolOptions() {
setOrientation(SCREEN_ORIENTATION_LANDSCAPE)
for (toolType in ToolType.values()) {
val tool = toolType == ToolType.IMPORTPNG ||
toolType == ToolType.COLORCHOOSER ||
toolType == ToolType.REDO ||
toolType == ToolType.UNDO ||
toolType == ToolType.LAYER ||
toolType == ToolType.CLIPBOARD ||
toolType == ToolType.TEXT ||
!toolType.hasOptions()
if (tool) { continue }
onToolBarView()
.performSelectTool(toolType)
if (toolOptionsViewController?.isVisible?.not() == true) {
if (toolOptionsViewController?.isVisible == false) {
onToolBarView()
.performClickSelectedToolButton()
}
onBottomNavigationView()
.onCurrentClicked()
onView(withId(R.id.pocketpaint_layout_tool_specific_options))
.check(matches(not(isDisplayed())))
EspressoUtils.waitForViewToDisappear(withId(R.id.pocketpaint_layout_tool_specific_options))
// BaseRobot().waitForViewToDisappear(withId(R.id.pocketpaint_layout_tool_specific_options)).check(matches(not(isDisplayed())))
// onView(withId(R.id.pocketpaint_layout_tool_specific_options))
// .check(matches(not(isDisplayed())))
}
}

Expand Down Expand Up @@ -408,6 +414,7 @@ class LandscapeIntegrationTest {
@Test
fun testIfCurrentToolIsShownInBottomNavigation() {
setOrientation(SCREEN_ORIENTATION_LANDSCAPE)
onView(isRoot()).perform(waitFor(5000))
for (toolType in ToolType.values()) {
val tools = toolType == ToolType.IMPORTPNG ||
toolType == ToolType.COLORCHOOSER ||
Expand All @@ -416,15 +423,39 @@ class LandscapeIntegrationTest {
toolType == ToolType.LAYER ||
!toolType.hasOptions()
if (tools) { continue }
onView(isRoot()).perform(waitFor(5000))
onToolBarView()
.performSelectTool(toolType)
onBottomNavigationView()
.checkShowsCurrentTool(toolType)
onView(isRoot()).perform(waitFor(500))
onBottomNavigationView().checkShowsCurrentTool(toolType)
onView(isRoot()).perform(waitFor(5000))
}
}

private fun setOrientation(orientation: Int) { activityTestRule.activity.requestedOrientation = orientation }

/*private fun checkShowsCurrentTool(toolType: ToolType) {
var matcher = allOf(withId(R.id.icon),
ViewMatchers.isDescendantOfA(withId(R.id.action_current_tool))
)
var assertion = ViewAssertions.matches(
Matchers.allOf(
isDisplayed(),
UiMatcher.withDrawable(toolType.drawableResource)
)
)
EspressoUtils.assertOnView(matcher, assertion)

matcher = withId(R.id.action_current_tool)
assertion = ViewAssertions.matches(
Matchers.allOf(
isDisplayed(),
ViewMatchers.hasDescendant(withText(toolType.nameResource))
)
)
EspressoUtils.assertOnView(matcher, assertion)
}*/

companion object {
@ColorInt
private fun getColorArrayFromResource(context: Context, @ArrayRes id: Int): IntArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ class LayerIntegrationTest {
LayerMenuViewInteraction.onLayerMenuView()
.performOpen()
.performSetOpacityTo(50, 0)
.performClose()

LayerMenuViewInteraction.onLayerMenuView().performClose()

ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.PIPETTE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import android.app.Instrumentation.ActivityResult
import android.content.Context
import android.content.Intent
import androidx.test.espresso.Espresso
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.RootMatchers
Expand Down Expand Up @@ -65,9 +67,22 @@ class MoreOptionsIntegrationTest {
@JvmField
@Rule
var screenshotOnFailRule = ScreenshotOnFailRule()

private var idlingResource: CountingIdlingResource? = null
private var mainActivity: MainActivity? = null
var defaultPictureName = "moreOptionsImageTest"

companion object {
@JvmField
@ClassRule
var grantPermissionRule = grantPermissionRulesVersionCheck()
}

@Before
fun setUp() {
mainActivity = activityTestRule.activity
idlingResource = mainActivity?.idlingResource
IdlingRegistry.getInstance().register(idlingResource)
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
activityTestRule.activity.getPreferences(Context.MODE_PRIVATE)
Expand All @@ -78,6 +93,7 @@ class MoreOptionsIntegrationTest {

@After
fun tearDown() {
IdlingRegistry.getInstance().unregister(idlingResource)
activityTestRule.activity.getPreferences(Context.MODE_PRIVATE)
.edit()
.clear()
Expand Down Expand Up @@ -275,10 +291,4 @@ class MoreOptionsIntegrationTest {
Espresso.onView(withText(R.string.cancel_button_text)).perform(ViewActions.click())
Assert.assertTrue("Smoothing is off after cancel!", AdvancedSettingsAlgorithms.smoothing)
}

companion object {
@JvmField
@ClassRule
var grantPermissionRule = grantPermissionRulesVersionCheck()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ package org.catrobat.paintroid.test.espresso
import android.content.Intent
import android.graphics.Color
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.catrobat.paintroid.MainActivity
Expand All @@ -31,13 +35,15 @@ import org.catrobat.paintroid.common.TEMP_IMAGE_PATH
import org.catrobat.paintroid.test.espresso.util.BitmapLocationProvider
import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider
import org.catrobat.paintroid.test.espresso.util.UiInteractions
import org.catrobat.paintroid.test.espresso.util.UiInteractions.waitFor
import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.Companion.onDrawingSurfaceView
import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction
import org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction
import org.catrobat.paintroid.tools.ToolReference
import org.catrobat.paintroid.tools.ToolType
import org.catrobat.paintroid.tools.Workspace
import org.catrobat.paintroid.ui.Perspective
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -58,13 +64,17 @@ class TemporaryFileSavingTest {
private lateinit var toolReference: ToolReference
private lateinit var mainActivity: MainActivity
private lateinit var intent: Intent
private var idlingResource: CountingIdlingResource? = null

@Before
fun setUp() {
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.BRUSH)
intent = Intent().putExtra("isTemporaryFileSavingTest", true)
mainActivity = launchActivityRule.launchActivity(intent)
idlingResource = mainActivity.idlingResource
IdlingRegistry.getInstance().register(idlingResource)
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.BRUSH)

workspace = mainActivity.workspace
perspective = mainActivity.perspective
toolReference = mainActivity.toolReference
Expand All @@ -74,6 +84,9 @@ class TemporaryFileSavingTest {
}
}

@After
fun tearDown() { IdlingRegistry.getInstance().unregister(idlingResource) }

@Test
fun testOneUserInteraction() {
onDrawingSurfaceView()
Expand Down Expand Up @@ -110,15 +123,20 @@ class TemporaryFileSavingTest {
fun testMultipleUserInteractions() {
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))
onView(isRoot()).perform(waitFor(1000))
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT))
Thread.sleep(THREAD_WAITING_TIME)
onView(isRoot()).perform(waitFor(1000))
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_RIGHT))
Thread.sleep(THREAD_WAITING_TIME)
onView(isRoot()).perform(waitFor(1000))
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_LEFT))
Thread.sleep(4000)
onView(isRoot()).perform(waitFor(5000))
launchActivityRule.finishActivity()
onView(isRoot()).perform(waitFor(1000))
Thread.sleep(1000)
launchActivityRule.launchActivity(intent)
onDrawingSurfaceView()
.checkPixelColor(Color.BLACK, BitmapLocationProvider.MIDDLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@
package org.catrobat.paintroid.test.espresso.tools

import androidx.test.espresso.Espresso
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.test.espresso.rtl.util.RtlActivityTestRule
import org.catrobat.paintroid.test.espresso.util.ViewRobot
import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule
import org.catrobat.paintroid.tools.ToolType
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
Expand All @@ -47,14 +51,21 @@ class ImportToolIntegrationTest {
@get:Rule
var screenshotOnFailRule = ScreenshotOnFailRule()
private var mainActivity: MainActivity? = null
private var idlingResource: CountingIdlingResource? = null

@Before
fun setUp() {
mainActivity = launchActivityRule.activity
ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.IMPORTPNG)
idlingResource = mainActivity?.idlingResource
IdlingRegistry.getInstance().register(idlingResource)
}

@After
fun tearDown() { IdlingRegistry.getInstance().unregister(idlingResource) }

@Test
fun testImportDialogShownOnImportToolSelected() {
ToolBarViewInteraction.onToolBarView().performSelectTool(ToolType.IMPORTPNG)
Espresso.onView(ViewMatchers.withId(R.id.pocketpaint_dialog_import_stickers))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
Espresso.onView(ViewMatchers.withId(R.id.pocketpaint_dialog_import_gallery))
Expand All @@ -63,8 +74,6 @@ class ImportToolIntegrationTest {

@Test
fun testImportDialogDismissedOnCancelClicked() {
Espresso.onView(ViewMatchers.withText(R.string.pocketpaint_cancel))
.perform(ViewActions.click())
Espresso.onView(ViewMatchers.withId(R.id.pocketpaint_dialog_import_stickers))
.check(ViewAssertions.doesNotExist())
Espresso.onView(ViewMatchers.withId(R.id.pocketpaint_dialog_import_gallery))
Expand All @@ -73,17 +82,14 @@ class ImportToolIntegrationTest {

@Test
fun testImportDoesNotResetPerspectiveScale() {
Espresso.onView(ViewMatchers.withText(R.string.pocketpaint_cancel))
.perform(ViewActions.click())
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.BRUSH)
val scale = 2.0f
mainActivity?.perspective?.scale = scale
mainActivity?.refreshDrawingSurface()
ToolBarViewInteraction.onToolBarView()
.performSelectTool(ToolType.IMPORTPNG)
Espresso.onView(ViewMatchers.withText(R.string.pocketpaint_cancel))
.perform(ViewActions.click())
ViewRobot().doOnView(ViewMatchers.withText(R.string.pocketpaint_cancel), ViewActions.click())
mainActivity?.perspective?.let { Assert.assertEquals(scale, it.scale, Float.MIN_VALUE) }
}
}
Loading