Cotton code
62 lines · 2.4 KB · KotlinRaw
package com.cottondb.android.ui.settingsimport androidx.compose.ui.test.onRootimport androidx.compose.ui.test.captureToImageimport androidx.compose.ui.graphics.asAndroidBitmapimport androidx.compose.ui.test.junit4.createComposeRuleimport androidx.compose.ui.test.onNodeWithContentDescriptionimport androidx.compose.ui.test.onNodeWithTextimport androidx.compose.ui.test.performClickimport androidx.compose.ui.test.assertIsNotEnabledimport androidx.test.ext.junit.runners.AndroidJUnit4import com.cottondb.android.design.CottonThemeimport com.cottondb.android.ScreenEvidenceimport org.junit.Assert.assertEqualsimport org.junit.Ruleimport org.junit.Testimport org.junit.runner.RunWith@RunWith(AndroidJUnit4::class)class KeyboardSettingsScreenTest {    @get:Rule val compose = createComposeRule()    @Test fun setupActionsAndTypedCaptureRemainHostOwned() {        var enabled = 0        var selected = 0        var changed: Boolean? = null        var backs = 0        compose.setContent {            CottonTheme {                KeyboardSettingsScreen(false, null, { backs += 1 }, { changed = it }, { enabled += 1 }, { selected += 1 })            }        }        compose.onNodeWithContentDescription("Enable Cotton keyboard").performClick()        compose.onNodeWithContentDescription("Select Cotton keyboard").performClick()        compose.onNodeWithContentDescription("Keep what I type").performClick()        compose.onNodeWithContentDescription("Back").performClick()        assertEquals(1, enabled)        assertEquals(1, selected)        assertEquals(true, changed)        assertEquals(1, backs)        ScreenEvidence.capture("keyboard-settings-opt-in") { compose.onRoot().captureToImage().asAndroidBitmap() }    }    @Test fun problemRemainsVisibleAlongsideTheControls() {        compose.setContent {            CottonTheme {                KeyboardSettingsScreen(false, "Keyboard settings could not be opened.", {}, {}, {}, {})            }        }        compose.onNodeWithText("Keyboard settings could not be opened.").assertExists()        compose.onNodeWithContentDescription("Enable Cotton keyboard").assertExists()    }    @Test fun savingDisablesTheTypedCaptureSwitch() {        compose.setContent {            CottonTheme {                KeyboardSettingsScreen(false, null, {}, {}, {}, {}, enabled = false)            }        }        compose.onNodeWithContentDescription("Keep what I type").assertIsNotEnabled()    }}