Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a2ba19b authored by Jonathan He's avatar Jonathan He
Browse files

Add unit tests for region box state class

This commit aims to write unit tests specifically aimed at testing and verifying the behavior of functions found within the region box state class. This includes the startDrag, drag, and endDrag functions. These tests are comprehensive and will furthermore test functionalities of code outside of the region box state class (but still directly related) such as functionalities found within the ResizeZone.kt for resize operations. Helper functions are made within the test file in order to reduce any redundancy while having full test coverage (such as testing all different corners/edges). Lastly, this commit also changes the visibility of several functions/variables/classes within the RegionBox to "public" in order to access/test it from the new RegionBoxStateTest file.

Bug: 436265991
Test: atest RegionBoxStateTest
Flag: TEST_ONLY
Change-Id: Id20750e506df1f38b91339663a8698da128f88ed
parent 8091259f
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ import kotlin.math.min
import kotlin.math.roundToInt

// The different modes of interaction that the user can have with the RegionBox.
private enum class DragMode {
enum class DragMode {
    DRAWING,
    MOVING,
    RESIZING,
@@ -166,9 +166,8 @@ private fun getTappedOrHoveredZone(
 * @param minSizePx The minimum size of the box in pixels.
 * @param touchAreaPx The size of the touch area for resizing in pixels.
 */
private class RegionBoxState(private val minSizePx: Float, private val touchAreaPx: Float) {
class RegionBoxState(private val minSizePx: Float, private val touchAreaPx: Float) {
    var rect by mutableStateOf<Rect?>(null)
        private set

    var dragMode by mutableStateOf(DragMode.NONE)

@@ -194,7 +193,7 @@ private class RegionBoxState(private val minSizePx: Float, private val touchArea
    var isHoveringButton by mutableStateOf(false)

    // The offset of the initial press when the user starts a drag gesture.
    private var newBoxStartOffset by mutableStateOf(Offset.Zero)
    var newBoxStartOffset by mutableStateOf(Offset.Zero)

    // Must remember the screen size for the drag logic. Initial values are set to 0.
    var screenWidth by mutableStateOf(0f)
+1219 −0

File added.

Preview size limit exceeded, changes collapsed.