Skip to content

Commit

Permalink
PAINTROID-185: Visibility of the text tool settings (Catrobat#1252)
Browse files Browse the repository at this point in the history
* PAINTROID-185: Visibility of the text tool settings
  • Loading branch information
bakicelebi authored May 13, 2023
1 parent 3dd8790 commit 0b55c54
Show file tree
Hide file tree
Showing 30 changed files with 517 additions and 173 deletions.
66 changes: 4 additions & 62 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withHint
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.google.android.material.button.MaterialButton
Expand Down Expand Up @@ -70,6 +69,11 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.math.roundToInt
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withHint
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import org.hamcrest.CoreMatchers.not

@RunWith(AndroidJUnit4::class)
@Suppress("LargeClass")
Expand Down Expand Up @@ -118,13 +122,12 @@ class TextToolIntegrationTest {
}

@Test
fun testTextToolStillEditableAfterClosingTextTool() {
fun testTextToolStillEditableAfterClickingInsideTheCanvasTextToolOptionsVisible() {
selectFormatting(FormattingOptions.ITALIC)
selectFormatting(FormattingOptions.BOLD)
selectFormatting(FormattingOptions.UNDERLINE)
enterTestText()
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))
onView(withId(R.id.pocketpaint_text_tool_dialog_input_text)).perform(click())
onView(withId(R.id.pocketpaint_text_tool_dialog_input_text)).perform(
ViewActions.replaceText(
TEST_TEXT_ADVANCED
Expand All @@ -134,6 +137,39 @@ class TextToolIntegrationTest {
boldToggleButton?.let { Assert.assertTrue(it.isChecked) }
underlinedToggleButton?.let { Assert.assertTrue(it.isChecked) }
Assert.assertEquals(TEST_TEXT_ADVANCED, textEditText?.text?.toString())
onView(withId(R.id.pocketpaint_text_tool_dialog_input_text)).check(matches(isDisplayed()))
onView(withId(R.id.pocketpaint_text_tool_dialog_list_font)).check(matches(isDisplayed()))
onView(withId(R.id.pocketpaint_text_tool_dialog_toggle_underlined)).check(matches(isDisplayed()))
onView(withId(R.id.pocketpaint_text_tool_dialog_toggle_italic)).check(matches(isDisplayed()))
onView(withId(R.id.pocketpaint_text_tool_dialog_toggle_bold)).check(matches(isDisplayed()))
onView(withId(R.id.pocketpaint_font_size_text)).check(matches(isDisplayed()))
}

@Test
fun testTextToolNotEditableAfterClickingOutsideTheCanvasTextToolOptionsHidden() {
selectFormatting(FormattingOptions.ITALIC)
selectFormatting(FormattingOptions.BOLD)
selectFormatting(FormattingOptions.UNDERLINE)
enterTestText()
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))

italicToggleButton?.let { Assert.assertTrue(it.isChecked) }
boldToggleButton?.let { Assert.assertTrue(it.isChecked) }
underlinedToggleButton?.let { Assert.assertTrue(it.isChecked) }
Assert.assertEquals(TEST_TEXT, textEditText?.text?.toString())
onView(withId(R.id.pocketpaint_text_tool_dialog_input_text))
.check(matches(not(isDisplayed())))
onView(withId(R.id.pocketpaint_text_tool_dialog_list_font))
.check(matches(not(isDisplayed())))
onView(withId(R.id.pocketpaint_text_tool_dialog_toggle_underlined))
.check(matches(not(isDisplayed())))
onView(withId(R.id.pocketpaint_text_tool_dialog_toggle_italic))
.check(matches(not(isDisplayed())))
onView(withId(R.id.pocketpaint_text_tool_dialog_toggle_bold))
.check(matches(not(isDisplayed())))
onView(withId(R.id.pocketpaint_font_size_text))
.check(matches(not(isDisplayed())))
}

@Ignore("Fix bug in own ticket , focus is not correctly implemented in google play either")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.catrobat.paintroid.test.junit.tools
import android.graphics.Bitmap
import android.graphics.PointF
import android.util.DisplayMetrics
import android.view.ViewGroup
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.rule.ActivityTestRule
Expand Down Expand Up @@ -83,6 +84,7 @@ class BaseToolWithRectangleShapeToolTest {
private val metrics: DisplayMetrics? = null
private var toolToTest: BaseToolWithRectangleShape? = null
private var idlingResource: CountingIdlingResource? = null
private val viewMock = Mockito.mock(ViewGroup::class.java)
@Before
fun setUp() {
idlingResource = launchActivityRule.activity.idlingResource
Expand Down Expand Up @@ -116,6 +118,8 @@ class BaseToolWithRectangleShapeToolTest {
rectHeight = (toolToTest as BaseToolWithRectangleShapeImpl).boxHeight
rotation = (toolToTest as BaseToolWithRectangleShapeImpl).boxRotation
symbolDistance = (toolToTest as BaseToolWithRectangleShapeImpl).rotationSymbolDistance
Mockito.`when`(toolOptionsViewController!!.toolSpecificOptionsLayout).thenReturn(viewMock)
Mockito.`when`(toolOptionsViewController.toolSpecificOptionsLayout).thenReturn(viewMock)
}

@After
Expand Down Expand Up @@ -429,6 +433,14 @@ class BaseToolWithRectangleShapeToolTest {
get() = 0
set(drawTime) {}

override fun handleUpAnimations(coordinate: PointF?) {
super.handleUp(coordinate)
}

override fun handleDownAnimations(coordinate: PointF?) {
super.handleUp(coordinate)
}

override fun toolPositionCoordinates(coordinate: PointF) = coordinate
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.catrobat.paintroid.test.junit.tools
import android.graphics.Color
import android.graphics.Paint
import android.graphics.PointF
import android.view.View
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.rule.ActivityTestRule
Expand Down Expand Up @@ -173,6 +174,10 @@ class BrushToolTest {

@Test
fun testShouldMovePathOnUpEvent() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)
whenever(workspace!!.contains(any<PointF>())).thenReturn(true)
whenever(toolPaint!!.paint).thenReturn(paint)
val event1 = PointF(0f, 0f)
Expand Down Expand Up @@ -206,6 +211,11 @@ class BrushToolTest {

@Test
fun testShouldAddCommandOnUpEvent() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)

whenever(workspace!!.contains(any())).thenReturn(true)
whenever(toolPaint!!.paint).thenReturn(paint)
val event = PointF(0f, 0f)
Expand Down Expand Up @@ -240,6 +250,11 @@ class BrushToolTest {

@Test
fun testShouldAddCommandOnTapEvent() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)

Mockito.`when`(workspace!!.contains(any<PointF>())).thenReturn(true)
Mockito.`when`(toolPaint!!.paint).thenReturn(paint)
val tap = PointF(5f, 5f)
Expand All @@ -256,6 +271,11 @@ class BrushToolTest {

@Test
fun testShouldAddCommandOnTapWithinToleranceEvent() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)

val tap1 = PointF(0f, 0f)
val tap2 = PointF(MOVE_TOLERANCE - .1f, 0f)
val tap3 = PointF(MOVE_TOLERANCE - 0.1f, MOVE_TOLERANCE - 0.1f)
Expand All @@ -276,6 +296,11 @@ class BrushToolTest {

@Test
fun testShouldAddPathCommandOnMultipleMovesWithinToleranceEvent() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)

Mockito.`when`(workspace!!.contains(any<PointF>())).thenReturn(true)
Mockito.`when`(toolPaint!!.paint).thenReturn(paint)
val tap1 = PointF(7f, 7f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.graphics.PointF
import android.os.Looper
import android.util.DisplayMetrics
import android.view.ViewConfiguration
import android.view.ViewGroup
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.platform.app.InstrumentationRegistry
Expand Down Expand Up @@ -73,6 +74,7 @@ class ClipboardToolTest {
private var tool: ClipboardTool? = null
private var idlingResource: CountingIdlingResource? = null

private val viewMock = Mockito.mock(ViewGroup::class.java)
@Rule
@JvmField
var launchActivityRule = ActivityTestRule(MainActivity::class.java)
Expand Down Expand Up @@ -100,6 +102,8 @@ class ClipboardToolTest {
commandManager!!,
0
)
Mockito.`when`(toolOptionsViewController.toolSpecificOptionsLayout).thenReturn(viewMock)
Mockito.`when`(toolOptionsViewController.toolSpecificOptionsLayout).thenReturn(viewMock)
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.catrobat.paintroid.test.junit.tools
import android.graphics.Color
import android.graphics.Paint
import android.graphics.PointF
import android.view.View
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.test.rule.ActivityTestRule
Expand Down Expand Up @@ -100,6 +101,11 @@ class CursorToolTest {

@Test
fun testShouldActivateCursorOnTapEvent() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)

val point = PointF(5f, 5f)
Mockito.`when`(workspace!!.contains(any<PointF>())).thenReturn(true)
Assert.assertTrue(toolToTest!!.handleDown(point))
Expand All @@ -110,6 +116,10 @@ class CursorToolTest {

@Test
fun testShouldActivateCursorOnTapEventOutsideDrawingSurface() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)
Mockito.`when`(workspace!!.contains(toolToTest!!.toolPosition)).thenReturn(true)
val point = PointF(-5f, -5f)
Assert.assertTrue(toolToTest!!.handleDown(point))
Expand All @@ -120,6 +130,11 @@ class CursorToolTest {

@Test
fun testShouldNotActivateCursorOnTapEvent() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)

val pointDown = PointF(0f, 0f)
val pointUp = PointF(pointDown.x + MOVE_TOLERANCE + 1, pointDown.y + MOVE_TOLERANCE + 1)

Expand Down Expand Up @@ -153,6 +168,11 @@ class CursorToolTest {

@Test
fun testShouldMovePathOnUpEvent() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)

Mockito.`when`(workspace!!.surfaceHeight).thenReturn(1920)
Mockito.`when`(workspace.surfaceWidth).thenReturn(1080)
Mockito.`when`(workspace.getSurfacePointFromCanvasPoint(any<PointF>())).thenAnswer { invocation -> copyPointF(invocation.getArgument<Any>(0) as PointF) }
Expand Down Expand Up @@ -199,6 +219,11 @@ class CursorToolTest {

@Test
fun testShouldCheckIfColorChangesIfToolIsActive() {
val viewMock = Mockito.mock(View::class.java)
Mockito.`when`(viewMock.visibility).thenReturn(View.VISIBLE)
Mockito.`when`(brushToolOptionsView!!.getTopToolOptions()).thenReturn(viewMock)
Mockito.`when`(brushToolOptionsView.getBottomToolOptions()).thenReturn(viewMock)

Mockito.`when`(workspace!!.contains(toolToTest!!.toolPosition)).thenReturn(true)
Mockito.`when`(toolPaint!!.color).thenReturn(Color.RED)
Assert.assertFalse(toolToTest!!.toolInDrawMode)
Expand Down
Loading

0 comments on commit 0b55c54

Please sign in to comment.