Add unit test for ChatViewModel.refreshSettings (#506)

* Add unit test for ChatViewModel.refreshSettings

This commit adds a missing test case for the `refreshSettings` function in `ChatViewModel.kt`. The new test verifies that the UI state correctly updates to reflect changes in `AuthManager` properties such as `typingEffectEnabled` and `typingEffectDelayMs`. This resolves the testing gap and ensures safer refactoring for settings management in the future.

* test(#506): strengthen refreshSettings test to prove live re-read + drop test_plan.md

Re-stub AuthManager after construction and assert the state delta, so the
test actually catches a regression where refreshSettings() would cache the
init-time value instead of re-reading AuthManager live. Removes the one-off
Jules planning artifact from the repo root.
This commit is contained in:
M57 authored and GitHub committed 2026-07-09 15:09:25 +03:00
1 parent 5c7363389d
commit 14496bb510
1 file changed
+29
@@ -888,4 +888,33 @@ class ChatViewModelTest {
assertNotNull(msgAfter)
assertNull(msgAfter!!.approvalInfo)
}
// ── Settings ─────────────────────────────────────────────────────────────
@Test
fun testRefreshSettings_updatesUiState() =
runTest {
// Given the default setup, init{} already calls refreshSettings() once,
// so the initial state reflects the setUp defaults (typingEffectEnabled=true,
// typingEffectDelayMs=30).
val viewModel = createViewModel()
advanceUntilIdle()
with(viewModel.uiState.value) {
assertTrue(typingEffectEnabled)
assertEquals(30, typingEffectDelayMs)
}
// When settings change after construction and refreshSettings() is re-invoked,
// the UI state must reflect the NEW values — this proves refreshSettings()
// re-reads AuthManager live (the real regression scenario).
every { AuthManager.isTypingEffectEnabled() } returns false
every { AuthManager.getTypingEffectDelayMs() } returns 50
viewModel.refreshSettings()
advanceUntilIdle()
// Then
val state = viewModel.uiState.value
assertFalse(state.typingEffectEnabled)
assertEquals(50, state.typingEffectDelayMs)
}
}