@@ -14,6 +14,7 @@ import kotlinx.coroutines.test.runCurrent
1414import org.junit.Before
1515import org.junit.Test
1616import org.mockito.kotlin.mock
17+ import org.mockito.kotlin.never
1718import org.mockito.kotlin.verify
1819import org.mockito.kotlin.whenever
1920import to.bitkit.R
@@ -102,11 +103,12 @@ class HwConnectViewModelTest : BaseUnitTest() {
102103 }
103104
104105 @Test
105- fun `onConnectClick scans usb before connecting a device seeded by route` () = test {
106+ fun `onConnectClick scans usb before connecting a usb attach route path` () = test {
107+ val devicePath = " /dev/bus/usb/001/002"
106108 val connectedFeatures = features(model = " Safe 3" )
107109 whenever(hwWalletRepo.scan(includeBluetooth = false )).thenReturn(Result .success(emptyList()))
108- whenever(hwWalletRepo.connect(" usb1 " )).thenReturn(Result .success(connectedFeatures))
109- sut.onFoundRoute(deviceId = " usb1 " , deviceModel = " Trezor" )
110+ whenever(hwWalletRepo.connect(devicePath )).thenReturn(Result .success(connectedFeatures))
111+ sut.onFoundRoute(deviceId = devicePath , deviceModel = " Trezor" )
110112
111113 sut.effects.test {
112114 sut.onConnectClick()
@@ -115,7 +117,23 @@ class HwConnectViewModelTest : BaseUnitTest() {
115117 }
116118
117119 verify(hwWalletRepo).scan(includeBluetooth = false )
118- verify(hwWalletRepo).connect(" usb1" )
120+ verify(hwWalletRepo).connect(devicePath)
121+ }
122+
123+ @Test
124+ fun `onConnectClick does not usb rescan before connecting a bluetooth route device` () = test {
125+ val connectedFeatures = features(model = " Safe 7" )
126+ whenever(hwWalletRepo.connect(" ble-device-id" )).thenReturn(Result .success(connectedFeatures))
127+ sut.onFoundRoute(deviceId = " ble-device-id" , deviceModel = " Trezor Safe 7" )
128+
129+ sut.effects.test {
130+ sut.onConnectClick()
131+ assertEquals(HwConnectEffect .NavigateToPaired , awaitItem())
132+ cancelAndIgnoreRemainingEvents()
133+ }
134+
135+ verify(hwWalletRepo).connect(" ble-device-id" )
136+ verify(hwWalletRepo, never()).scan(includeBluetooth = false )
119137 }
120138
121139 @Test
0 commit comments