From 2f16ed7e629ac5cccad6c4420bc397763b3d3dd4 Mon Sep 17 00:00:00 2001 From: M57 <41645758+Hy4ri@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:21:45 +0300 Subject: [PATCH] test: add unit tests for SystemViewModel update confirm state toggles (#509) Added SystemViewModelTest to provide basic testing coverage for the openUpdateConfirm and closeUpdateConfirm methods. These methods handle state changes within the UI without side-effects or dependencies, so straightforward property assertions were sufficient. This improves overall code reliability by ensuring simple UI boolean states function predictably. --- .../ui/system/SystemViewModelTest.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/src/test/java/com/m57/hermescontrol/ui/system/SystemViewModelTest.kt diff --git a/app/src/test/java/com/m57/hermescontrol/ui/system/SystemViewModelTest.kt b/app/src/test/java/com/m57/hermescontrol/ui/system/SystemViewModelTest.kt new file mode 100644 index 00000000..16369a97 --- /dev/null +++ b/app/src/test/java/com/m57/hermescontrol/ui/system/SystemViewModelTest.kt @@ -0,0 +1,51 @@ +package com.m57.hermescontrol.ui.system + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.StandardTestDispatcher +import kotlinx.coroutines.test.resetMain +import kotlinx.coroutines.test.setMain +import org.junit.After +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test + +@OptIn(ExperimentalCoroutinesApi::class) +class SystemViewModelTest { + private val testDispatcher = StandardTestDispatcher() + + @Before + fun setup() { + Dispatchers.setMain(testDispatcher) + } + + @After + fun teardown() { + Dispatchers.resetMain() + } + + @Test + fun `openUpdateConfirm sets updateConfirmOpen to true`() { + val viewModel = SystemViewModel() + + assertFalse(viewModel.uiState.value.updateConfirmOpen) + + viewModel.openUpdateConfirm() + + assertTrue(viewModel.uiState.value.updateConfirmOpen) + } + + @Test + fun `closeUpdateConfirm sets updateConfirmOpen to false`() { + val viewModel = SystemViewModel() + + // First open it + viewModel.openUpdateConfirm() + assertTrue(viewModel.uiState.value.updateConfirmOpen) + + // Then close it + viewModel.closeUpdateConfirm() + assertFalse(viewModel.uiState.value.updateConfirmOpen) + } +}