diff --git a/desktop/src/test/kotlin/io/spine/examples/pingh/desktop/MentionsPageUiTest.kt b/desktop/src/test/kotlin/io/spine/examples/pingh/desktop/MentionsPageUiTest.kt index 355c4f67..e782f423 100644 --- a/desktop/src/test/kotlin/io/spine/examples/pingh/desktop/MentionsPageUiTest.kt +++ b/desktop/src/test/kotlin/io/spine/examples/pingh/desktop/MentionsPageUiTest.kt @@ -42,6 +42,7 @@ import io.kotest.matchers.floats.shouldBeLessThan import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual import io.kotest.matchers.shouldBe import io.spine.examples.pingh.desktop.given.DelayedFactAssertion.Companion.awaitFact +import io.spine.examples.pingh.desktop.given.performHover import io.spine.examples.pingh.desktop.given.testTag import kotlin.test.Test import org.junit.jupiter.api.DisplayName @@ -70,8 +71,13 @@ internal class MentionsPageUiTest : UiTest() { logIn() awaitFact { mentionCards().size shouldBeGreaterThanOrEqual 1 } val tag = mentionCards().random().testTag + onNodeWithTag(tag).performHover() + awaitFact { onSnoozeButtonWithParentTag(tag).assertExists() } onSnoozeButtonWithParentTag(tag).performClick() - awaitFact { onSnoozeButtonWithParentTag(tag).assertDoesNotExist() } + awaitFact { + onNodeWithTag(tag).performHover() + onSnoozeButtonWithParentTag(tag).assertDoesNotExist() + } } @Test @@ -82,7 +88,10 @@ internal class MentionsPageUiTest : UiTest() { awaitFact { mentionCards().size shouldBeGreaterThanOrEqual 1 } val tag = mentionCards().random().testTag onNodeWithTag(tag).performClick() - awaitFact { onSnoozeButtonWithParentTag(tag).assertDoesNotExist() } + awaitFact { + onNodeWithTag(tag).performHover() + onSnoozeButtonWithParentTag(tag).assertDoesNotExist() + } } @Test @@ -94,8 +103,10 @@ internal class MentionsPageUiTest : UiTest() { val mentionsCards = mentionCards().sortedBy { it.positionInRoot.y } val readMentionTag = mentionsCards[0].testTag val snoozedMentionTag = mentionsCards[1].testTag - onNodeWithTag(readMentionTag).performClick() + onNodeWithTag(snoozedMentionTag).performHover() + awaitFact { onSnoozeButtonWithParentTag(snoozedMentionTag).assertExists() } onSnoozeButtonWithParentTag(snoozedMentionTag).performClick() + onNodeWithTag(readMentionTag).performClick() awaitFact { val mentions = mentionCards() val readMention = mentions.first { it.testTag == readMentionTag } diff --git a/desktop/src/test/kotlin/io/spine/examples/pingh/desktop/given/UiTestEnv.kt b/desktop/src/test/kotlin/io/spine/examples/pingh/desktop/given/UiTestEnv.kt index 13effe40..e324bc7b 100644 --- a/desktop/src/test/kotlin/io/spine/examples/pingh/desktop/given/UiTestEnv.kt +++ b/desktop/src/test/kotlin/io/spine/examples/pingh/desktop/given/UiTestEnv.kt @@ -26,8 +26,12 @@ package io.spine.examples.pingh.desktop.given +import androidx.compose.ui.geometry.Offset import androidx.compose.ui.semantics.SemanticsNode import androidx.compose.ui.semantics.SemanticsProperties +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.SemanticsNodeInteraction +import androidx.compose.ui.test.performMouseInput import com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly import java.util.concurrent.TimeUnit import kotlin.time.Duration @@ -46,3 +50,13 @@ internal val SemanticsNode.testTag: String get() = config.getOrElse(SemanticsProperties.TestTag) { throw IllegalStateException("This node does not have a `TestTag` specified.") } + +/** + * Hovers the mouse pointer over the center of the element to trigger a hover event. + */ +@OptIn(ExperimentalTestApi::class) +internal fun SemanticsNodeInteraction.performHover() { + val size = this.fetchSemanticsNode().size + val middle = Offset(size.width / 2f, size.height / 2f) + this.performMouseInput { this.moveTo(middle) } +}