mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(test): Add comprehensive unit and instrumentation tests (#4260)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
4e2c429180
commit
45227fb142
26 changed files with 1270 additions and 307 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
* 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
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
* 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.component
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
|
|
@ -41,7 +40,6 @@ import org.meshtastic.core.model.util.UnitConversions
|
|||
import org.meshtastic.core.model.util.UnitConversions.toTempString
|
||||
import org.meshtastic.core.model.util.toSmallDistanceString
|
||||
import org.meshtastic.core.model.util.toSpeedString
|
||||
import org.meshtastic.core.strings.R
|
||||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.current
|
||||
import org.meshtastic.core.strings.dew_point
|
||||
|
|
@ -74,7 +72,7 @@ internal fun EnvironmentMetrics(
|
|||
remember(node.environmentMetrics, isFahrenheit, displayUnits) {
|
||||
buildList {
|
||||
with(node.environmentMetrics) {
|
||||
if (hasTemperature()) {
|
||||
if (!temperature.isNaN()) {
|
||||
add(
|
||||
VectorMetricInfo(
|
||||
Res.string.temperature,
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ import org.meshtastic.core.ui.util.toPosition
|
|||
import org.meshtastic.feature.map.model.TracerouteOverlay
|
||||
import org.meshtastic.feature.node.model.MetricsState
|
||||
import org.meshtastic.feature.node.model.TimeFrame
|
||||
import org.meshtastic.proto.ConfigProtos.Config
|
||||
import org.meshtastic.proto.MeshProtos
|
||||
import org.meshtastic.proto.MeshProtos.MeshPacket
|
||||
import org.meshtastic.proto.Portnums
|
||||
|
|
@ -240,11 +241,14 @@ constructor(
|
|||
launch {
|
||||
radioConfigRepository.deviceProfileFlow.collect { profile ->
|
||||
val moduleConfig = profile.moduleConfig
|
||||
val displayUnits = profile.config.display.units
|
||||
_state.update { state ->
|
||||
state.copy(
|
||||
isManaged = profile.config.security.isManaged,
|
||||
isFahrenheit = moduleConfig.telemetry.environmentDisplayFahrenheit,
|
||||
displayUnits = profile.config.display.units,
|
||||
isFahrenheit =
|
||||
moduleConfig.telemetry.environmentDisplayFahrenheit ||
|
||||
(displayUnits == Config.DisplayConfig.DisplayUnits.IMPERIAL),
|
||||
displayUnits = displayUnits,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* 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.metrics
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.meshtastic.feature.node.model.TimeFrame
|
||||
import org.meshtastic.proto.TelemetryProtos.EnvironmentMetrics
|
||||
import org.meshtastic.proto.TelemetryProtos.Telemetry
|
||||
|
||||
class EnvironmentMetricsStateTest {
|
||||
|
||||
@Test
|
||||
fun `environmentMetricsFiltered correctly calculates times`() {
|
||||
val now = (System.currentTimeMillis() / 1000).toInt()
|
||||
val metrics =
|
||||
listOf(
|
||||
Telemetry.newBuilder()
|
||||
.setTime(now - 100)
|
||||
.setEnvironmentMetrics(EnvironmentMetrics.newBuilder().setTemperature(20f))
|
||||
.build(),
|
||||
Telemetry.newBuilder()
|
||||
.setTime(now - 50)
|
||||
.setEnvironmentMetrics(EnvironmentMetrics.newBuilder().setTemperature(22f))
|
||||
.build(),
|
||||
Telemetry.newBuilder()
|
||||
.setTime(now)
|
||||
.setEnvironmentMetrics(EnvironmentMetrics.newBuilder().setTemperature(21f))
|
||||
.build(),
|
||||
)
|
||||
val state = EnvironmentMetricsState(metrics)
|
||||
val result = state.environmentMetricsFiltered(TimeFrame.TWENTY_FOUR_HOURS)
|
||||
|
||||
assertEquals(now - 100, result.times.first)
|
||||
assertEquals(now, result.times.second)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `environmentMetricsFiltered ignores invalid timestamps`() {
|
||||
val now = (System.currentTimeMillis() / 1000).toInt()
|
||||
val metrics =
|
||||
listOf(
|
||||
Telemetry.newBuilder()
|
||||
.setTime(0)
|
||||
.setEnvironmentMetrics(EnvironmentMetrics.newBuilder().setTemperature(20f))
|
||||
.build(),
|
||||
Telemetry.newBuilder()
|
||||
.setTime(now)
|
||||
.setEnvironmentMetrics(EnvironmentMetrics.newBuilder().setTemperature(21f))
|
||||
.build(),
|
||||
)
|
||||
val state = EnvironmentMetricsState(metrics)
|
||||
val result = state.environmentMetricsFiltered(TimeFrame.TWENTY_FOUR_HOURS)
|
||||
|
||||
// Only the valid timestamp should be considered for filters
|
||||
assertEquals(now, result.times.first)
|
||||
assertEquals(now, result.times.second)
|
||||
assertEquals(1, result.metrics.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `environmentMetricsFiltered handles valid zero temperatures`() {
|
||||
val now = (System.currentTimeMillis() / 1000).toInt()
|
||||
val metrics =
|
||||
listOf(
|
||||
Telemetry.newBuilder()
|
||||
.setTime(now)
|
||||
.setEnvironmentMetrics(EnvironmentMetrics.newBuilder().setTemperature(0.0f))
|
||||
.build(),
|
||||
)
|
||||
val state = EnvironmentMetricsState(metrics)
|
||||
val result = state.environmentMetricsFiltered(TimeFrame.TWENTY_FOUR_HOURS)
|
||||
|
||||
assertTrue(result.shouldPlot[Environment.TEMPERATURE.ordinal])
|
||||
assertEquals(0.0f, result.rightMinMax.first, 0.01f)
|
||||
assertEquals(0.0f, result.rightMinMax.second, 0.01f)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue