Add comprehensive tests for loadSettings in SettingsViewModel (#697)
* test: add comprehensive tests for loadSettings in SettingsViewModel Adds `testLoadSettings_loadsAllProperties` to `SettingsViewModelTest.kt` to thoroughly verify that `loadSettings()` correctly maps all required settings properties from `AuthManager` to the `uiState`. The test utilizes `runTest` and `advanceUntilIdle()` to properly handle testing the coroutine launch in the ViewModel's init block. * test: add comprehensive tests for loadSettings in SettingsViewModel Adds `testLoadSettings_loadsAllProperties` to `SettingsViewModelTest.kt` to thoroughly verify that `loadSettings()` correctly maps all required settings properties from `AuthManager` to the `uiState`. The test utilizes `runTest` and `advanceUntilIdle()` to properly handle testing the coroutine launch in the ViewModel's init block. Fixes ktlint formatting issues on imports.
This commit is contained in:
1 file changed
+36
@@ -12,7 +12,9 @@ import io.mockk.verify
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||||
|
import kotlinx.coroutines.test.advanceUntilIdle
|
||||||
import kotlinx.coroutines.test.resetMain
|
import kotlinx.coroutines.test.resetMain
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
import kotlinx.coroutines.test.setMain
|
import kotlinx.coroutines.test.setMain
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@@ -105,6 +107,40 @@ class SettingsViewModelTest {
|
|||||||
assertEquals("Work", state.renameProfileName)
|
assertEquals("Work", state.renameProfileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testLoadSettings_loadsAllProperties() =
|
||||||
|
runTest {
|
||||||
|
every { AuthManager.getSelectedProfileId() } answers { "prof-2" }
|
||||||
|
every { AuthManager.getBaseUrl() } returns "https://192.168.1.10:9119/"
|
||||||
|
every { AuthManager.getToken() } returns "dummy_token"
|
||||||
|
every { AuthManager.isAutoReconnect() } returns false
|
||||||
|
every { AuthManager.getThemePreference() } returns ThemePreference.DARK
|
||||||
|
every { AuthManager.isUseDynamicColors() } returns false
|
||||||
|
every { AuthManager.getThemePreset() } returns ThemePreset.CATPPUCCIN
|
||||||
|
every { AuthManager.isTypingEffectEnabled() } returns false
|
||||||
|
every { AuthManager.getTypingEffectDelayMs() } returns 15
|
||||||
|
every { AuthManager.getConnectionProfiles() } returns testProfiles
|
||||||
|
every { AuthManager.getAppLanguage() } returns "fr"
|
||||||
|
|
||||||
|
val viewModel = SettingsViewModel(ioDispatcher = testDispatcher)
|
||||||
|
testDispatcher.scheduler.advanceUntilIdle()
|
||||||
|
|
||||||
|
val state = viewModel.uiState.value
|
||||||
|
|
||||||
|
assertEquals("https://192.168.1.10:9119/", state.baseUrl)
|
||||||
|
assertEquals("dummy_token", state.token)
|
||||||
|
assertEquals(false, state.autoReconnect)
|
||||||
|
assertEquals(ThemePreference.DARK, state.themePreference)
|
||||||
|
assertEquals(false, state.useDynamicColors)
|
||||||
|
assertEquals(ThemePreset.CATPPUCCIN, state.themePreset)
|
||||||
|
assertEquals(false, state.typingEffectEnabled)
|
||||||
|
assertEquals(15, state.typingEffectDelayMs)
|
||||||
|
assertEquals(testProfiles, state.profiles)
|
||||||
|
assertEquals("prof-2", state.selectedProfileId)
|
||||||
|
assertEquals("Home", state.renameProfileName)
|
||||||
|
assertEquals("fr", state.appLanguage)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLoadSettings_noSelectedProfile_renameEmpty() {
|
fun testLoadSettings_noSelectedProfile_renameEmpty() {
|
||||||
every { AuthManager.getConnectionProfiles() } returns testProfiles
|
every { AuthManager.getConnectionProfiles() } returns testProfiles
|
||||||
|
|||||||
Reference in new issue
Block a user