Skip to content

Commit

Permalink
For mozilla-mobile#26826 - Add test tags for the recent bookmarks sec…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
Mugurell committed Sep 6, 2022
1 parent 2a47c7c commit 2524fff
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -66,13 +70,18 @@ private val imageModifier = Modifier
* @param menuItems List of [RecentBookmarksMenuItem] shown when long clicking a [RecentBookmarkItem]
* @param onRecentBookmarkClick Invoked when the user clicks on a recent bookmark.
*/
@OptIn(ExperimentalComposeUiApi::class) // for testTagsAsResourceId
@Composable
fun RecentBookmarks(
bookmarks: List<RecentBookmark>,
menuItems: List<RecentBookmarksMenuItem>,
onRecentBookmarkClick: (RecentBookmark) -> Unit = {},
) {
LazyRow(
modifier = Modifier.semantics {
testTagsAsResourceId = true
testTag = "recent.bookmarks"
},
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Expand All @@ -92,7 +101,10 @@ fun RecentBookmarks(
* @param bookmark The [RecentBookmark] to display.
* @param onRecentBookmarkClick Invoked when the user clicks on the recent bookmark item.
*/
@OptIn(ExperimentalFoundationApi::class)
@OptIn(
ExperimentalFoundationApi::class,
ExperimentalComposeUiApi::class, // for testTagsAsResourceId
)
@Composable
private fun RecentBookmarkItem(
bookmark: RecentBookmark,
Expand Down Expand Up @@ -124,6 +136,10 @@ private fun RecentBookmarkItem(

Text(
text = bookmark.title ?: bookmark.url ?: "",
modifier = Modifier.semantics {
testTagsAsResourceId = true
testTag = "recent.bookmark.title"
},
color = FirefoxTheme.colors.textPrimary,
overflow = TextOverflow.Ellipsis,
maxLines = 1,
Expand Down Expand Up @@ -207,6 +223,7 @@ private fun PlaceholderBookmarkImage() {
* @param recentBookmark The [RecentBookmark] for which this menu is shown.
* @param onDismissRequest Called when the user chooses a menu option or requests to dismiss the menu.
*/
@OptIn(ExperimentalComposeUiApi::class) // for testTagsAsResourceId
@Composable
private fun RecentBookmarksMenu(
showMenu: Boolean,
Expand All @@ -219,6 +236,10 @@ private fun RecentBookmarksMenu(
onDismissRequest = { onDismissRequest() },
modifier = Modifier
.background(color = FirefoxTheme.colors.layer2)
.semantics {
testTagsAsResourceId = true
testTag = "recent.bookmark.menu"
},
) {
for (item in menuItems) {
DropdownMenuItem(
Expand Down

0 comments on commit 2524fff

Please sign in to comment.