|
|
@ -35,66 +35,51 @@ import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState
|
|
|
|
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState
|
|
|
|
|
|
|
|
|
|
|
|
internal class BookmarksRobot(
|
|
|
|
internal class BookmarksRobot(
|
|
|
|
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<ComponentActivity>, ComponentActivity>
|
|
|
|
private val composeTestRule: AndroidComposeTestRule<
|
|
|
|
|
|
|
|
ActivityScenarioRule<ComponentActivity>, ComponentActivity>
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
private val removedBookmarks = mutableSetOf<String>()
|
|
|
|
private val removedBookmarks = mutableSetOf<String>()
|
|
|
|
|
|
|
|
|
|
|
|
fun setContent(newsFeedUiState: NewsFeedUiState) {
|
|
|
|
fun setContent(newsFeedUiState: NewsFeedUiState) {
|
|
|
|
composeTestRule.setContent {
|
|
|
|
composeTestRule.setContent {
|
|
|
|
BookmarksScreen(
|
|
|
|
BookmarksScreen(feedState = newsFeedUiState, removeFromBookmarks = {
|
|
|
|
feedState = newsFeedUiState,
|
|
|
|
|
|
|
|
removeFromBookmarks = {
|
|
|
|
|
|
|
|
removedBookmarks.add(it)
|
|
|
|
removedBookmarks.add(it)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun loadingIndicatorShown() {
|
|
|
|
fun loadingIndicatorShown() {
|
|
|
|
composeTestRule
|
|
|
|
composeTestRule.onNodeWithContentDescription(
|
|
|
|
.onNodeWithContentDescription(
|
|
|
|
|
|
|
|
composeTestRule.activity.resources.getString(R.string.saved_loading)
|
|
|
|
composeTestRule.activity.resources.getString(R.string.saved_loading)
|
|
|
|
)
|
|
|
|
).assertExists()
|
|
|
|
.assertExists()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun clickableNewsResourceExists(newsResource: NewsResource) {
|
|
|
|
fun clickableNewsResourceExists(newsResource: NewsResource) {
|
|
|
|
composeTestRule
|
|
|
|
composeTestRule.onNodeWithText(
|
|
|
|
.onNodeWithText(
|
|
|
|
newsResource.title, substring = true
|
|
|
|
newsResource.title,
|
|
|
|
).assertExists().assertHasClickAction()
|
|
|
|
substring = true
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.assertExists()
|
|
|
|
|
|
|
|
.assertHasClickAction()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun scrollToNewsResource(newsResource: NewsResource) {
|
|
|
|
fun scrollToNewsResource(newsResource: NewsResource) {
|
|
|
|
composeTestRule.onNode(hasScrollToNodeAction())
|
|
|
|
composeTestRule.onNode(hasScrollToNodeAction()).performScrollToNode(
|
|
|
|
.performScrollToNode(
|
|
|
|
|
|
|
|
hasText(
|
|
|
|
hasText(
|
|
|
|
newsResource.title,
|
|
|
|
newsResource.title, substring = true
|
|
|
|
substring = true
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun clickNewsResourceBookmark(newsResource: NewsResource) {
|
|
|
|
fun clickNewsResourceBookmark(newsResource: NewsResource) {
|
|
|
|
composeTestRule
|
|
|
|
composeTestRule.onAllNodesWithContentDescription(
|
|
|
|
.onAllNodesWithContentDescription(
|
|
|
|
|
|
|
|
composeTestRule.activity.getString(
|
|
|
|
composeTestRule.activity.getString(
|
|
|
|
com.google.samples.apps.nowinandroid.core.ui.R.string.unbookmark
|
|
|
|
com.google.samples.apps.nowinandroid.core.ui.R.string.unbookmark
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).filter(
|
|
|
|
).filter(
|
|
|
|
hasAnyAncestor(
|
|
|
|
hasAnyAncestor(
|
|
|
|
hasText(
|
|
|
|
hasText(
|
|
|
|
newsResource.title,
|
|
|
|
newsResource.title, substring = true
|
|
|
|
substring = true
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.assertCountEquals(1)
|
|
|
|
).assertCountEquals(1).onFirst().performClick()
|
|
|
|
.onFirst()
|
|
|
|
|
|
|
|
.performClick()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun removedNewsResourceBookmark(newsResource: NewsResource) =
|
|
|
|
fun removedNewsResourceBookmark(newsResource: NewsResource) =
|
|
|
|