Skip to content

Commit

Permalink
update(BaselineProfile): generate baseline profile with testTag
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Jul 22, 2024
1 parent 7380971 commit e112e37
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 17 deletions.
10 changes: 9 additions & 1 deletion app/src/main/kotlin/com/muedsa/compose/tv/widget/Scaffold.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package com.muedsa.compose.tv.widget
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Surface
import androidx.tv.material3.SurfaceColors
Expand All @@ -13,6 +16,7 @@ import com.muedsa.compose.tv.LocalErrorMsgBoxControllerProvider
import com.muedsa.compose.tv.LocalRightSideDrawerControllerProvider


@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun Scaffold(
holdBack: Boolean = true,
Expand All @@ -33,7 +37,11 @@ fun Scaffold(
}
}
Surface(
modifier = Modifier.fillMaxSize(),
modifier = Modifier
.fillMaxSize()
.semantics {
testTagsAsResourceId = true
},
shape = RectangleShape,
colors = colors
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
Expand Down Expand Up @@ -325,6 +326,7 @@ fun AnimeDetailScreen(
// 剧集列表
item {
EpisodeListWidget(
modifier = Modifier.testTag("animeDetailScreen_episodeListWidget"),
episodeList = episodeList,
danEpisodeList = danAnimeInfoLD.data?.episodes ?: emptyList(),
episodeProgressMap = watchedEpisodeTitleMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.tv.material3.ButtonDefaults
Expand Down Expand Up @@ -224,7 +225,8 @@ fun CatalogScreen(
ImageContentCard(
modifier = Modifier
.padding(end = ImageCardRowCardPadding)
.focusRequester(itemFocusRequester),
.focusRequester(itemFocusRequester)
.testTag("catalogScreen_card_$index"),
url = item.imageUrl,
imageSize = VideoPosterSize,
type = CardType.STANDARD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.tv.material3.ButtonDefaults
Expand Down Expand Up @@ -71,9 +72,10 @@ fun FavoritesScreen(
style = MaterialTheme.typography.headlineMedium
)
Spacer(modifier = Modifier.width(30.dp))
OutlinedButton(onClick = {
deleteMode = !deleteMode
}) {
OutlinedButton(
modifier = Modifier.testTag("favoritesScreen_deleteModeButton"),
onClick = { deleteMode = !deleteMode }
) {
Text(if (deleteMode) "退出" else "删除模式")
Spacer(modifier = Modifier.width(ButtonDefaults.IconSpacing))
Icon(
Expand All @@ -98,7 +100,8 @@ fun FavoritesScreen(
) { index, item ->
ImageContentCard(
modifier = Modifier
.padding(end = ImageCardRowCardPadding),
.padding(end = ImageCardRowCardPadding)
.testTag("favoritesScreen_card_$index"),
url = item.cover,
imageSize = VideoPosterSize,
type = CardType.STANDARD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.tv.material3.MaterialTheme
Expand Down Expand Up @@ -110,6 +111,7 @@ fun MainScreen(
.height(screenHeight - firstRowHeight - tabHeight)
)
ImageCardsRow(
modifier = Modifier.testTag("mainScreen_row_1"),
title = firstRow.first,
modelList = firstRow.second,
imageFn = { _, anime ->
Expand All @@ -134,9 +136,10 @@ fun MainScreen(
}
}

homeRows.subList(1, homeRows.size).forEach { row ->
homeRows.subList(1, homeRows.size).forEachIndexed { index, row ->
item {
StandardImageCardsRow(
modifier = Modifier.testTag("mainScreen_row_${index + 1}"),
title = row.first,
modelList = row.second,
imageFn = { _, anime ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -50,11 +51,12 @@ fun RankScreen(
if (rankListLD.type == LazyType.SUCCESS && !rankListLD.data.isNullOrEmpty()) {
val ranks = rankListLD.data!!.subList(0, min(3, rankListLD.data!!.size))
Row {
ranks.forEach { rank ->
ranks.forEachIndexed { index, rank ->
Column(
modifier = Modifier
.padding(top = 10.dp, bottom = 10.dp, end = 10.dp)
.weight(1f)
.testTag("rankScreen_column_$index")
) {
Text(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.tv.material3.ButtonDefaults
Expand Down Expand Up @@ -100,9 +101,10 @@ fun SearchScreen(
singleLine = true
)
Spacer(modifier = Modifier.width(16.dp))
OutlinedIconButton(onClick = {
viewModel.searchAnime(searchText)
}) {
OutlinedIconButton(
modifier = Modifier.testTag("searchScreen_searchButton"),
onClick = { viewModel.searchAnime(searchText) }
) {
Icon(
modifier = Modifier.size(ButtonDefaults.IconSize),
imageVector = Icons.Outlined.Search,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BaselineProfileGenerator {
device.run {
// 等到首屏加载
wait(
Until.findObject(By.text("首页").clickable(true)),
Until.findObject(By.res("mainScreen_row_1")),
INITIAL_WAIT_TIMEOUT
)
// 浏览首页 3个Row
Expand All @@ -77,7 +77,7 @@ class BaselineProfileGenerator {
pressDPadCenter(); waitForIdle(WAIT_TIMEOUT)
// 等待排行页面加载完成
wait(
Until.findObject(By.textContains(". ")),
Until.findObject(By.res("rankScreen_column_1")),
INITIAL_WAIT_TIMEOUT
)
// 浏览排行
Expand All @@ -90,7 +90,7 @@ class BaselineProfileGenerator {
pressDPadCenter(); waitForIdle(WAIT_TIMEOUT)
// 等待收藏页面加载完成
wait(
Until.findObject(By.textContains("删除模式")),
Until.findObject(By.res("favoritesScreen_deleteModeButton")),
INITIAL_WAIT_TIMEOUT
)
// 浏览收藏
Expand All @@ -102,7 +102,7 @@ class BaselineProfileGenerator {
pressDPadCenter(); waitForIdle(WAIT_TIMEOUT)
// 等待搜索页面加载完成
wait(
Until.findObject(By.desc("搜索")),
Until.findObject(By.res("searchScreen_searchButton")),
INITIAL_WAIT_TIMEOUT
)

Expand All @@ -111,7 +111,7 @@ class BaselineProfileGenerator {
pressDPadCenter(); waitForIdle(WAIT_TIMEOUT)
// 等待目录加载完成
wait(
Until.findObject(By.textContains("更新")),
Until.findObject(By.res("catalogScreen_card_")),
INITIAL_WAIT_TIMEOUT
)
// 浏览目录
Expand All @@ -122,7 +122,7 @@ class BaselineProfileGenerator {
pressDPadCenter(); waitForIdle(WAIT_TIMEOUT)
// 等待视频详情页面加载完成
wait(
Until.findObject(By.textStartsWith("剧集 1-")),
Until.findObject(By.res("animeDetailScreen_episodeListWidget")),
INITIAL_WAIT_TIMEOUT
)
repeat(2) { pressDPadDown(); waitForIdle(WAIT_TIMEOUT) }
Expand Down

0 comments on commit e112e37

Please sign in to comment.