mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix(node): keep node detail screen active for remove confirmation
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Android/sessions/3944a0a8-4e30-400b-bdd4-d4c41695792b Co-authored-by: jamesarich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
2aa1c984b6
commit
58f09d7083
2 changed files with 91 additions and 4 deletions
|
|
@ -43,10 +43,7 @@ internal fun handleNodeAction(
|
|||
val route = viewModel.getDirectMessageRoute(menuAction.node, uiState.ourNode)
|
||||
navigateToMessages(route)
|
||||
}
|
||||
is NodeMenuAction.Remove -> {
|
||||
viewModel.handleNodeMenuAction(menuAction)
|
||||
onNavigateUp()
|
||||
}
|
||||
is NodeMenuAction.Remove -> viewModel.handleNodeMenuAction(menuAction)
|
||||
else -> viewModel.handleNodeMenuAction(menuAction)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.feature.node.detail
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import dev.mokkery.answering.returns
|
||||
import dev.mokkery.every
|
||||
import dev.mokkery.matcher.any
|
||||
import dev.mokkery.mock
|
||||
import dev.mokkery.verify
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import org.meshtastic.core.model.Node
|
||||
import org.meshtastic.core.repository.ServiceRepository
|
||||
import org.meshtastic.feature.node.component.NodeMenuAction
|
||||
import org.meshtastic.feature.node.domain.usecase.GetNodeDetailsUseCase
|
||||
import org.meshtastic.feature.node.model.NodeDetailAction
|
||||
import org.meshtastic.proto.User
|
||||
import kotlin.test.AfterTest
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertFalse
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class HandleNodeActionTest {
|
||||
|
||||
private val testDispatcher = UnconfinedTestDispatcher()
|
||||
private val nodeManagementActions: NodeManagementActions = mock()
|
||||
private val nodeRequestActions: NodeRequestActions = mock()
|
||||
private val serviceRepository: ServiceRepository = mock()
|
||||
private val getNodeDetailsUseCase: GetNodeDetailsUseCase = mock()
|
||||
|
||||
@BeforeTest
|
||||
fun setUp() {
|
||||
Dispatchers.setMain(testDispatcher)
|
||||
every { getNodeDetailsUseCase(any()) } returns emptyFlow()
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
fun tearDown() {
|
||||
Dispatchers.resetMain()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `remove action delegates to viewModel and does not navigate up immediately`() = runTest(testDispatcher) {
|
||||
val node = Node(num = 1234, user = User(id = "!1234"))
|
||||
every { nodeManagementActions.requestRemoveNode(any(), any()) } returns Unit
|
||||
val viewModel = createViewModel()
|
||||
var navigateUpCalled = false
|
||||
|
||||
handleNodeAction(
|
||||
action = NodeDetailAction.HandleNodeMenuAction(NodeMenuAction.Remove(node)),
|
||||
uiState = NodeDetailUiState(),
|
||||
navigateToMessages = {},
|
||||
onNavigateUp = { navigateUpCalled = true },
|
||||
onNavigate = {},
|
||||
viewModel = viewModel,
|
||||
)
|
||||
|
||||
verify { nodeManagementActions.requestRemoveNode(any(), node) }
|
||||
assertFalse(navigateUpCalled)
|
||||
}
|
||||
|
||||
private fun createViewModel() = NodeDetailViewModel(
|
||||
savedStateHandle = SavedStateHandle(mapOf("destNum" to 1234)),
|
||||
nodeManagementActions = nodeManagementActions,
|
||||
nodeRequestActions = nodeRequestActions,
|
||||
serviceRepository = serviceRepository,
|
||||
getNodeDetailsUseCase = getNodeDetailsUseCase,
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue