mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: Enable test coverage and update CI (#4233)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
45d8f5944a
commit
962137ae4d
21 changed files with 140 additions and 126 deletions
|
|
@ -22,11 +22,13 @@ import io.mockk.mockk
|
|||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import no.nordicsemi.kotlin.ble.client.RemoteCharacteristic
|
||||
import no.nordicsemi.kotlin.ble.client.RemoteService
|
||||
import no.nordicsemi.kotlin.ble.client.android.CentralManager
|
||||
import no.nordicsemi.kotlin.ble.client.android.Peripheral
|
||||
import no.nordicsemi.kotlin.ble.client.android.ScanResult
|
||||
import no.nordicsemi.kotlin.ble.core.ConnectionState
|
||||
import org.junit.Test
|
||||
import java.util.UUID
|
||||
|
|
@ -50,8 +52,13 @@ class BleOtaTransportTest {
|
|||
val otaChar: RemoteCharacteristic = mockk(relaxed = true)
|
||||
val txChar: RemoteCharacteristic = mockk(relaxed = true)
|
||||
val service: RemoteService = mockk(relaxed = true)
|
||||
val scanResult: ScanResult = mockk()
|
||||
|
||||
every { scanResult.peripheral } returns peripheral
|
||||
|
||||
// Mock the scan call. It takes a Duration and a lambda.
|
||||
every { centralManager.scan(any(), any()) } returns flowOf(scanResult)
|
||||
|
||||
every { centralManager.getBondedPeripherals() } returns listOf(peripheral)
|
||||
every { peripheral.address } returns address
|
||||
every { peripheral.state } returns MutableStateFlow(ConnectionState.Connected)
|
||||
|
||||
|
|
@ -83,17 +90,9 @@ class BleOtaTransportTest {
|
|||
val hash = "hash"
|
||||
|
||||
// We mock write to immediately emit to notificationFlow
|
||||
coEvery { otaChar.write(any(), any()) } coAnswers
|
||||
{
|
||||
println("Mock writing, emitting OK to notificationFlow")
|
||||
notificationFlow.emit("OK\n".toByteArray())
|
||||
println("OK emitted to notificationFlow")
|
||||
}
|
||||
coEvery { otaChar.write(any(), any()) } coAnswers { notificationFlow.emit("OK\n".toByteArray()) }
|
||||
|
||||
println("Calling startOta")
|
||||
val result = transport.startOta(size, hash) {}
|
||||
println("startOta result: $result")
|
||||
|
||||
assert(result.isSuccess)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
package org.meshtastic.feature.messaging.component
|
||||
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.junit4.v2.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.Rule
|
||||
|
|
|
|||
|
|
@ -16,30 +16,17 @@
|
|||
*/
|
||||
import com.android.build.api.dsl.LibraryExtension
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 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/>.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.meshtastic.android.library)
|
||||
alias(libs.plugins.meshtastic.android.library.compose)
|
||||
alias(libs.plugins.meshtastic.hilt)
|
||||
}
|
||||
|
||||
configure<LibraryExtension> { namespace = "org.meshtastic.feature.node" }
|
||||
configure<LibraryExtension> {
|
||||
namespace = "org.meshtastic.feature.node"
|
||||
|
||||
defaultConfig { manifestPlaceholders["MAPS_API_KEY"] = "DEBUG_KEY" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.core.data)
|
||||
|
|
@ -68,4 +55,6 @@ dependencies {
|
|||
|
||||
googleImplementation(libs.location.services)
|
||||
googleImplementation(libs.maps.compose)
|
||||
|
||||
androidTestImplementation(libs.androidx.test.runner)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.settings.debugging
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -25,7 +24,7 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.junit4.v2.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
|
|
@ -33,11 +32,14 @@ import androidx.compose.ui.test.performTextInput
|
|||
import androidx.compose.ui.unit.dp
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.meshtastic.core.strings.getString
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.debug_active_filters
|
||||
import org.meshtastic.core.strings.debug_filters
|
||||
import org.meshtastic.feature.settings.debugging.DebugViewModel.UiMeshLog
|
||||
import org.meshtastic.core.strings.R as Res
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class DebugFiltersTest {
|
||||
|
|
@ -47,7 +49,7 @@ class DebugFiltersTest {
|
|||
@Test
|
||||
fun debugFilterBar_showsFilterButtonAndMenu() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val filterLabel = context.getString(Res.string.debug_filters)
|
||||
val filterLabel = getString(Res.string.debug_filters)
|
||||
composeTestRule.setContent {
|
||||
var filterTexts by remember { mutableStateOf(listOf<String>()) }
|
||||
var customFilterText by remember { mutableStateOf("") }
|
||||
|
|
@ -77,7 +79,7 @@ class DebugFiltersTest {
|
|||
@Test
|
||||
fun debugFilterBar_addCustomFilter_displaysActiveFilter() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val activeFiltersLabel = context.getString(Res.string.debug_active_filters)
|
||||
val activeFiltersLabel = getString(Res.string.debug_active_filters)
|
||||
composeTestRule.setContent {
|
||||
var filterTexts by remember { mutableStateOf(listOf<String>()) }
|
||||
var customFilterText by remember { mutableStateOf("") }
|
||||
|
|
@ -108,8 +110,7 @@ class DebugFiltersTest {
|
|||
|
||||
@Test
|
||||
fun debugActiveFilters_clearAllFilters_removesFilters() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val activeFiltersLabel = context.getString(Res.string.debug_active_filters)
|
||||
val activeFiltersLabel = getString(Res.string.debug_active_filters)
|
||||
composeTestRule.setContent {
|
||||
var filterTexts by remember { mutableStateOf(listOf("A", "B")) }
|
||||
DebugActiveFilters(
|
||||
|
|
|
|||
|
|
@ -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.settings.debugging
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -25,21 +24,24 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.junit4.v2.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performTextInput
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.meshtastic.core.strings.getString
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.debug_active_filters
|
||||
import org.meshtastic.core.strings.debug_default_search
|
||||
import org.meshtastic.core.strings.debug_filters
|
||||
import org.meshtastic.feature.settings.debugging.DebugViewModel.UiMeshLog
|
||||
import org.meshtastic.feature.settings.debugging.LogSearchManager.SearchMatch
|
||||
import org.meshtastic.feature.settings.debugging.LogSearchManager.SearchState
|
||||
import org.meshtastic.core.strings.R as Res
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class DebugSearchTest {
|
||||
|
|
@ -48,8 +50,7 @@ class DebugSearchTest {
|
|||
|
||||
@Test
|
||||
fun debugSearchBar_showsPlaceholder() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val placeholder = context.getString(Res.string.debug_default_search)
|
||||
val placeholder = getString(Res.string.debug_default_search)
|
||||
composeTestRule.setContent {
|
||||
DebugSearchBar(
|
||||
searchState = SearchState(),
|
||||
|
|
@ -64,8 +65,7 @@ class DebugSearchTest {
|
|||
|
||||
@Test
|
||||
fun debugSearchBar_showsClearButtonWhenTextEntered() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val placeholder = context.getString(Res.string.debug_default_search)
|
||||
val placeholder = getString(Res.string.debug_default_search)
|
||||
composeTestRule.setContent {
|
||||
var searchText by remember { mutableStateOf("test") }
|
||||
DebugSearchBar(
|
||||
|
|
@ -112,8 +112,7 @@ class DebugSearchTest {
|
|||
|
||||
@Test
|
||||
fun debugFilterBar_showsFilterButtonAndMenu() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val filterLabel = context.getString(Res.string.debug_filters)
|
||||
val filterLabel = getString(Res.string.debug_filters)
|
||||
composeTestRule.setContent {
|
||||
var filterTexts by remember { mutableStateOf(listOf<String>()) }
|
||||
var customFilterText by remember { mutableStateOf("") }
|
||||
|
|
@ -142,8 +141,7 @@ class DebugSearchTest {
|
|||
|
||||
@Test
|
||||
fun debugFilterBar_addCustomFilter_displaysActiveFilter() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val activeFiltersLabel = context.getString(Res.string.debug_active_filters)
|
||||
val activeFiltersLabel = getString(Res.string.debug_active_filters)
|
||||
composeTestRule.setContent {
|
||||
var filterTexts by remember { mutableStateOf(listOf<String>()) }
|
||||
var customFilterText by remember { mutableStateOf("") }
|
||||
|
|
@ -172,8 +170,7 @@ class DebugSearchTest {
|
|||
|
||||
@Test
|
||||
fun debugActiveFilters_clearAllFilters_removesFilters() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val activeFiltersLabel = context.getString(Res.string.debug_active_filters)
|
||||
val activeFiltersLabel = getString(Res.string.debug_active_filters)
|
||||
composeTestRule.setContent {
|
||||
var filterTexts by remember { mutableStateOf(listOf("A", "B")) }
|
||||
DebugActiveFilters(
|
||||
|
|
|
|||
|
|
@ -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,23 +14,25 @@
|
|||
* 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.settings.radio.component
|
||||
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.junit4.v2.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.meshtastic.core.strings.getString
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.cancel
|
||||
import org.meshtastic.core.strings.save
|
||||
import org.meshtastic.proto.ClientOnlyProtos.DeviceProfile
|
||||
import org.meshtastic.proto.deviceProfile
|
||||
import org.meshtastic.proto.position
|
||||
import org.meshtastic.core.strings.R as Res
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class EditDeviceProfileDialogTest {
|
||||
|
|
|
|||
|
|
@ -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,21 +14,25 @@
|
|||
* 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.settings.radio.component
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.junit4.v2.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.meshtastic.core.strings.getString
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.meshtastic.core.strings.Res
|
||||
import org.meshtastic.core.strings.i_agree
|
||||
import org.meshtastic.core.strings.map_reporting
|
||||
import org.meshtastic.core.strings.map_reporting_summary
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class MapReportingPreferenceTest {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue