test: add SharingStatusChip tests and location sharing SettingsViewModel tests

Add UI tests for SharingStatusChip component:
- Singular/plural text display
- Stop button callback
- Large count handling

Add SettingsViewModel tests for location sharing methods:
- setLocationSharingEnabled (enable/disable with stopSharing)
- stopSharingWith
- stopAllSharing
- setDefaultSharingDuration
- setLocationPrecisionRadius

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
torlando-tech
2025-12-20 18:48:02 -05:00
parent ae4d7369be
commit f627df19ba
2 changed files with 178 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
package com.lxmf.messenger.ui.components
import android.app.Application
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.lxmf.messenger.test.RegisterComponentActivityRule
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
/**
* UI tests for SharingStatusChip.
*
* Tests:
* - Display with singular/plural text
* - Stop button callback
*/
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], application = Application::class)
class SharingStatusChipTest {
private val registerActivityRule = RegisterComponentActivityRule()
private val composeRule = createComposeRule()
@get:Rule
val ruleChain: RuleChain = RuleChain.outerRule(registerActivityRule).around(composeRule)
val composeTestRule get() = composeRule
@Test
fun `sharingStatusChip displays singular text for one person`() {
composeTestRule.setContent {
SharingStatusChip(
sharingWithCount = 1,
onStopAllClick = {},
)
}
composeTestRule.onNodeWithText("Sharing with 1 person").assertIsDisplayed()
}
@Test
fun `sharingStatusChip displays plural text for multiple people`() {
composeTestRule.setContent {
SharingStatusChip(
sharingWithCount = 3,
onStopAllClick = {},
)
}
composeTestRule.onNodeWithText("Sharing with 3 people").assertIsDisplayed()
}
@Test
fun `sharingStatusChip displays plural text for zero people`() {
composeTestRule.setContent {
SharingStatusChip(
sharingWithCount = 0,
onStopAllClick = {},
)
}
composeTestRule.onNodeWithText("Sharing with 0 people").assertIsDisplayed()
}
@Test
fun `sharingStatusChip displays stop button`() {
composeTestRule.setContent {
SharingStatusChip(
sharingWithCount = 2,
onStopAllClick = {},
)
}
composeTestRule.onNodeWithContentDescription("Stop sharing").assertIsDisplayed()
}
@Test
fun `sharingStatusChip stop button invokes callback`() {
var stopCalled = false
composeTestRule.setContent {
SharingStatusChip(
sharingWithCount = 2,
onStopAllClick = { stopCalled = true },
)
}
composeTestRule.onNodeWithContentDescription("Stop sharing").performClick()
assertTrue(stopCalled)
}
@Test
fun `sharingStatusChip displays with large count`() {
composeTestRule.setContent {
SharingStatusChip(
sharingWithCount = 100,
onStopAllClick = {},
)
}
composeTestRule.onNodeWithText("Sharing with 100 people").assertIsDisplayed()
}
}

View File

@@ -2016,6 +2016,73 @@ class SettingsViewModelTest {
// endregion
// region Location Sharing Tests
@Test
fun `setLocationSharingEnabled true saves to repository`() =
runTest {
viewModel = createViewModel()
viewModel.setLocationSharingEnabled(true)
coVerify { settingsRepository.saveLocationSharingEnabled(true) }
}
@Test
fun `setLocationSharingEnabled false saves to repository and stops all sharing`() =
runTest {
viewModel = createViewModel()
viewModel.setLocationSharingEnabled(false)
coVerify { settingsRepository.saveLocationSharingEnabled(false) }
coVerify { locationSharingManager.stopSharing(null) }
}
@Test
fun `stopSharingWith calls locationSharingManager stopSharing`() =
runTest {
viewModel = createViewModel()
val testHash = "testDestinationHash123"
viewModel.stopSharingWith(testHash)
coVerify { locationSharingManager.stopSharing(testHash) }
}
@Test
fun `stopAllSharing calls locationSharingManager stopSharing with null`() =
runTest {
viewModel = createViewModel()
viewModel.stopAllSharing()
coVerify { locationSharingManager.stopSharing(null) }
}
@Test
fun `setDefaultSharingDuration saves to repository`() =
runTest {
viewModel = createViewModel()
viewModel.setDefaultSharingDuration("FOUR_HOURS")
coVerify { settingsRepository.saveDefaultSharingDuration("FOUR_HOURS") }
}
@Test
fun `setLocationPrecisionRadius saves to repository and sends update`() =
runTest {
viewModel = createViewModel()
viewModel.setLocationPrecisionRadius(1000)
coVerify { settingsRepository.saveLocationPrecisionRadius(1000) }
coVerify { locationSharingManager.sendImmediateUpdate() }
}
// endregion
// region Manual Propagation Node Tests
@Test