Modularize messaging code (#3435)

This commit is contained in:
Phil Oliver 2025-10-12 13:07:03 -04:00 committed by GitHub
parent cd1a54f506
commit 886e9cfede
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 297 additions and 143 deletions

View file

@ -1,114 +0,0 @@
/*
* 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/>.
*/
package com.geeksville.mesh.compose
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.geeksville.mesh.ui.message.components.MessageItem
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.meshtastic.core.database.model.Message
import org.meshtastic.core.model.MessageStatus
import org.meshtastic.core.ui.component.preview.NodePreviewParameterProvider
@RunWith(AndroidJUnit4::class)
class MessageItemTest {
@get:Rule val composeTestRule = createComposeRule()
@Test
fun mqttIconIsDisplayedWhenViaMqttIsTrue() {
val testNode = NodePreviewParameterProvider().minnieMouse
val messageWithMqtt =
Message(
text = "Test message via MQTT",
time = "10:00",
fromLocal = false,
status = MessageStatus.RECEIVED,
snr = 2.5f,
rssi = 90,
hopsAway = 0,
uuid = 1L,
receivedTime = System.currentTimeMillis(),
node = testNode,
read = false,
routingError = 0,
packetId = 1234,
emojis = listOf(),
replyId = null,
viaMqtt = true,
)
composeTestRule.setContent {
MessageItem(
message = messageWithMqtt,
node = testNode,
selected = false,
onClick = {},
onLongClick = {},
onStatusClick = {},
ourNode = testNode,
)
}
// Check that the MQTT icon is displayed
composeTestRule.onNodeWithContentDescription("via MQTT").assertIsDisplayed()
}
@Test
fun mqttIconIsNotDisplayedWhenViaMqttIsFalse() {
val testNode = NodePreviewParameterProvider().minnieMouse
val messageWithoutMqtt =
Message(
text = "Test message not via MQTT",
time = "10:00",
fromLocal = false,
status = MessageStatus.RECEIVED,
snr = 2.5f,
rssi = 90,
hopsAway = 0,
uuid = 1L,
receivedTime = System.currentTimeMillis(),
node = testNode,
read = false,
routingError = 0,
packetId = 1234,
emojis = listOf(),
replyId = null,
viaMqtt = false,
)
composeTestRule.setContent {
MessageItem(
message = messageWithoutMqtt,
node = testNode,
selected = false,
onClick = {},
onLongClick = {},
onStatusClick = {},
ourNode = testNode,
)
}
// Check that the MQTT icon is not displayed
composeTestRule.onNodeWithContentDescription("via MQTT").assertDoesNotExist()
}
}