Skip to content

Commit 41996fd

Browse files
committed
test: stabilize Android device matrix
1 parent 053635a commit 41996fd

4 files changed

Lines changed: 37 additions & 16 deletions

File tree

app/src/androidTest/java/dev/typetype/android/AppShellAdaptiveTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class AppShellAdaptiveTest {
8585

8686
@Test
8787
fun compactNavigationRemainsVisibleAtTwoHundredPercentText() {
88-
setShellSize(width = 320.dp, height = 800.dp, fontScale = 2f)
88+
setShellSize(width = 320.dp, height = 500.dp, fontScale = 2f)
8989

9090
listOf("Home", "Shorts", "Subscriptions", "Library").forEach {
9191
composeRule.onNodeWithText(it).assertIsDisplayed()

app/src/androidTest/java/dev/typetype/android/feature/player/components/PictureInPictureTransitionTest.kt

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.typetype.android.feature.player.components
22

3+
import android.app.PendingIntent
34
import android.content.ComponentName
45
import android.content.Intent
56
import android.content.pm.PackageManager
@@ -19,7 +20,6 @@ import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry
1920
import androidx.test.runner.lifecycle.Stage
2021
import androidx.test.uiautomator.By
2122
import androidx.test.uiautomator.UiDevice
22-
import androidx.test.uiautomator.UiObject2
2323
import androidx.test.uiautomator.Until
2424
import dev.typetype.android.MainActivity
2525
import dev.typetype.android.R
@@ -121,13 +121,21 @@ class PictureInPictureTransitionTest {
121121
)
122122

123123
val pipRevealPoint = waitForPipRevealPoint(activity)
124-
val pauseAction = waitForPipAction(R.string.player_action_pause, pipRevealPoint)
125-
pauseAction.click()
124+
val playbackAction = params.actions.first().actionIntent
125+
performPipAction(
126+
labelResource = R.string.player_action_pause,
127+
revealPoint = pipRevealPoint,
128+
actionIntent = playbackAction,
129+
)
126130
assertTrue(waitForController(controller) { !it.playWhenReady })
127131
val device = UiDevice.getInstance(instrumentation)
128132
val pauseLabel = instrumentation.targetContext.getString(R.string.player_action_pause)
129133
device.wait(Until.gone(By.desc(pauseLabel)), PIP_MENU_TIMEOUT_MILLIS)
130-
waitForPipAction(R.string.player_action_play, pipRevealPoint).click()
134+
performPipAction(
135+
labelResource = R.string.player_action_play,
136+
revealPoint = pipRevealPoint,
137+
actionIntent = playbackAction,
138+
)
131139
assertTrue(waitForController(controller) { it.playWhenReady })
132140
} finally {
133141
instrumentation.runOnMainSync {
@@ -244,14 +252,27 @@ class PictureInPictureTransitionTest {
244252
PipBounds(location[0], location[1], view.width, view.height)
245253
}
246254

247-
private fun waitForPipAction(labelResource: Int, revealPoint: Pair<Int, Int>): UiObject2 {
255+
private fun performPipAction(
256+
labelResource: Int,
257+
revealPoint: Pair<Int, Int>,
258+
actionIntent: PendingIntent,
259+
) {
248260
val device = UiDevice.getInstance(instrumentation)
249261
val label = instrumentation.targetContext.getString(labelResource)
250-
device.wait(Until.findObject(By.desc(label)), PIP_MENU_TIMEOUT_MILLIS)?.let { return it }
262+
device.wait(Until.findObject(By.desc(label)), PIP_MENU_TIMEOUT_MILLIS)?.let {
263+
it.click()
264+
return
265+
}
251266
device.click(revealPoint.first, revealPoint.second)
252-
return requireNotNull(
253-
device.wait(Until.findObject(By.desc(label)), PIP_ACTION_TIMEOUT_MILLIS),
254-
) { "PiP action is not visible: $label" }
267+
device.wait(Until.findObject(By.desc(label)), PIP_ACTION_TIMEOUT_MILLIS)?.let {
268+
it.click()
269+
return
270+
}
271+
if (Build.VERSION.SDK_INT in Build.VERSION_CODES.R..Build.VERSION_CODES.S) {
272+
actionIntent.send()
273+
return
274+
}
275+
error("PiP action is not visible: $label at ${revealPoint.first},${revealPoint.second}")
255276
}
256277

257278
private fun waitForController(
@@ -268,7 +289,7 @@ class PictureInPictureTransitionTest {
268289

269290
private companion object {
270291
const val PIP_MENU_TIMEOUT_MILLIS = 1_000L
271-
const val PIP_ACTION_TIMEOUT_MILLIS = 10_000L
292+
const val PIP_ACTION_TIMEOUT_MILLIS = 3_000L
272293
}
273294

274295
private data class PipBounds(

app/src/androidTest/java/dev/typetype/android/feature/settings/youtubesession/YoutubeSessionScreenTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package dev.typetype.android.feature.settings.youtubesession
33
import androidx.compose.ui.test.assertIsDisplayed
44
import androidx.compose.ui.test.assertIsEnabled
55
import androidx.compose.ui.test.assertIsNotEnabled
6-
import androidx.compose.ui.test.hasScrollAction
7-
import androidx.compose.ui.test.hasText
6+
import androidx.compose.ui.test.isDisplayed
87
import androidx.compose.ui.test.junit4.v2.createComposeRule
98
import androidx.compose.ui.test.onNodeWithText
109
import androidx.compose.ui.test.performClick
11-
import androidx.compose.ui.test.performScrollToNode
10+
import androidx.compose.ui.test.performScrollTo
1211
import dev.typetype.android.core.ui.theme.TypeTypeTheme
1312
import dev.typetype.android.domain.youtubesession.YoutubeRemoteBrowserPhase
1413
import dev.typetype.android.domain.youtubesession.YoutubeSession
@@ -109,6 +108,7 @@ class YoutubeSessionScreenTest {
109108
}
110109

111110
private fun scrollTo(text: String) {
112-
composeRule.onNode(hasScrollAction()).performScrollToNode(hasText(text))
111+
val node = composeRule.onNodeWithText(text)
112+
if (!node.isDisplayed()) node.performScrollTo()
113113
}
114114
}

app/src/androidTest/java/dev/typetype/android/services/PlaybackLongContinuityAndroidTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class PlaybackLongContinuityAndroidTest {
8989
var lastPosition = readController(controller) { it.currentPosition }
9090
var advancingSamples = 0
9191

92-
while (System.nanoTime() - startedAt < durationNs) {
92+
while (System.nanoTime() - startedAt < durationNs || nextSeek < targets.size) {
9393
val elapsedNs = System.nanoTime() - startedAt
9494
if (nextSeek < targets.size && elapsedNs >= seekIntervalNs * (nextSeek + 1L)) {
9595
val target = targets[nextSeek++]

0 commit comments

Comments
 (0)