Skip to content

Commit a8dd9b1

Browse files
committed
Resizing display in tests is only supported on API>=24
1 parent 6bd966b commit a8dd9b1

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

app/src/androidTest/java/org/schabi/newpipe/ui/components/menu/LongPressMenuTest.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.ui.components.menu
22

3+
import android.os.Build
34
import androidx.activity.ComponentActivity
45
import androidx.compose.runtime.getValue
56
import androidx.compose.runtime.mutableStateOf
@@ -37,13 +38,16 @@ import androidx.test.espresso.device.sizeclass.WidthSizeClass
3738
import androidx.test.espresso.matcher.ViewMatchers.withId
3839
import androidx.test.espresso.matcher.ViewMatchers.withText
3940
import androidx.test.ext.junit.runners.AndroidJUnit4
41+
import androidx.test.filters.SdkSuppress
4042
import java.time.OffsetDateTime
4143
import java.time.temporal.ChronoUnit
4244
import kotlinx.coroutines.delay
4345
import org.junit.Assert.assertEquals
4446
import org.junit.Assert.assertNotEquals
4547
import org.junit.Rule
4648
import org.junit.Test
49+
import org.junit.rules.RuleChain
50+
import org.junit.rules.TestRule
4751
import org.junit.runner.RunWith
4852
import org.schabi.newpipe.R
4953
import org.schabi.newpipe.assertInRange
@@ -69,7 +73,12 @@ class LongPressMenuTest {
6973
// Test rule for restoring device to its starting display size when a test case finishes.
7074
// See https://developer.android.com/training/testing/different-screens/tools#resize-displays.
7175
@get:Rule(order = 2)
72-
val displaySizeRule: DisplaySizeRule = DisplaySizeRule()
76+
val displaySizeRule: TestRule =
77+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
78+
DisplaySizeRule()
79+
} else {
80+
RuleChain.emptyRuleChain()
81+
}
7382

7483
private fun getLongPressable(
7584
title: String = "title",
@@ -382,6 +391,7 @@ class LongPressMenuTest {
382391
}
383392

384393
@Test
394+
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
385395
fun testHeaderSpansAllWidthIfSmallScreen() {
386396
onDevice().setDisplaySize(
387397
widthSizeClass = WidthSizeClass.COMPACT,
@@ -401,6 +411,7 @@ class LongPressMenuTest {
401411
}
402412

403413
@Test
414+
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
404415
fun testHeaderIsNotFullWidthIfLargeScreen() {
405416
onDevice().setDisplaySize(
406417
widthSizeClass = WidthSizeClass.EXPANDED,
@@ -549,6 +560,7 @@ class LongPressMenuTest {
549560
}
550561

551562
@Test
563+
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
552564
fun testAllActionsOnSmallScreenAreScrollable() {
553565
onDevice().setDisplaySize(
554566
widthSizeClass = WidthSizeClass.COMPACT,

0 commit comments

Comments
 (0)