From 928b30db022235a741ca49301042336d3423be97 Mon Sep 17 00:00:00 2001 From: w2sv Date: Sat, 12 Oct 2024 22:50:21 +0200 Subject: [PATCH] Fix tests --- app/src/main/res/values/strings.xml | 2 +- .../com/w2sv/domain/model/FileTypeTest.kt | 8 +- .../navigatorconfig/NavigatorConfigTest.kt | 128 ++++++++++++++---- ...ick_move_permission_query_dialog_title.xml | 5 +- .../main/kotlin/com/w2sv/test/Parcelable.kt | 10 +- gradle/libs.versions.toml | 2 +- 6 files changed, 125 insertions(+), 30 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 68b1a588..9ba65a0c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -54,7 +54,7 @@ Examine the app\'s source code on GitHub Check out my other apps Support development - Buy me a coffee as a sign of gratitude if you feel like I\'ve deserved one + Buy me a coffee as a sign of gratitude ♥ Required Permissions Auto Rate the app in the PlayStore diff --git a/core/domain/src/test/kotlin/com/w2sv/domain/model/FileTypeTest.kt b/core/domain/src/test/kotlin/com/w2sv/domain/model/FileTypeTest.kt index 30ea73e6..ff159266 100644 --- a/core/domain/src/test/kotlin/com/w2sv/domain/model/FileTypeTest.kt +++ b/core/domain/src/test/kotlin/com/w2sv/domain/model/FileTypeTest.kt @@ -10,6 +10,12 @@ class FileTypeTest { @Test fun testParceling() { - FileType.values.forEach { it.testParceling() } + FileType.Image.testParceling() + FileType.Video.testParceling() + FileType.Audio.testParceling() + + FileType.EBook.testParceling() + FileType.PDF.testParceling() + FileType.APK.testParceling() } } \ No newline at end of file diff --git a/core/domain/src/test/kotlin/com/w2sv/domain/model/navigatorconfig/NavigatorConfigTest.kt b/core/domain/src/test/kotlin/com/w2sv/domain/model/navigatorconfig/NavigatorConfigTest.kt index 3824c02d..a6585d19 100644 --- a/core/domain/src/test/kotlin/com/w2sv/domain/model/navigatorconfig/NavigatorConfigTest.kt +++ b/core/domain/src/test/kotlin/com/w2sv/domain/model/navigatorconfig/NavigatorConfigTest.kt @@ -4,24 +4,24 @@ import com.w2sv.common.util.copy import com.w2sv.common.util.update import com.w2sv.domain.model.FileType import com.w2sv.domain.model.SourceType +import com.w2sv.domain.model.movedestination.LocalDestination import org.junit.Assert.assertEquals import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +@RunWith(RobolectricTestRunner::class) internal class NavigatorConfigTest { @Test - fun testEnabledDisabledFileTypes() { + fun `enabledFileTypes and disabledFileTypes`() { val config = NavigatorConfig.default.run { copy( fileTypeConfigMap = fileTypeConfigMap.copy { - update(FileType.Image) { - it.copy(enabled = false) - } - update(FileType.Video) { - it.copy(enabled = false) - } - update(FileType.Audio) { - it.copy(enabled = false) + FileType.Media.values.forEach { mediaFileType -> + update(mediaFileType) { fileTypeConfig -> + fileTypeConfig.copy(enabled = false) + } } } ) @@ -32,23 +32,105 @@ internal class NavigatorConfigTest { @Test fun testCopyWithAlteredFileTypeConfig() { - val config = NavigatorConfig.default.copyWithAlteredFileTypeConfig(FileType.Image) { - it.copy( - enabled = false, - sourceTypeConfigMap = it.sourceTypeConfigMap.copy { - update(SourceType.Screenshot) { - it.copy(enabled = false) + val config = + NavigatorConfig.default.copyWithAlteredFileTypeConfig(FileType.Image) { fileTypeConfig -> + fileTypeConfig.copy( + enabled = false, + sourceTypeConfigMap = fileTypeConfig.sourceTypeConfigMap.copy { + update(SourceType.Screenshot) { + it.copy( + enabled = false, + quickMoveDestinations = listOf(LocalDestination.parse("path/to/destination")), + autoMoveConfig = AutoMoveConfig( + enabled = true, + destination = LocalDestination.parse("path/to/auto/move/dest") + ) + ) + } + update(SourceType.Camera) { + it.copy(enabled = false) + } } - update(SourceType.Camera) { - it.copy(enabled = false) - } - } - ) - } + ) + } + + val expected = NavigatorConfig( + fileTypeConfigMap = mapOf( + FileType.Image to FileTypeConfig( + enabled = false, + sourceTypeConfigMap = mapOf( + SourceType.Camera to SourceConfig( + enabled = false, + quickMoveDestinations = emptyList(), + autoMoveConfig = AutoMoveConfig.Empty + ), + SourceType.Screenshot to SourceConfig( + enabled = false, + quickMoveDestinations = listOf(LocalDestination.parse("path/to/destination")), + autoMoveConfig = AutoMoveConfig( + enabled = true, + destination = LocalDestination.parse("path/to/auto/move/dest") + ) + ), + SourceType.OtherApp to SourceConfig(), + SourceType.Download to SourceConfig() + ) + ), + FileType.Video to FileTypeConfig( + enabled = true, + sourceTypeConfigMap = mapOf( + SourceType.Camera to SourceConfig(), + SourceType.OtherApp to SourceConfig(), + SourceType.Download to SourceConfig() + ) + ), + FileType.Audio to FileTypeConfig( + enabled = true, + sourceTypeConfigMap = mapOf( + SourceType.Recording to SourceConfig(), + SourceType.OtherApp to SourceConfig(), + SourceType.Download to SourceConfig() + ) + ), + FileType.PDF to FileTypeConfig( + enabled = true, + sourceTypeConfigMap = mapOf( + SourceType.Download to SourceConfig() + ) + ), + FileType.Text to FileTypeConfig( + enabled = true, + sourceTypeConfigMap = mapOf( + SourceType.Download to SourceConfig() + ) + ), + FileType.Archive to FileTypeConfig( + enabled = true, + sourceTypeConfigMap = mapOf( + SourceType.Download to SourceConfig() + ) + ), + FileType.APK to FileTypeConfig( + enabled = true, + sourceTypeConfigMap = mapOf( + SourceType.Download to SourceConfig() + ) + ), + FileType.EBook to FileTypeConfig( + enabled = true, + sourceTypeConfigMap = mapOf( + SourceType.Download to SourceConfig() + ) + ) + ), + showBatchMoveNotification = true, + disableOnLowBattery = false, + startOnBoot = false + ) assertEquals( - "NavigatorConfig(fileTypeConfigMap={Image=FileTypeConfig(enabled=false, sourceTypeConfigMap={Camera=SourceConfig(enabled=false, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), Screenshot=SourceConfig(enabled=false, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), OtherApp=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), Video=FileTypeConfig(enabled=true, sourceTypeConfigMap={Camera=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), OtherApp=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), Audio=FileTypeConfig(enabled=true, sourceTypeConfigMap={Recording=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), OtherApp=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null)), Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), PDF=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), Text=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), Archive=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), APK=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))}), EBook=FileTypeConfig(enabled=true, sourceTypeConfigMap={Download=SourceConfig(enabled=true, lastMoveDestinations=[], autoMoveConfig=AutoMoveConfig(enabled=false, destination=null))})}, showBatchMoveNotification=true, disableOnLowBattery=false, startOnBoot=false)", - config.toString() + expected, + config ) } } \ No newline at end of file diff --git a/core/navigator/src/main/res/layout/quick_move_permission_query_dialog_title.xml b/core/navigator/src/main/res/layout/quick_move_permission_query_dialog_title.xml index e525524b..4bde84df 100644 --- a/core/navigator/src/main/res/layout/quick_move_permission_query_dialog_title.xml +++ b/core/navigator/src/main/res/layout/quick_move_permission_query_dialog_title.xml @@ -1,16 +1,17 @@ - + app:tint="@color/ic_launcher_foreground" /> \ No newline at end of file diff --git a/core/test/src/main/kotlin/com/w2sv/test/Parcelable.kt b/core/test/src/main/kotlin/com/w2sv/test/Parcelable.kt index 4bf7e1a2..07c817c8 100644 --- a/core/test/src/main/kotlin/com/w2sv/test/Parcelable.kt +++ b/core/test/src/main/kotlin/com/w2sv/test/Parcelable.kt @@ -10,9 +10,15 @@ import org.junit.Assert.assertEquals */ inline fun T.testParceling(flags: Int = 0) { val parcel = Parcel.obtain() - writeToParcel(parcel, flags) + this.writeToParcel(parcel, flags) + // Reset the parcel's position for reading parcel.setDataPosition(0) - assertEquals(this, parcelableCreator().createFromParcel(parcel)) + // Assert that the original and recreated objects are equal + val recreated = parcelableCreator().createFromParcel(parcel) + assertEquals(this, recreated) + + // Recycle the parcel to avoid memory leaks + parcel.recycle() } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fabe874c..567178a6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -91,7 +91,7 @@ androidx-test-rules = "androidx.test:rules:1.6.1" androidx-test-runner = "androidx.test:runner:1.6.2" androidx-test-ext-junit = "androidx.test.ext:junit:1.2.1" #androidx-test-uiautomator = "androidx.test.uiautomator:uiautomator:2.3.0" -roboelectric = "org.robolectric:robolectric:4.12.2" +roboelectric = "org.robolectric:robolectric:4.13" mockito-kotlin = "org.mockito.kotlin:mockito-kotlin:5.4.0" kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" }