Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SettingsScreenInstallKeyboardButtonTest {
every { mockViewModel.vibrateOnKeypress } returns MutableStateFlow(false)
every { mockViewModel.popupOnKeypress } returns MutableStateFlow(false)
every { mockViewModel.isUserDarkMode } returns MutableStateFlow(false)
every { mockViewModel.isIncreaseTextSize } returns MutableStateFlow(false)
return mockViewModel
}

Expand All @@ -43,6 +44,7 @@ class SettingsScreenInstallKeyboardButtonTest {
SettingsScreen(
onDarkModeChange = {},
onLanguageSettingsClick = {},
onIncreaseTextSizeChange = {},
context = context,
viewModel = mockViewModel,
)
Expand All @@ -68,6 +70,7 @@ class SettingsScreenInstallKeyboardButtonTest {
SettingsScreen(
onDarkModeChange = {},
onLanguageSettingsClick = {},
onIncreaseTextSizeChange = {},
context = context,
viewModel = mockViewModel,
)
Expand All @@ -90,6 +93,7 @@ class SettingsScreenInstallKeyboardButtonTest {
SettingsScreen(
onDarkModeChange = {},
onLanguageSettingsClick = {},
onIncreaseTextSizeChange = {},
context = context,
viewModel = mockViewModel,
)
Expand All @@ -113,6 +117,7 @@ class SettingsScreenInstallKeyboardButtonTest {
SettingsScreen(
onDarkModeChange = {},
onLanguageSettingsClick = {},
onIncreaseTextSizeChange = {},
context = context,
viewModel = mockViewModel,
)
Expand All @@ -137,6 +142,7 @@ class SettingsScreenInstallKeyboardButtonTest {
SettingsScreen(
onDarkModeChange = {},
onLanguageSettingsClick = {},
onIncreaseTextSizeChange = {},
context = context,
viewModel = mockViewModel,
)
Expand All @@ -160,6 +166,7 @@ class SettingsScreenInstallKeyboardButtonTest {
SettingsScreen(
onDarkModeChange = {},
onLanguageSettingsClick = {},
onIncreaseTextSizeChange = {},
context = context,
viewModel = mockViewModel,
)
Expand All @@ -186,6 +193,7 @@ class SettingsScreenInstallKeyboardButtonTest {
SettingsScreen(
onDarkModeChange = {},
onLanguageSettingsClick = {},
onIncreaseTextSizeChange = {},
context = context,
viewModel = mockViewModel,
)
Expand All @@ -210,6 +218,7 @@ class SettingsScreenInstallKeyboardButtonTest {
SettingsScreen(
onDarkModeChange = {},
onLanguageSettingsClick = {},
onIncreaseTextSizeChange = {},
context = context,
viewModel = mockViewModel,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.filterToOne
import androidx.compose.ui.test.hasClickAction
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
Expand Down Expand Up @@ -39,13 +36,15 @@ class SettingsScreenInstrumentedTest {
private lateinit var context: Context
private lateinit var mockViewModel: SettingsViewModel
private lateinit var onDarkModeChangeMock: (Boolean) -> Unit
private lateinit var onIncreaseTextSizeChangeMock: (Boolean) -> Unit
private lateinit var onLanguageSettingsClickMock: (String) -> Unit

@Before
fun setUp() {
context = InstrumentationRegistry.getInstrumentation().targetContext
mockViewModel = mockk(relaxed = true)
onDarkModeChangeMock = mockk(relaxed = true)
onIncreaseTextSizeChangeMock = mockk(relaxed = true)
onLanguageSettingsClickMock = mockk(relaxed = true)

// Setup comprehensive mock returns for all StateFlow properties
Expand All @@ -54,9 +53,11 @@ class SettingsScreenInstrumentedTest {
every { mockViewModel.vibrateOnKeypress } returns MutableStateFlow(false)
every { mockViewModel.popupOnKeypress } returns MutableStateFlow(false)
every { mockViewModel.isUserDarkMode } returns MutableStateFlow(false)
every { mockViewModel.isIncreaseTextSize } returns MutableStateFlow(false)

every { mockViewModel.refreshSettings(any()) } returns Unit
every { mockViewModel.setLightDarkMode(any()) } returns Unit
every { mockViewModel.setIncreaseTextSize(any()) } returns Unit
}

private fun setTestContent(content: @Composable () -> Unit) {
Expand All @@ -73,6 +74,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
Expand All @@ -88,6 +90,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
Expand All @@ -103,6 +106,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
Expand All @@ -118,6 +122,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
Expand All @@ -128,13 +133,34 @@ class SettingsScreenInstrumentedTest {
.assertIsDisplayed()
}

@Test
fun settingsScreen_increaseTextSizeSwitch_isDisplayed() {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
}

composeTestRule
.onNodeWithText(context.getString(R.string.i18n_app_settings_menu_increase_text_size))
.assertIsDisplayed()

composeTestRule
.onNodeWithText(context.getString(R.string.i18n_app_settings_menu_increase_text_size_description))
.assertIsDisplayed()
}

@Test
fun settingsScreen_whenKeyboardNotInstalled_showsInstallButton() {
every { mockViewModel.isKeyboardInstalled } returns MutableStateFlow(false)

setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
viewModel = mockViewModel,
Expand All @@ -156,6 +182,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
viewModel = mockViewModel,
Expand Down Expand Up @@ -183,6 +210,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
viewModel = mockViewModel,
Expand All @@ -206,12 +234,14 @@ class SettingsScreenInstrumentedTest {
every { mockViewModelSpy.vibrateOnKeypress } returns MutableStateFlow(false)
every { mockViewModelSpy.popupOnKeypress } returns MutableStateFlow(false)
every { mockViewModelSpy.isUserDarkMode } returns MutableStateFlow(false)
every { mockViewModelSpy.isIncreaseTextSize } returns MutableStateFlow(false)
every { mockViewModelSpy.refreshSettings(any()) } returns Unit
every { mockViewModelSpy.setLightDarkMode(any()) } returns Unit

setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
viewModel = mockViewModelSpy,
Expand All @@ -222,20 +252,50 @@ class SettingsScreenInstrumentedTest {

composeTestRule
.onNodeWithText(darkModeText)
.assertIsDisplayed()

composeTestRule
.onAllNodes(hasClickAction() and !hasText(darkModeText))
.filterToOne(
!hasText("App language") and !hasText("Install keyboards"),
).performClick()
.performClick()

composeTestRule.waitForIdle()

verify(timeout = 3000) { mockViewModelSpy.setLightDarkMode(true) }
verify(timeout = 3000) { onDarkModeChangeMock(true) }
}

@Test
fun settingsScreen_increaseTextSizeToggle_triggersCallbacks() {
every { mockViewModel.isIncreaseTextSize } returns MutableStateFlow(false)
val mockViewModelSpy = spyk(mockViewModel)

every { mockViewModelSpy.languages } returns MutableStateFlow(emptyList())
every { mockViewModelSpy.isKeyboardInstalled } returns MutableStateFlow(false)
every { mockViewModelSpy.vibrateOnKeypress } returns MutableStateFlow(false)
every { mockViewModelSpy.popupOnKeypress } returns MutableStateFlow(false)
every { mockViewModelSpy.isUserDarkMode } returns MutableStateFlow(false)
every { mockViewModelSpy.isIncreaseTextSize } returns MutableStateFlow(false)
every { mockViewModelSpy.refreshSettings(any()) } returns Unit
every { mockViewModelSpy.setIncreaseTextSize(any()) } returns Unit

setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
viewModel = mockViewModelSpy,
)
}

val increaseTextSizeText = "Increase app text size"

composeTestRule
.onNodeWithText(increaseTextSizeText)
.performClick()

composeTestRule.waitForIdle()

verify(timeout = 3000) { mockViewModelSpy.setIncreaseTextSize(true) }
verify(timeout = 3000) { onIncreaseTextSizeChangeMock(true) }
}

@Test
fun settingsScreen_refreshSettings_whenLifecycleResumes() {
val mockViewModelSpy = spyk(mockViewModel)
Expand All @@ -245,12 +305,14 @@ class SettingsScreenInstrumentedTest {
every { mockViewModelSpy.vibrateOnKeypress } returns MutableStateFlow(false)
every { mockViewModelSpy.popupOnKeypress } returns MutableStateFlow(false)
every { mockViewModelSpy.isUserDarkMode } returns MutableStateFlow(false)
every { mockViewModelSpy.isIncreaseTextSize } returns MutableStateFlow(false)
every { mockViewModelSpy.refreshSettings(any()) } returns Unit
every { mockViewModelSpy.setLightDarkMode(any()) } returns Unit

setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
viewModel = mockViewModelSpy,
Expand All @@ -265,6 +327,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
Expand All @@ -280,6 +343,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
Expand All @@ -298,6 +362,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
Expand All @@ -317,6 +382,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
viewModel = mockViewModel,
Expand All @@ -338,6 +404,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
viewModel = mockViewModel,
Expand All @@ -354,6 +421,7 @@ class SettingsScreenInstrumentedTest {
setTestContent {
SettingsScreen(
onDarkModeChange = onDarkModeChangeMock,
onIncreaseTextSizeChange = onIncreaseTextSizeChangeMock,
onLanguageSettingsClick = onLanguageSettingsClickMock,
context = context,
)
Expand Down
14 changes: 14 additions & 0 deletions app/src/keyboards/java/be/scri/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class MainActivity : ComponentActivity() {
.getUserDarkModePreference(context) == AppCompatDelegate.MODE_NIGHT_YES,
)
}

val isIncreaseTextSize =
remember {
mutableStateOf(
PreferencesHelper.getIncreaseTextSizePreference(context),
)
}

val pagerState =
rememberPagerState {
bottomBarScreens.size
Expand Down Expand Up @@ -82,13 +90,19 @@ class MainActivity : ComponentActivity() {

ScribeTheme(
useDarkTheme = isDarkMode.value,
isIncreaseTextSize = isIncreaseTextSize.value,
) {
ScribeApp(
pagerState = pagerState,
isDarkTheme = isDarkMode.value,
isIncreaseTextSize = isIncreaseTextSize.value,
onDarkModeChange = { darkMode ->
updateTheme(darkMode)
},
onIncreaseTextSizeChange = { increaseTextSize ->
PreferencesHelper.setIncreaseTextSizePreference(context, increaseTextSize)
isIncreaseTextSize.value = increaseTextSize
},
resetHints = {
isHintChangedMap[0] = true
isHintChangedMap[1] = true
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/be/scri/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ fun ScribeApp(
pagerState: PagerState,
navController: NavHostController,
onDarkModeChange: (Boolean) -> Unit,
onIncreaseTextSizeChange: (Boolean) -> Unit,
resetHints: () -> Unit,
@SuppressLint("ComposeUnstableCollections") isHintChanged: Map<Int, Boolean>,
onDismiss: (Int) -> Unit,
context: Context,
isDarkTheme: Boolean,
isIncreaseTextSize: Boolean,
modifier: Modifier = Modifier,
downloadViewModel: DataDownloadViewModel = viewModel(),
) {
Expand All @@ -87,6 +89,7 @@ fun ScribeApp(

ScribeTheme(
useDarkTheme = isDarkTheme,
isIncreaseTextSize = isIncreaseTextSize,
) {
Scaffold(
bottomBar = {
Expand Down Expand Up @@ -151,6 +154,9 @@ fun ScribeApp(
onDarkModeChange = { isDarkMode ->
onDarkModeChange(isDarkMode)
},
onIncreaseTextSizeChange = { increaseTextSize ->
onIncreaseTextSizeChange(increaseTextSize)
},
onLanguageSettingsClick = { language ->
navController.navigate(
"${Screen.LanguageSettings.route}/$language",
Expand Down
Loading
Loading