mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: settings rework part 2, domain and usecase abstraction, tests (#4680)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
5f31df96d8
commit
8c6bd8ab7a
121 changed files with 5245 additions and 1332 deletions
|
|
@ -30,8 +30,8 @@ import org.junit.Assert.assertTrue
|
|||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.meshtastic.core.data.repository.RadioConfigRepository
|
||||
import org.meshtastic.core.model.ConnectionState
|
||||
import org.meshtastic.core.model.DataPacket
|
||||
import org.meshtastic.core.service.ConnectionState
|
||||
import org.meshtastic.proto.Config
|
||||
import org.meshtastic.proto.LocalConfig
|
||||
import org.meshtastic.proto.MeshPacket
|
||||
|
|
|
|||
|
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025-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 com.geeksville.mesh.service
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import okio.ByteString
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.meshtastic.core.model.DataPacket
|
||||
import org.meshtastic.core.service.ConnectionState
|
||||
import org.meshtastic.proto.PortNum
|
||||
|
||||
class MeshCommandSenderQueueTest {
|
||||
|
||||
private val packetHandler = mockk<PacketHandler>(relaxed = true)
|
||||
private val connectionStateHandler = mockk<ConnectionStateHandler>(relaxed = true)
|
||||
private val connectionStateFlow = MutableStateFlow<ConnectionState>(ConnectionState.Disconnected)
|
||||
|
||||
private lateinit var commandSender: MeshCommandSender
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
every { connectionStateHandler.connectionState } returns connectionStateFlow.asStateFlow()
|
||||
commandSender = MeshCommandSender(packetHandler, null, connectionStateHandler, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sendData queues TEXT_MESSAGE_APP when disconnected`() {
|
||||
val packet = DataPacket(dataType = PortNum.TEXT_MESSAGE_APP.value, bytes = ByteString.EMPTY)
|
||||
commandSender.sendData(packet)
|
||||
|
||||
verify(exactly = 0) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
|
||||
connectionStateFlow.value = ConnectionState.Connected
|
||||
commandSender.processQueuedPackets()
|
||||
|
||||
verify(exactly = 1) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sendData queues ATAK_PLUGIN when disconnected`() {
|
||||
val packet = DataPacket(dataType = PortNum.ATAK_PLUGIN.value, bytes = ByteString.EMPTY)
|
||||
commandSender.sendData(packet)
|
||||
|
||||
verify(exactly = 0) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
|
||||
connectionStateFlow.value = ConnectionState.Connected
|
||||
commandSender.processQueuedPackets()
|
||||
|
||||
verify(exactly = 1) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sendData queues ATAK_FORWARDER when disconnected`() {
|
||||
val packet = DataPacket(dataType = PortNum.ATAK_FORWARDER.value, bytes = ByteString.EMPTY)
|
||||
commandSender.sendData(packet)
|
||||
|
||||
verify(exactly = 0) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
|
||||
connectionStateFlow.value = ConnectionState.Connected
|
||||
commandSender.processQueuedPackets()
|
||||
|
||||
verify(exactly = 1) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sendData queues DETECTION_SENSOR_APP when disconnected`() {
|
||||
val packet = DataPacket(dataType = PortNum.DETECTION_SENSOR_APP.value, bytes = ByteString.EMPTY)
|
||||
commandSender.sendData(packet)
|
||||
|
||||
verify(exactly = 0) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
|
||||
connectionStateFlow.value = ConnectionState.Connected
|
||||
commandSender.processQueuedPackets()
|
||||
|
||||
verify(exactly = 1) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sendData queues PRIVATE_APP when disconnected`() {
|
||||
val packet = DataPacket(dataType = PortNum.PRIVATE_APP.value, bytes = ByteString.EMPTY)
|
||||
commandSender.sendData(packet)
|
||||
|
||||
verify(exactly = 0) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
|
||||
connectionStateFlow.value = ConnectionState.Connected
|
||||
commandSender.processQueuedPackets()
|
||||
|
||||
verify(exactly = 1) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sendData does NOT queue IP_TUNNEL_APP when disconnected`() {
|
||||
val packet = DataPacket(dataType = PortNum.IP_TUNNEL_APP.value, bytes = ByteString.EMPTY)
|
||||
commandSender.sendData(packet)
|
||||
|
||||
verify(exactly = 0) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
|
||||
connectionStateFlow.value = ConnectionState.Connected
|
||||
commandSender.processQueuedPackets()
|
||||
|
||||
verify(exactly = 0) { packetHandler.sendToRadio(any<org.meshtastic.proto.MeshPacket>()) }
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,9 @@ package com.geeksville.mesh.service
|
|||
import android.content.Context
|
||||
import androidx.glance.appwidget.GlanceAppWidget
|
||||
import androidx.glance.appwidget.updateAll
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkManager
|
||||
import com.geeksville.mesh.repository.radio.RadioInterfaceService
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
|
|
@ -37,12 +40,15 @@ import org.junit.Before
|
|||
import org.junit.Test
|
||||
import org.meshtastic.core.analytics.platform.PlatformAnalytics
|
||||
import org.meshtastic.core.data.repository.NodeRepository
|
||||
import org.meshtastic.core.data.repository.PacketRepository
|
||||
import org.meshtastic.core.data.repository.RadioConfigRepository
|
||||
import org.meshtastic.core.database.entity.MyNodeEntity
|
||||
import org.meshtastic.core.database.model.Node
|
||||
import org.meshtastic.core.model.ConnectionState
|
||||
import org.meshtastic.core.model.DataPacket
|
||||
import org.meshtastic.core.prefs.ui.UiPrefs
|
||||
import org.meshtastic.core.service.ConnectionState
|
||||
import org.meshtastic.core.service.MeshServiceNotifications
|
||||
import org.meshtastic.feature.messaging.domain.worker.SendMessageWorker
|
||||
import org.meshtastic.proto.Config
|
||||
import org.meshtastic.proto.LocalConfig
|
||||
import org.meshtastic.proto.LocalModuleConfig
|
||||
|
|
@ -67,6 +73,8 @@ class MeshConnectionManagerTest {
|
|||
private val commandSender: MeshCommandSender = mockk(relaxed = true)
|
||||
private val nodeManager: MeshNodeManager = mockk(relaxed = true)
|
||||
private val analytics: PlatformAnalytics = mockk(relaxed = true)
|
||||
private val packetRepository: PacketRepository = mockk(relaxed = true)
|
||||
private val workManager: WorkManager = mockk(relaxed = true)
|
||||
private val radioConnectionState = MutableStateFlow<ConnectionState>(ConnectionState.Disconnected)
|
||||
private val localConfigFlow = MutableStateFlow(LocalConfig())
|
||||
private val moduleConfigFlow = MutableStateFlow(LocalModuleConfig())
|
||||
|
|
@ -107,6 +115,8 @@ class MeshConnectionManagerTest {
|
|||
commandSender,
|
||||
nodeManager,
|
||||
analytics,
|
||||
packetRepository,
|
||||
workManager,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -194,10 +204,23 @@ class MeshConnectionManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `onRadioConfigLoaded processes queued packets and sets time`() = runTest(testDispatcher) {
|
||||
manager.onRadioConfigLoaded()
|
||||
fun `onRadioConfigLoaded enqueues queued packets and sets time`() = runTest(testDispatcher) {
|
||||
manager.start(backgroundScope)
|
||||
val packetId = 456
|
||||
val dataPacket = mockk<DataPacket>(relaxed = true)
|
||||
every { dataPacket.id } returns packetId
|
||||
coEvery { packetRepository.getQueuedPackets() } returns listOf(dataPacket)
|
||||
|
||||
verify { commandSender.processQueuedPackets() }
|
||||
manager.onRadioConfigLoaded()
|
||||
advanceUntilIdle()
|
||||
|
||||
verify {
|
||||
workManager.enqueueUniqueWork(
|
||||
match<String> { it.startsWith(SendMessageWorker.WORK_NAME_PREFIX) },
|
||||
any<ExistingWorkPolicy>(),
|
||||
any<OneTimeWorkRequest>(),
|
||||
)
|
||||
}
|
||||
verify { commandSender.sendAdmin(any(), initFn = any()) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import org.junit.Assert.assertEquals
|
|||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.meshtastic.core.service.ConnectionState
|
||||
import org.meshtastic.core.model.ConnectionState
|
||||
import org.meshtastic.core.service.ServiceRepository
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import org.junit.Test
|
|||
import org.meshtastic.core.data.repository.MeshLogRepository
|
||||
import org.meshtastic.core.data.repository.PacketRepository
|
||||
import org.meshtastic.core.database.entity.MeshLog
|
||||
import org.meshtastic.core.service.ConnectionState
|
||||
import org.meshtastic.core.model.ConnectionState
|
||||
import org.meshtastic.proto.Data
|
||||
import org.meshtastic.proto.MeshPacket
|
||||
import org.meshtastic.proto.PortNum
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue