|
|
@ -1,17 +1,17 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2022 The Android Open Source Project
|
|
|
|
* Copyright 2022 The Android Open Source Project
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid.feature.bookmarks
|
|
|
|
package com.google.samples.apps.nowinandroid.feature.bookmarks
|
|
|
@ -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,
|
|
|
|
removedBookmarks.add(it)
|
|
|
|
removeFromBookmarks = {
|
|
|
|
})
|
|
|
|
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, substring = true
|
|
|
|
newsResource.title,
|
|
|
|
|
|
|
|
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, substring = true
|
|
|
|
newsResource.title,
|
|
|
|
|
|
|
|
substring = true
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.assertCountEquals(1)
|
|
|
|
).assertCountEquals(1).onFirst().performClick()
|
|
|
|
.onFirst()
|
|
|
|
|
|
|
|
.performClick()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun removedNewsResourceBookmark(newsResource: NewsResource) =
|
|
|
|
fun removedNewsResourceBookmark(newsResource: NewsResource) =
|
|
|
|