Skip to content

Commit 30596e8

Browse files
committed
test: Implement Settings refresh and update desktop back navigation
- **Settings**: - Added a unit test to `SettingsViewModelTest` to verify that the `Refresh` action correctly updates the encryption and language state. - Updated documentation to reflect pull-to-refresh support in both master and detail settings panes. - **Desktop UI Tests**: - Refactored `pressBack` in `DesktopUiTests` to handle multiple back buttons by identifying and clicking the right-most node with the back arrow content description. This ensures correct navigation in adaptive layouts.
1 parent 9f5a098 commit 30596e8

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

app/desktop/src/jvmTest/kotlin/com/softartdev/notedelight/ui/DesktopUiTests.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import androidx.compose.ui.test.ExperimentalTestApi
99
import androidx.compose.ui.test.assertIsDisplayed
1010
import androidx.compose.ui.test.junit4.ComposeContentTestRule
1111
import androidx.compose.ui.test.junit4.createComposeRule
12-
import androidx.compose.ui.test.onNodeWithContentDescription
12+
import androidx.compose.ui.test.onAllNodesWithContentDescription
1313
import androidx.compose.ui.test.performClick
1414
import androidx.lifecycle.Lifecycle
1515
import androidx.lifecycle.compose.LocalLifecycleOwner
@@ -104,9 +104,12 @@ class DesktopUiTests : AbstractJvmUiTests() {
104104
override fun localeTest() = super.localeTest()
105105

106106
override fun pressBack() {
107-
composeTestRule.onNodeWithContentDescription(label = Icons.AutoMirrored.Filled.ArrowBack.name)
108-
.assertIsDisplayed()
109-
.performClick()
107+
val backButtons = composeTestRule.onAllNodesWithContentDescription(
108+
label = Icons.AutoMirrored.Filled.ArrowBack.name
109+
)
110+
val nodes = backButtons.fetchSemanticsNodes()
111+
val rightMostIndex = nodes.indices.maxBy { index -> nodes[index].boundsInRoot.left }
112+
backButtons[rightMostIndex].assertIsDisplayed().performClick()
110113
}
111114

112115
override fun closeSoftKeyboard() = Unit // Desktop doesn't have soft keyboard

core/presentation/src/androidHostTest/kotlin/com/softartdev/notedelight/presentation/settings/SettingsViewModelTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ class SettingsViewModelTest {
6868
@Test
6969
fun checkEncryptionFalse() = assertEncryption(false)
7070

71+
@Test
72+
fun refreshUpdatesSwitches() = runTest {
73+
Mockito.`when`(mockSafeRepo.databaseState).thenReturn(ENCRYPTED)
74+
Mockito.`when`(mockLocaleInteractor.languageEnum).thenReturn(LanguageEnum.ENGLISH)
75+
settingsViewModel.stateFlow.test {
76+
assertFalse(awaitItem().loading)
77+
settingsViewModel.onAction(SettingsAction.Refresh)
78+
var result: SecurityResult = awaitItem()
79+
while (result.loading) {
80+
result = awaitItem()
81+
}
82+
assertTrue(result.encryption)
83+
cancelAndIgnoreRemainingEvents()
84+
}
85+
Mockito.verifyNoMoreInteractions(mockRouter)
86+
}
87+
7188
private fun assertEncryption(encryption: Boolean) = runTest {
7289
val platformSQLiteState = if (encryption) ENCRYPTED else UNENCRYPTED
7390
Mockito.`when`(mockSafeRepo.databaseState).thenReturn(platformSQLiteState)

ui/shared/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Each screen is a composable function connected to a ViewModel:
9898
- `settings/master/SettingsMasterScreen.kt`: Category list (Theme, Security, Info)
9999
- `settings/detail/SettingsDetailScreen.kt`: Category detail preferences
100100
- `AdaptiveSettingsScreen.kt`: Adaptive list/detail scaffold for settings
101+
- Pull-to-refresh is supported on both the master and detail panes to re-sync settings state
101102
- Security password flows live in `ui/dialog/security/` (enter/confirm/change password dialogs)
102103

103104
#### Adaptive UI (`ui/main/`, `ui/settings/`)

0 commit comments

Comments
 (0)