@@ -9,6 +9,7 @@ import com.synonym.bitkitcore.TrezorPublicKeyResponse
99import com.synonym.bitkitcore.TrezorSignedMessageResponse
1010import com.synonym.bitkitcore.TrezorTransportType
1111import com.synonym.bitkitcore.WalletSelection
12+ import kotlinx.coroutines.ExperimentalCoroutinesApi
1213import kotlinx.coroutines.flow.MutableSharedFlow
1314import kotlinx.coroutines.flow.MutableStateFlow
1415import kotlinx.coroutines.test.advanceUntilIdle
@@ -41,7 +42,7 @@ import kotlin.test.assertTrue
4142import kotlin.time.Clock
4243import kotlin.time.ExperimentalTime
4344
44- @OptIn(ExperimentalTime ::class )
45+ @OptIn(ExperimentalCoroutinesApi :: class , ExperimentalTime ::class )
4546@Suppress(" LargeClass" )
4647class TrezorRepoTest : BaseUnitTest () {
4748
@@ -355,6 +356,39 @@ class TrezorRepoTest : BaseUnitTest() {
355356 assertNotNull(sut.state.value.connected)
356357 }
357358
359+ @Test
360+ fun `app foreground auto-reconnects to a known bluetooth device` () = test {
361+ val features = mockFeatures()
362+ val device = mockDeviceInfo(
363+ transportType = TrezorTransportType .BLUETOOTH ,
364+ path = " ble-path" ,
365+ )
366+ whenever(hwWalletStore.loadKnownDevices()).thenReturn(
367+ listOf (mockKnownDevice(transportType = TransportType .BLUETOOTH ))
368+ )
369+ whenever(trezorService.isConnected()).thenReturn(false )
370+ whenever(trezorService.scan()).thenReturn(listOf (device))
371+ whenever(trezorService.connect(eq(DEVICE_ID ), any(), eq(false ))).thenReturn(features)
372+ sut = createSut()
373+
374+ sut.onAppForegrounded()
375+ advanceUntilIdle()
376+
377+ assertNotNull(sut.state.value.connected)
378+ verify(trezorService).connect(eq(DEVICE_ID ), any(), eq(false ))
379+ }
380+
381+ @Test
382+ fun `app foreground skips reconnect without a known bluetooth device` () = test {
383+ whenever(hwWalletStore.loadKnownDevices()).thenReturn(listOf (mockKnownDevice()))
384+ sut = createSut()
385+
386+ sut.onAppForegrounded()
387+ advanceUntilIdle()
388+
389+ verify(trezorService, never()).scan()
390+ }
391+
358392 @Test
359393 fun `onTransportRestored skips usb device without permission` () = test {
360394 val device = mockDeviceInfo()
0 commit comments