Skip to content

Commit

Permalink
PAINTROID-396 Multiline tool with movable intermediate points
Browse files Browse the repository at this point in the history
test undo
  • Loading branch information
Lenkomotive committed Jul 27, 2023
1 parent 4ff166c commit a4c9d45
Showing 1 changed file with 100 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,48 +368,6 @@ class DynamicLineToolIntegrationTest {
TopBarViewInteraction.onTopBarView().performClickCheckmark()
}

@Test
fun testColorChangesInConnectedLineMode() {
ToolPropertiesInteraction.onToolProperties().setColor(Color.parseColor(colorStringBlack))

touchAt(DrawingSurfaceLocationProvider.HALFWAY_LEFT_MIDDLE)
touchAt(DrawingSurfaceLocationProvider.HALFWAY_RIGHT_MIDDLE)

TopBarViewInteraction.onTopBarView().performClickPlus()

touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_RIGHT)

TestUtils.selectColorInDialog(0)
checkPixelColor(colorStringIndex0, BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT)

TestUtils.selectColorInDialog(1)
checkPixelColor(colorStringIndex1, BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT)

TopBarViewInteraction.onTopBarView().performUndo()
checkPixelColor(colorStringIndex0, BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT)

TopBarViewInteraction.onTopBarView().performRedo()
checkPixelColor(colorStringIndex1, BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT)

TopBarViewInteraction.onTopBarView().performUndo()
TopBarViewInteraction.onTopBarView().performUndo()
TopBarViewInteraction.onTopBarView().performUndo()

checkPixelColor(colorStringTransparent, BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT)

TopBarViewInteraction.onTopBarView().performUndo()
checkPixelColor(colorStringTransparent, BitmapLocationProvider.MIDDLE)

TopBarViewInteraction.onTopBarView().performRedo()
TopBarViewInteraction.onTopBarView().performRedo()
TopBarViewInteraction.onTopBarView().performRedo()
TopBarViewInteraction.onTopBarView().performRedo()

checkPixelColor(colorStringIndex0, BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT)

TopBarViewInteraction.onTopBarView().performClickCheckmark()
}

@Test
fun testColorChangesAndQuittingConnectedLineMode() {
ToolPropertiesInteraction.onToolProperties().setColor(Color.BLACK)
Expand Down Expand Up @@ -457,8 +415,7 @@ class DynamicLineToolIntegrationTest {
touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_MIDDLE)
touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_MIDDLE)
touchAt(DrawingSurfaceLocationProvider.BOTTOM_MIDDLE)
touchAt(DrawingSurfaceLocationProvider.BOTTOM_RIGHT_CLOSE_CENTER)

touchAt(DrawingSurfaceLocationProvider.HALFWAY_RIGHT_MIDDLE)

val currentTool = launchActivityRule.activity.defaultToolController.currentTool as DynamicLineTool
Assert.assertEquals(2, currentTool.vertexStack.size)
Expand Down Expand Up @@ -560,6 +517,105 @@ class DynamicLineToolIntegrationTest {
checkPixelColor(colorStringBlack, BitmapLocationProvider.HALFWAY_BOTTOM_RIGHT)
}

@Test
fun testUndoOnlyPathResetsVertexStack() {
val currentTool = launchActivityRule.activity.defaultToolController.currentTool as DynamicLineTool
ToolPropertiesInteraction.onToolProperties().setColor(Color.BLACK)

touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT)
touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_RIGHT)

Assert.assertEquals(2, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performUndo()

Assert.assertEquals(0, currentTool.vertexStack.size)
}

@Test
fun testUndoOnlyPathRebuildsVertexStackAfterCheckmark() {
val currentTool = launchActivityRule.activity.defaultToolController.currentTool as DynamicLineTool
ToolPropertiesInteraction.onToolProperties().setColor(Color.BLACK)

touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT)
touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_RIGHT)

Assert.assertEquals(2, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performClickCheckmark()

Assert.assertEquals(0, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performUndo()

Assert.assertEquals(2, currentTool.vertexStack.size)
}

@Test
fun testUndoSecondPathDecreasesVertexStackByOne() {
val currentTool = launchActivityRule.activity.defaultToolController.currentTool as DynamicLineTool
ToolPropertiesInteraction.onToolProperties().setColor(Color.BLACK)

touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT)
touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_RIGHT)

Assert.assertEquals(2, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performClickPlus()

touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_RIGHT)

Assert.assertEquals(3, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performUndo()

Assert.assertEquals(2, currentTool.vertexStack.size)
}

@Test
fun testUndoAfterTwoPathsRebuildsVertexStackAfterCheckmark() {
val currentTool = launchActivityRule.activity.defaultToolController.currentTool as DynamicLineTool
ToolPropertiesInteraction.onToolProperties().setColor(Color.BLACK)

touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT)
touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_RIGHT)

Assert.assertEquals(2, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performClickPlus()

touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_RIGHT)

Assert.assertEquals(3, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performClickCheckmark()
TopBarViewInteraction.onTopBarView().performUndo()

Assert.assertEquals(3, currentTool.vertexStack.size)
}

@Test
fun testTwiceUndoResetsVertexStack() {
val currentTool = launchActivityRule.activity.defaultToolController.currentTool as DynamicLineTool
ToolPropertiesInteraction.onToolProperties().setColor(Color.BLACK)

touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT)
touchAt(DrawingSurfaceLocationProvider.HALFWAY_TOP_RIGHT)

Assert.assertEquals(2, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performClickPlus()

touchAt(DrawingSurfaceLocationProvider.HALFWAY_BOTTOM_RIGHT)

Assert.assertEquals(3, currentTool.vertexStack.size)

TopBarViewInteraction.onTopBarView().performUndo()
TopBarViewInteraction.onTopBarView().performUndo()

Assert.assertEquals(0, currentTool.vertexStack.size)
}

private fun checkPixelColor(colorString: String, position: BitmapLocationProvider) {
DrawingSurfaceInteraction.onDrawingSurfaceView()
.checkPixelColor(Color.parseColor(colorString), position)
Expand Down

0 comments on commit a4c9d45

Please sign in to comment.