From e112e372f6b0e7e6f0733be31e07d162bb6bd00a Mon Sep 17 00:00:00 2001 From: MUEDSA <7676275+muedsa@users.noreply.github.com> Date: Mon, 22 Jul 2024 09:57:40 +0800 Subject: [PATCH] update(BaselineProfile): generate baseline profile with testTag --- .../kotlin/com/muedsa/compose/tv/widget/Scaffold.kt | 10 +++++++++- .../jcytv/ui/features/detail/AnimeDetailScreen.kt | 2 ++ .../jcytv/ui/features/home/catalog/CatalogScreen.kt | 4 +++- .../ui/features/home/favorites/FavoritesScreen.kt | 11 +++++++---- .../muedsa/jcytv/ui/features/home/main/MainScreen.kt | 5 ++++- .../muedsa/jcytv/ui/features/home/rank/RankScreen.kt | 4 +++- .../jcytv/ui/features/home/search/SearchScreen.kt | 8 +++++--- .../jcytv/benchmark/BaselineProfileGenerator.kt | 12 ++++++------ 8 files changed, 39 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/muedsa/compose/tv/widget/Scaffold.kt b/app/src/main/kotlin/com/muedsa/compose/tv/widget/Scaffold.kt index 0968ab4..301548b 100644 --- a/app/src/main/kotlin/com/muedsa/compose/tv/widget/Scaffold.kt +++ b/app/src/main/kotlin/com/muedsa/compose/tv/widget/Scaffold.kt @@ -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 @@ -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, @@ -33,7 +37,11 @@ fun Scaffold( } } Surface( - modifier = Modifier.fillMaxSize(), + modifier = Modifier + .fillMaxSize() + .semantics { + testTagsAsResourceId = true + }, shape = RectangleShape, colors = colors ) { diff --git a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/detail/AnimeDetailScreen.kt b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/detail/AnimeDetailScreen.kt index 8f136c5..8be95d0 100644 --- a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/detail/AnimeDetailScreen.kt +++ b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/detail/AnimeDetailScreen.kt @@ -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 @@ -325,6 +326,7 @@ fun AnimeDetailScreen( // 剧集列表 item { EpisodeListWidget( + modifier = Modifier.testTag("animeDetailScreen_episodeListWidget"), episodeList = episodeList, danEpisodeList = danAnimeInfoLD.data?.episodes ?: emptyList(), episodeProgressMap = watchedEpisodeTitleMap, diff --git a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/catalog/CatalogScreen.kt b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/catalog/CatalogScreen.kt index 3e90f72..3158a8f 100644 --- a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/catalog/CatalogScreen.kt +++ b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/catalog/CatalogScreen.kt @@ -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 @@ -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, diff --git a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/favorites/FavoritesScreen.kt b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/favorites/FavoritesScreen.kt index f0248c9..c26c8c4 100644 --- a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/favorites/FavoritesScreen.kt +++ b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/favorites/FavoritesScreen.kt @@ -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 @@ -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( @@ -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, diff --git a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/main/MainScreen.kt b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/main/MainScreen.kt index bdc5b39..ba27342 100644 --- a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/main/MainScreen.kt +++ b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/main/MainScreen.kt @@ -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 @@ -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 -> @@ -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 -> diff --git a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/rank/RankScreen.kt b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/rank/RankScreen.kt index 22465f0..b13139f 100644 --- a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/rank/RankScreen.kt +++ b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/rank/RankScreen.kt @@ -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 @@ -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(), diff --git a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/search/SearchScreen.kt b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/search/SearchScreen.kt index 07d3f18..321086f 100644 --- a/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/search/SearchScreen.kt +++ b/app/src/main/kotlin/com/muedsa/jcytv/ui/features/home/search/SearchScreen.kt @@ -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 @@ -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, diff --git a/benchmark/src/main/java/com/muedsa/jcytv/benchmark/BaselineProfileGenerator.kt b/benchmark/src/main/java/com/muedsa/jcytv/benchmark/BaselineProfileGenerator.kt index 0447a5e..59bcf78 100644 --- a/benchmark/src/main/java/com/muedsa/jcytv/benchmark/BaselineProfileGenerator.kt +++ b/benchmark/src/main/java/com/muedsa/jcytv/benchmark/BaselineProfileGenerator.kt @@ -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 @@ -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 ) // 浏览排行 @@ -90,7 +90,7 @@ class BaselineProfileGenerator { pressDPadCenter(); waitForIdle(WAIT_TIMEOUT) // 等待收藏页面加载完成 wait( - Until.findObject(By.textContains("删除模式")), + Until.findObject(By.res("favoritesScreen_deleteModeButton")), INITIAL_WAIT_TIMEOUT ) // 浏览收藏 @@ -102,7 +102,7 @@ class BaselineProfileGenerator { pressDPadCenter(); waitForIdle(WAIT_TIMEOUT) // 等待搜索页面加载完成 wait( - Until.findObject(By.desc("搜索")), + Until.findObject(By.res("searchScreen_searchButton")), INITIAL_WAIT_TIMEOUT ) @@ -111,7 +111,7 @@ class BaselineProfileGenerator { pressDPadCenter(); waitForIdle(WAIT_TIMEOUT) // 等待目录加载完成 wait( - Until.findObject(By.textContains("更新")), + Until.findObject(By.res("catalogScreen_card_")), INITIAL_WAIT_TIMEOUT ) // 浏览目录 @@ -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) }