Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-555: Add compose support #610

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
@@ -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
Loading