Created
August 26, 2023 03:18
-
-
Save dladukedev/8f546b6725bf37d91ec54f92b088fdb2 to your computer and use it in GitHub Desktop.
Show how to use the different modifying functions for SemanticMatchers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dladukedev.semanticsmatchertest | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.material3.Text | |
import androidx.compose.ui.test.assertCountEquals | |
import androidx.compose.ui.test.hasAnyAncestor | |
import androidx.compose.ui.test.hasText | |
import androidx.compose.ui.test.isDialog | |
import androidx.compose.ui.test.isRoot | |
import androidx.compose.ui.test.junit4.createComposeRule | |
import androidx.compose.ui.window.Dialog | |
import org.junit.Test | |
import org.junit.Before | |
import org.junit.Rule | |
class SemanticMatchersDemo { | |
@get:Rule | |
val composeTestRule = createComposeRule() | |
@Before | |
fun before() { | |
composeTestRule.setContent { | |
Box { | |
Column { | |
Text("Hello") | |
Text("Good-bye") | |
} | |
Dialog(onDismissRequest = {}) { | |
Column { | |
Text("Hello") | |
Text("Good-bye") | |
} | |
} | |
} | |
} | |
} | |
@Test | |
fun andTest() { | |
composeTestRule.onAllNodes(hasAnyAncestor(isDialog()) and hasText("Hello")).assertCountEquals(1) | |
} | |
@Test | |
fun orTest() { | |
composeTestRule.onAllNodes(hasText("Hello") or hasText("Good-bye")).assertCountEquals(4) | |
} | |
@Test | |
fun notTest() { | |
composeTestRule.onAllNodes(!isRoot()).assertCountEquals(5) | |
composeTestRule.onAllNodes(isRoot().not()).assertCountEquals(5) | |
} | |
@Test | |
fun combineTest() { | |
composeTestRule.onAllNodes(hasAnyAncestor(isDialog()).not() and hasText("Hello")).assertCountEquals(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment