From 14496bb51046a8a36364d42e8206f223a02a7a55 Mon Sep 17 00:00:00 2001 From: M57 <41645758+Hy4ri@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:09:25 +0300 Subject: [PATCH] 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. --- .../ui/chat/ChatViewModelTest.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/src/test/java/com/m57/hermescontrol/ui/chat/ChatViewModelTest.kt b/app/src/test/java/com/m57/hermescontrol/ui/chat/ChatViewModelTest.kt index a7565c39..52578442 100644 --- a/app/src/test/java/com/m57/hermescontrol/ui/chat/ChatViewModelTest.kt +++ b/app/src/test/java/com/m57/hermescontrol/ui/chat/ChatViewModelTest.kt @@ -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) + } }