Skip to content

Commit

Permalink
For mozilla-mobile#26826 - Add test tags for the recent visits section.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugurell committed Nov 8, 2022
1 parent f09d604 commit acd12d3
Showing 1 changed file with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ 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.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
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 @@ -69,6 +73,7 @@ private const val VISITS_PER_COLUMN = 3
* @param onRecentVisitClick Invoked when the user clicks on a recent visit.
* @param onRecentVisitLongClick Invoked when the user long clicks on a recent visit.
*/
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun RecentlyVisited(
recentVisits: List<RecentlyVisitedItem>,
Expand All @@ -87,6 +92,10 @@ fun RecentlyVisited(
val flingBehavior = EagerFlingBehavior(lazyRowState = listState)

LazyRow(
modifier = Modifier.semantics {
testTagsAsResourceId = true
testTag = "recent.visits"
},
state = listState,
contentPadding = PaddingValues(16.dp),
horizontalArrangement = Arrangement.spacedBy(32.dp),
Expand Down Expand Up @@ -138,7 +147,10 @@ fun RecentlyVisited(
* @param onRecentVisitClick Invoked when the user clicks on a recent visit.
* @param onRecentVisitClick Invoked when the user long clicks on a recently visited group.
*/
@OptIn(ExperimentalFoundationApi::class)
@OptIn(
ExperimentalFoundationApi::class,
ExperimentalComposeUiApi::class,
)
@Suppress("LongParameterList")
@Composable
private fun RecentlyVisitedHistoryGroup(
Expand All @@ -161,7 +173,11 @@ private fun RecentlyVisitedHistoryGroup(
isMenuExpanded = true
},
)
.size(268.dp, 56.dp),
.size(268.dp, 56.dp)
.semantics {
testTagsAsResourceId = true
testTag = "recent.visits.group"
},
verticalAlignment = Alignment.CenterVertically,
) {
Image(
Expand All @@ -179,12 +195,21 @@ private fun RecentlyVisitedHistoryGroup(
text = recentVisit.title,
modifier = Modifier
.padding(top = 7.dp, bottom = 2.dp)
.weight(1f),
.weight(1f)
.semantics {
testTagsAsResourceId = true
testTag = "recent.visits.group.title"
},
)

RecentlyVisitedCaption(
count = recentVisit.historyMetadata.size,
modifier = Modifier.weight(1f),
modifier = Modifier
.weight(1f)
.semantics {
testTagsAsResourceId = true
testTag = "recent.visits.group.caption"
},
)

if (showDividerLine) {
Expand All @@ -211,7 +236,10 @@ private fun RecentlyVisitedHistoryGroup(
* @param onRecentVisitClick Invoked when the user clicks on a recent visit.
* @param onRecentVisitLongClick Invoked when the user long clicks on a recent visit highlight.
*/
@OptIn(ExperimentalFoundationApi::class)
@OptIn(
ExperimentalFoundationApi::class,
ExperimentalComposeUiApi::class,
)
@Suppress("LongParameterList")
@Composable
private fun RecentlyVisitedHistoryHighlight(
Expand All @@ -234,7 +262,11 @@ private fun RecentlyVisitedHistoryHighlight(
isMenuExpanded = true
},
)
.size(268.dp, 56.dp),
.size(268.dp, 56.dp)
.semantics {
testTagsAsResourceId = true
testTag = "recent.visits.highlight"
},
verticalAlignment = Alignment.CenterVertically,
) {
Favicon(url = recentVisit.url, size = 24.dp)
Expand All @@ -244,7 +276,12 @@ private fun RecentlyVisitedHistoryHighlight(
Box(modifier = Modifier.fillMaxSize()) {
RecentlyVisitedTitle(
text = recentVisit.title.trimmed(),
modifier = Modifier.align(Alignment.CenterStart),
modifier = Modifier
.align(Alignment.CenterStart)
.semantics {
testTagsAsResourceId = true
testTag = "recent.visits.highlight.title"
},
)

if (showDividerLine) {
Expand Down Expand Up @@ -322,6 +359,7 @@ private fun RecentlyVisitedCaption(
* @param recentVisit The [RecentlyVisitedItem] 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)
@Composable
private fun RecentlyVisitedMenu(
showMenu: Boolean,
Expand All @@ -337,7 +375,11 @@ private fun RecentlyVisitedMenu(
expanded = showMenu,
onDismissRequest = { onDismissRequest() },
modifier = Modifier
.background(color = FirefoxTheme.colors.layer2),
.background(color = FirefoxTheme.colors.layer2)
.semantics {
testTagsAsResourceId = true
testTag = "recent.visit.menu"
},
) {
for (item in menuItems) {
DropdownMenuItem(
Expand Down

0 comments on commit acd12d3

Please sign in to comment.