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 Sep 14, 2022
1 parent b76133e commit a7458c2
Showing 1 changed file with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ 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.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 All @@ -66,6 +70,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 @@ -83,6 +88,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 @@ -134,7 +143,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 @@ -157,7 +169,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 @@ -175,12 +191,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 @@ -207,7 +232,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 @@ -230,7 +258,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 @@ -240,7 +272,12 @@ private fun RecentlyVisitedHistoryHighlight(
Box(modifier = Modifier.fillMaxSize()) {
RecentlyVisitedTitle(
text = recentVisit.title,
modifier = Modifier.align(Alignment.CenterStart),
modifier = Modifier
.align(Alignment.CenterStart)
.semantics {
testTagsAsResourceId = true
testTag = "recent.visits.highlight.title"
},
)

if (showDividerLine) {
Expand Down Expand Up @@ -318,6 +355,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 @@ -333,7 +371,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 a7458c2

Please sign in to comment.