mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-15 02:36:12 -04:00
Render device settings before BT profile state arrives
This commit is contained in:
+16
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user