summaryrefslogtreecommitdiffhomepage
path: root/android/test
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2023-09-29 17:26:47 +0200
committerAlbin <albin@mullvad.net>2023-10-02 11:44:48 +0200
commitb10b2ba2c5d99d70befe1c7db8e5dee444ed7e0a (patch)
tree5a3027bc9156c3112d70a20021c7cad808e1d2c8 /android/test
parent3bf2f5767f9f7c363279be110c215c26bf9446e4 (diff)
downloadmullvadvpn-b10b2ba2c5d99d70befe1c7db8e5dee444ed7e0a.tar.xz
mullvadvpn-b10b2ba2c5d99d70befe1c7db8e5dee444ed7e0a.zip
Add konsist check for vm property names
Diffstat (limited to 'android/test')
-rw-r--r--android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt30
1 files changed, 28 insertions, 2 deletions
diff --git a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt
index 35ffe52c31..e5a2ae8e0b 100644
--- a/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt
+++ b/android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ViewModelTests.kt
@@ -2,6 +2,8 @@ package net.mullvad.mullvadvpn.test.arch
import androidx.lifecycle.ViewModel
import com.lemonappdev.konsist.api.Konsist
+import com.lemonappdev.konsist.api.ext.list.modifierprovider.withPublicOrDefaultModifier
+import com.lemonappdev.konsist.api.ext.list.properties
import com.lemonappdev.konsist.api.ext.list.withAllParentsOf
import com.lemonappdev.konsist.api.verify.assert
import org.junit.Test
@@ -9,8 +11,32 @@ import org.junit.Test
class ViewModelTests {
@Test
fun ensureViewModelsHaveViewModelSuffix() {
- Konsist.scopeFromProject().classes().withAllParentsOf(ViewModel::class).assert {
- it.name.endsWith("ViewModel")
+ allViewModels().assert { it.name.endsWith("ViewModel") }
+ }
+
+ // The purpose of this check is to both keep the naming consistent and also to avoid exposing
+ // properties that shouldn't be exposed.
+ @Test
+ fun ensurePublicPropertiesUsePermittedNames() {
+ allViewModels().properties().withPublicOrDefaultModifier().assert { property ->
+ permittedPublicPropertyNames.contains(property.name)
}
}
+
+ private fun allViewModels() =
+ Konsist.scopeFromProject().classes().withAllParentsOf(ViewModel::class)
+
+ companion object {
+ // TODO: The goal is to reduce this list to only "uiState" and "uiAction".
+ private val permittedPublicPropertyNames =
+ listOf(
+ "uiState",
+ "viewActions",
+ "toastMessages",
+ "uiCloseAction",
+ "enterTransitionEndAction",
+ "accountToken",
+ "changelogDialogUiState"
+ )
+ }
}