Skip to content

Commit

Permalink
Add hover effect before clicking snooze button in testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
MykytaPimonovTD committed Oct 31, 2024
1 parent 48a5cca commit 9ea21ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
}

0 comments on commit 9ea21ae

Please sign in to comment.