app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

FoundationSettingsScreenTest.kt (5241B)


      1 package org.harvestcircle.ui.shell
      2 
      3 import androidx.compose.foundation.layout.Box
      4 import androidx.compose.foundation.layout.size
      5 import androidx.compose.ui.Modifier
      6 import androidx.compose.ui.test.ExperimentalTestApi
      7 import androidx.compose.ui.test.assertCountEquals
      8 import androidx.compose.ui.test.assertIsDisplayed
      9 import androidx.compose.ui.test.assertIsEnabled
     10 import androidx.compose.ui.test.assertIsSelected
     11 import androidx.compose.ui.test.assertTextEquals
     12 import androidx.compose.ui.test.onAllNodesWithText
     13 import androidx.compose.ui.test.onNodeWithTag
     14 import androidx.compose.ui.test.onNodeWithText
     15 import androidx.compose.ui.test.performClick
     16 import androidx.compose.ui.test.performScrollTo
     17 import androidx.compose.ui.test.v2.runComposeUiTest
     18 import androidx.compose.ui.unit.dp
     19 import org.harvestcircle.appearance.AppearanceState
     20 import org.harvestcircle.appearance.MotionPreference
     21 import org.harvestcircle.appearance.TextSizePreference
     22 import org.harvestcircle.appearance.ThemePreference
     23 import org.harvestcircle.application.BuildInfo
     24 import org.harvestcircle.identities.ui.HarvestCirclePlatformActions
     25 import org.harvestcircle.navigation.SettingsSection
     26 import kotlin.test.Test
     27 import kotlin.test.assertEquals
     28 
     29 @OptIn(ExperimentalTestApi::class)
     30 class FoundationSettingsScreenTest {
     31     @Test
     32     fun appearanceDispatchesSessionLocalTypedChoices() =
     33         runComposeUiTest {
     34             val selectedSections = mutableListOf<SettingsSection>()
     35             val themes = mutableListOf<ThemePreference>()
     36             val textSizes = mutableListOf<TextSizePreference>()
     37             val motions = mutableListOf<MotionPreference>()
     38             setHarvestCircleContent {
     39                 FoundationSettingsScreen(
     40                     SettingsSection.Appearance,
     41                     AppearanceState(),
     42                     BuildInfo.unknown(),
     43                     FoundationSettingsActions(selectedSections::add, themes::add, textSizes::add, motions::add),
     44                     HarvestCirclePlatformActions(),
     45                 )
     46             }
     47 
     48             onNodeWithTag("bounded-detail-settings").assertExists()
     49             onNodeWithTag("settings-appearance").assertIsSelected().assertIsEnabled().performClick()
     50             onNodeWithTag("theme-system").assertIsSelected().assertIsEnabled().performClick()
     51             onNodeWithTag("text-size-default").assertIsSelected().assertIsEnabled().performClick()
     52             onNodeWithTag("motion-standard").assertIsSelected().assertIsEnabled().performClick()
     53             onNodeWithTag("theme-dark").performClick()
     54             onNodeWithTag("text-size-verylarge").performClick()
     55             onNodeWithTag("motion-reduced").performClick()
     56             onNodeWithTag("settings-project").performClick()
     57             assertEquals(listOf(ThemePreference.Dark), themes)
     58             assertEquals(listOf(TextSizePreference.VeryLarge), textSizes)
     59             assertEquals(listOf(MotionPreference.Reduced), motions)
     60             assertEquals(listOf(SettingsSection.Project), selectedSections)
     61         }
     62 
     63     @Test
     64     fun projectShowsActualUnknownProvenanceAndFixedTypedActions() =
     65         runComposeUiTest {
     66             var source = 0
     67             var licence = 0
     68             setHarvestCircleContent {
     69                 FoundationSettingsScreen(
     70                     SettingsSection.Project,
     71                     AppearanceState(),
     72                     BuildInfo.unknown(),
     73                     FoundationSettingsActions({}, {}, {}, {}),
     74                     HarvestCirclePlatformActions(
     75                         openSource = { source += 1 },
     76                         openLicence = { licence += 1 },
     77                     ),
     78                 )
     79             }
     80 
     81             onNodeWithTag("project-source-commit").assertTextEquals("unknown")
     82             onNodeWithTag("project-source-state").assertTextEquals("Unknown")
     83             onNodeWithTag("project-ffi-contract").assertTextEquals("unknown 0.0")
     84             onNodeWithTag("project-storage-schema").assertTextEquals("0..0")
     85             onNodeWithText("GPL-3.0-only").assertExists()
     86             onNodeWithTag("project-open-source").performClick()
     87             onNodeWithTag("project-open-licence").performClick()
     88             assertEquals(1, source)
     89             assertEquals(1, licence)
     90             onAllNodesWithText("Locality").assertCountEquals(0)
     91             onAllNodesWithText("Delete data").assertCountEquals(0)
     92         }
     93 
     94     @Test
     95     fun veryLargeProjectFactsRemainReachableInTheBoundedPane() =
     96         runComposeUiTest {
     97             setHarvestCircleContent {
     98                 Box(Modifier.size(640.dp, 360.dp)) {
     99                     HarvestCircleTheme(AppearanceState(textSize = TextSizePreference.VeryLarge)) {
    100                         FoundationSettingsScreen(
    101                             SettingsSection.Project,
    102                             AppearanceState(textSize = TextSizePreference.VeryLarge),
    103                             BuildInfo.unknown(),
    104                             FoundationSettingsActions({}, {}, {}, {}),
    105                             HarvestCirclePlatformActions(),
    106                         )
    107                     }
    108                 }
    109             }
    110 
    111             onNodeWithTag("project-storage-schema").performScrollTo().assertIsDisplayed()
    112         }
    113 }