Render device settings before BT profile state arrives

This commit is contained in:
darken
2026-04-14 11:28:41 +02:00
committed by Matthias Urhahn
parent a37b9b0213
commit a6f292f737
2 changed files with 20 additions and 1 deletions
@@ -21,13 +21,16 @@ import io.mockk.verify
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import kotlinx.coroutines.withTimeout
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -298,4 +301,17 @@ class DeviceSettingsViewModelTest : BaseTest() {
vm.state.first().isClassicallyConnected shouldBe false
}
@Test
fun `state emits even when connected devices flow has not emitted yet`() = runTest(testDispatcher) {
every { bluetoothManager.connectedDevices } returns flow { awaitCancellation() }
val vm = createViewModel()
vm.initialize(testAddress)
val state = withTimeout(1_000) { vm.state.first() }
state.device?.address shouldBe testAddress
state.isClassicallyConnected shouldBe false
}
}