|
| 1 | +package helium314.keyboard.settings |
| 2 | + |
| 3 | +import android.content.res.Configuration |
| 4 | +import androidx.compose.runtime.CompositionLocalProvider |
| 5 | +import androidx.compose.ui.platform.LocalConfiguration |
| 6 | +import androidx.compose.ui.test.junit4.createComposeRule |
| 7 | +import org.junit.Assert.assertFalse |
| 8 | +import org.junit.Assert.assertTrue |
| 9 | +import org.junit.Rule |
| 10 | +import org.junit.Test |
| 11 | +import org.junit.runner.RunWith |
| 12 | +import org.robolectric.RobolectricTestRunner |
| 13 | +import org.robolectric.annotation.Config |
| 14 | + |
| 15 | +@RunWith(RobolectricTestRunner::class) |
| 16 | +@Config(sdk = [33]) // optional, explicitly setting SDK can sometimes resolve robolectric issues |
| 17 | +class MiscTest { |
| 18 | + |
| 19 | + @get:Rule |
| 20 | + val composeTestRule = createComposeRule() |
| 21 | + |
| 22 | + @Test |
| 23 | + fun isWideScreen_true_whenWidthGreaterThan600() { |
| 24 | + var result = false |
| 25 | + composeTestRule.setContent { |
| 26 | + val config = Configuration().apply { |
| 27 | + screenWidthDp = 601 |
| 28 | + } |
| 29 | + CompositionLocalProvider(LocalConfiguration provides config) { |
| 30 | + result = isWideScreen() |
| 31 | + } |
| 32 | + } |
| 33 | + assertTrue(result) |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + fun isWideScreen_false_whenWidthIs600() { |
| 38 | + var result = true |
| 39 | + composeTestRule.setContent { |
| 40 | + val config = Configuration().apply { |
| 41 | + screenWidthDp = 600 |
| 42 | + } |
| 43 | + CompositionLocalProvider(LocalConfiguration provides config) { |
| 44 | + result = isWideScreen() |
| 45 | + } |
| 46 | + } |
| 47 | + assertFalse(result) |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + fun isWideScreen_false_whenWidthLessThan600() { |
| 52 | + var result = true |
| 53 | + composeTestRule.setContent { |
| 54 | + val config = Configuration().apply { |
| 55 | + screenWidthDp = 599 |
| 56 | + } |
| 57 | + CompositionLocalProvider(LocalConfiguration provides config) { |
| 58 | + result = isWideScreen() |
| 59 | + } |
| 60 | + } |
| 61 | + assertFalse(result) |
| 62 | + } |
| 63 | +} |
0 commit comments