Skip to content

Commit

Permalink
Improve MentionsPageUiTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
MykytaPimonovTD committed Oct 23, 2024
1 parent 30ef641 commit ba36398
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package io.spine.examples.pingh.desktop

import androidx.compose.ui.semantics.SemanticsNode
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import androidx.compose.ui.test.filter
import androidx.compose.ui.test.filterToOne
Expand All @@ -49,8 +50,6 @@ import org.junit.jupiter.api.DisplayName
@OptIn(ExperimentalTestApi::class)
internal class MentionsPageUiTest : UiTest() {

private val isSnoozeButton = hasTestTag("snooze-button")

@Test
internal fun `allow users to open a mentions URL even after it has been read`() =
runComposeUiTest {
Expand All @@ -71,11 +70,8 @@ internal class MentionsPageUiTest : UiTest() {
logIn()
awaitFact { mentionCards().size shouldBeGreaterThanOrEqual 1 }
val tag = mentionCards().random().testTag
val snoozeButton = onNodeWithTag(tag)
.onChildren()
.filterToOne(isSnoozeButton)
snoozeButton.performClick()
awaitFact { snoozeButton.assertDoesNotExist() }
onSnoozeButtonWithParentTag(tag).performClick()
awaitFact { onSnoozeButtonWithParentTag(tag).assertDoesNotExist() }
}

@Test
Expand All @@ -85,11 +81,8 @@ internal class MentionsPageUiTest : UiTest() {
logIn()
awaitFact { mentionCards().size shouldBeGreaterThanOrEqual 1 }
val tag = mentionCards().random().testTag
val snoozeButton = onNodeWithTag(tag)
.onChildren()
.filterToOne(isSnoozeButton)
onNodeWithTag(tag).performClick()
awaitFact { snoozeButton.assertDoesNotExist() }
awaitFact { onSnoozeButtonWithParentTag(tag).assertDoesNotExist() }
}

@Test
Expand All @@ -102,10 +95,7 @@ internal class MentionsPageUiTest : UiTest() {
val readMentionTag = mentionsCards[0].testTag
val snoozedMentionTag = mentionsCards[1].testTag
onNodeWithTag(readMentionTag).performClick()
onNodeWithTag(snoozedMentionTag)
.onChildren()
.filterToOne(isSnoozeButton)
.performClick()
onSnoozeButtonWithParentTag(snoozedMentionTag).performClick()
awaitFact {
val mentions = mentionCards()
val readMention = mentions.first { it.testTag == readMentionTag }
Expand All @@ -125,4 +115,10 @@ internal class MentionsPageUiTest : UiTest() {
.onChildren()
.filter(hasClickAction())
.fetchSemanticsNodes()

private fun SemanticsNodeInteractionsProvider.onSnoozeButtonWithParentTag(tag: String):
SemanticsNodeInteraction =
onNodeWithTag(tag)
.onChildren()
.filterToOne(hasTestTag("snooze-button"))
}

0 comments on commit ba36398

Please sign in to comment.