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.
This commit is contained in:
M57 authored and GitHub committed 2026-07-09 15:21:45 +03:00
1 parent 2f5a841a03
commit 2f16ed7e62
1 file changed
+51
@@ -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)
}
}