Skip to content

Commit

Permalink
ISSUE-555: add knode class, long/double click actions (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
Areyana authored Dec 12, 2024
1 parent 657f639 commit fbb2a98
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.kaspersky.components.composesupport.core

import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.kaspersky.components.composesupport.core.actions.KNodeActions
import io.github.kakaocup.compose.node.builder.NodeMatcher
import io.github.kakaocup.compose.node.builder.ViewBuilder
import io.github.kakaocup.compose.node.core.BaseNode

class KNode : BaseNode<KNode>, KNodeActions {
constructor(
semanticsProvider: SemanticsNodeInteractionsProvider,
nodeMatcher: NodeMatcher,
parentNode: BaseNode<*>? = null,
) : super(semanticsProvider, nodeMatcher, parentNode)

constructor(
semanticsProvider: SemanticsNodeInteractionsProvider,
viewBuilderAction: ViewBuilder.() -> Unit,
) : super(semanticsProvider, viewBuilderAction)

constructor(
semanticsProvider: SemanticsNodeInteractionsProvider,
nodeMatcher: NodeMatcher,
) : super(semanticsProvider, nodeMatcher)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.kaspersky.components.composesupport.core.actions

import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.test.doubleClick
import androidx.compose.ui.test.longClick
import androidx.compose.ui.test.performTouchInput
import com.kaspersky.components.composesupport.core.actions.options.DoubleClickConfig
import com.kaspersky.components.composesupport.core.actions.options.LongClickConfig
import io.github.kakaocup.compose.intercept.delegate.ComposeDelegate
import io.github.kakaocup.compose.intercept.operation.ComposeOperationType

interface KNodeActions {
val delegate: ComposeDelegate

/**
* Performs a double click action on the element represented by the given semantics node.
*/
fun doubleClick(doubleClickConfig: DoubleClickConfig? = null) {
delegate.perform(ComposeKNodeActionType.PERFORM_DOUBLE_CLICK) {
performTouchInput {
doubleClick(
position = Offset(doubleClickConfig?.xOffset ?: centerX, doubleClickConfig?.yOffset ?: centerY),
delayMillis = doubleClickConfig?.delayMs ?: ((viewConfiguration.doubleTapMinTimeMillis + viewConfiguration.doubleTapTimeoutMillis) / 2)
)
}
}
}

/**
* Performs a long click action on the element represented by the given semantics node.
*/
fun longClick(longClickConfig: LongClickConfig? = null) {
delegate.perform(ComposeKNodeActionType.PERFORM_LONG_CLICK) {
performTouchInput {
longClick(
position = Offset(longClickConfig?.xOffset ?: centerX, longClickConfig?.yOffset ?: centerY),
durationMillis = longClickConfig?.durationMs ?: ((viewConfiguration.doubleTapMinTimeMillis + viewConfiguration.doubleTapTimeoutMillis) / 2)
)
}
}
}

enum class ComposeKNodeActionType : ComposeOperationType {
PERFORM_DOUBLE_CLICK,
PERFORM_LONG_CLICK
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kaspersky.components.composesupport.core.actions.options

data class DoubleClickConfig(
val xOffset: Float = 0F,
val yOffset: Float = 0F,
val delayMs: Long? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kaspersky.components.composesupport.core.actions.options

data class LongClickConfig(
val xOffset: Float = 0F,
val yOffset: Float = 0F,
val durationMs: Long? = null
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.kaspersky.kaspresso.composesupport.sample.screen

import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.kaspersky.components.composesupport.core.KNode
import com.kaspersky.kaspresso.composesupport.sample.resources.C
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.KNode

class ComposeMainScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<ComposeMainScreen>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.kaspersky.kaspresso.composesupport.sample.screen

import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.kaspersky.components.composesupport.core.KNode
import com.kaspersky.kaspresso.composesupport.sample.resources.C
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.KNode

class ComposeSanityFlakyScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<ComposeSanityFlakyScreen>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.kaspersky.kaspresso.composesupport.sample.screen

import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.kaspersky.components.composesupport.core.KNode
import com.kaspersky.kaspresso.composesupport.sample.resources.C
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.KNode

class ComposeScrollScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<ComposeScrollScreen>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.kaspersky.kaspresso.composesupport.sample.screen

import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.kaspersky.components.composesupport.core.KNode
import com.kaspersky.kaspresso.composesupport.sample.resources.C
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.KNode

class ComposeSimpleFlakyScreen(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<ComposeSimpleFlakyScreen>(
Expand Down

0 comments on commit fbb2a98

Please sign in to comment.