@@ -27,6 +27,8 @@ import org.kabiri.android.usbterminal.util.IResourceProvider
27
27
import org.kabiri.android.usbterminal.util.isCloneArduinoBoard
28
28
import org.kabiri.android.usbterminal.util.isOfficialArduinoBoard
29
29
30
+ private const val OFFICIAL_VENDOR_ID = 0x0043
31
+
30
32
@OptIn(ExperimentalCoroutinesApi ::class )
31
33
internal class MainActivityViewModelTest {
32
34
private val testDispatcher: TestDispatcher = StandardTestDispatcher ()
@@ -59,7 +61,7 @@ internal class MainActivityViewModelTest {
59
61
fun `startObservingUsbDevice updates infoMessage and calls openDeviceAndPort when device is emitted` () =
60
62
runTest {
61
63
// arrange
62
- val expected = 0x0043
64
+ val expected = OFFICIAL_VENDOR_ID
63
65
val deviceFlow = MutableStateFlow <UsbDevice ?>(null )
64
66
val mockDevice: UsbDevice = mockk(relaxed = true )
65
67
every { mockDevice.vendorId } returns expected
@@ -134,6 +136,28 @@ internal class MainActivityViewModelTest {
134
136
verify(exactly = 1 ) { mockUsbUseCase.requestPermission(fakeDevice) }
135
137
}
136
138
139
+ @Test
140
+ fun `connect emits expected message and calls requestPermission when the device is neither official nor a clone` () =
141
+ runTest {
142
+ // arrange
143
+ val expected = " connecting anyways"
144
+
145
+ val fakeDevice: UsbDevice = mockk(relaxed = true )
146
+ mockkStatic(UsbDevice ::isOfficialArduinoBoard, UsbDevice ::isCloneArduinoBoard)
147
+ every { fakeDevice.isOfficialArduinoBoard() } returns false
148
+ every { fakeDevice.isCloneArduinoBoard() } returns false
149
+
150
+ every { mockUsbUseCase.scanForUsbDevices() } returns listOf (fakeDevice)
151
+ every { mockResourceProvider.getString(R .string.helper_error_connecting_anyway) } returns expected
152
+
153
+ // act
154
+ sut.connect()
155
+
156
+ // assert
157
+ assertThat(sut.infoMessage.value).isEqualTo(expected)
158
+ verify(exactly = 1 ) { mockUsbUseCase.requestPermission(fakeDevice) }
159
+ }
160
+
137
161
@Test
138
162
fun `connect emits expected message and calls requestPermission when the device is a clone` () =
139
163
runTest {
@@ -196,7 +220,7 @@ internal class MainActivityViewModelTest {
196
220
runTest {
197
221
// arrange
198
222
val mockDevice: UsbDevice = mockk(relaxed = true )
199
- val fakeVendorId = 0x0043
223
+ val fakeVendorId = OFFICIAL_VENDOR_ID
200
224
every { mockDevice.vendorId } returns fakeVendorId
201
225
every { mockUsbUseCase.usbDevice } returns MutableStateFlow (mockDevice)
202
226
every { mockUsbUseCase.hasPermission(mockDevice) } returns true
0 commit comments