Skip to content

Commit aad848a

Browse files
committed
fix test for ConfigKeyEventActionViewModel
1 parent f1cffed commit aad848a

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

app/src/main/java/io/github/sds100/keymapper/actions/keyevent/ConfigKeyEventActionViewModel.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ConfigKeyEventActionViewModel(
5959
buildUiState(state, inputDevices, showDeviceDescriptors)
6060
}.stateIn(
6161
viewModelScope,
62-
SharingStarted.Lazily,
62+
SharingStarted.Eagerly,
6363
buildUiState(
6464
keyEventState.value,
6565
inputDeviceList = emptyList(),
@@ -133,17 +133,15 @@ class ConfigKeyEventActionViewModel(
133133
}
134134

135135
fun chooseDevice(index: Int) {
136-
viewModelScope.launch {
137-
val chosenDevice = uiState.value.deviceListItems.getOrNull(index)
138-
139-
if (chosenDevice == null) {
140-
return@launch
141-
}
136+
val chosenDevice = uiState.value.deviceListItems.getOrNull(index)
142137

143-
keyEventState.value = keyEventState.value.copy(
144-
chosenDevice = chosenDevice,
145-
)
138+
if (chosenDevice == null) {
139+
return
146140
}
141+
142+
keyEventState.value = keyEventState.value.copy(
143+
chosenDevice = chosenDevice,
144+
)
147145
}
148146

149147
fun onDoneClick() {

app/src/test/java/io/github/sds100/keymapper/actions/keyevents/ConfigKeyServiceEventActionViewModelTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ConfigKeyServiceEventActionViewModelTest {
4646
@Before
4747
fun init() {
4848
Dispatchers.setMain(testDispatcher)
49-
inputDevices = MutableStateFlow(emptyList<InputDeviceInfo>())
49+
inputDevices = MutableStateFlow(emptyList())
5050

5151
mockUseCase = mock {
5252
on { showDeviceDescriptors }.then { MutableStateFlow(false) }

0 commit comments

Comments
 (0)