diff --git a/deeplinks-plugin/deeplinks-plugin.gradle.kts b/deeplinks-plugin/deeplinks-plugin.gradle.kts index e0c430576..4d4d1789a 100644 --- a/deeplinks-plugin/deeplinks-plugin.gradle.kts +++ b/deeplinks-plugin/deeplinks-plugin.gradle.kts @@ -7,7 +7,7 @@ plugins { dependencies { implementation(libs.toml) implementation(libs.serialization) - implementation(projects.navigation) + implementation(projects.navigationTesting) compileOnly(libs.android.gradle.api) diff --git a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfigurator.kt b/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfigurator.kt index 4ff64bac0..2a061f24e 100644 --- a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfigurator.kt +++ b/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfigurator.kt @@ -1,5 +1,9 @@ package com.freeletics.khonshu.deeplinks.plugin +import com.freeletics.khonshu.navigation.deeplinks.DeepLinkDefinition +import com.freeletics.khonshu.navigation.deeplinks.DeepLinkDefinitions +import com.freeletics.khonshu.navigation.deeplinks.PatternDefinition +import com.freeletics.khonshu.navigation.deeplinks.PrefixDefinition import com.freeletics.khonshu.navigation.internal.InternalNavigationApi import java.io.File diff --git a/navigation-testing/navigation-testing.gradle.kts b/navigation-testing/navigation-testing.gradle.kts index 85d289b0c..0ec8576a1 100644 --- a/navigation-testing/navigation-testing.gradle.kts +++ b/navigation-testing/navigation-testing.gradle.kts @@ -1,16 +1,31 @@ plugins { - alias(libs.plugins.fgp.android) + alias(libs.plugins.fgp.multiplatform) alias(libs.plugins.fgp.publish) + alias(libs.plugins.kotlin.serialization) } freeletics { optIn("com.freeletics.khonshu.navigation.internal.InternalNavigationApi") + + multiplatform { + addJvmTarget() + addAndroidTarget() + } +} + +dependencies { } dependencies { - api(projects.navigation) - api(libs.coroutines.core) - api(libs.turbine) - implementation(libs.androidx.activity) - implementation(libs.truth) + "commonMainApi"(projects.navigation) + "commonMainApi"(libs.kotlin.test) + + "commonMainImplementation"(libs.toml) + "commonMainImplementation"(libs.serialization) + + "androidMainApi"(libs.coroutines.core) + "androidMainApi"(libs.turbine) + + "androidMainImplementation"(libs.androidx.activity) + "androidMainImplementation"(libs.truth) } diff --git a/navigation-testing/src/main/kotlin/com/freeletics/khonshu/navigation/NavigatorTurbine.kt b/navigation-testing/src/androidMain/kotlin/com/freeletics/khonshu/navigation/NavigatorTurbine.kt similarity index 100% rename from navigation-testing/src/main/kotlin/com/freeletics/khonshu/navigation/NavigatorTurbine.kt rename to navigation-testing/src/androidMain/kotlin/com/freeletics/khonshu/navigation/NavigatorTurbine.kt diff --git a/navigation-testing/src/main/kotlin/com/freeletics/khonshu/navigation/ResultOwnerTesting.kt b/navigation-testing/src/androidMain/kotlin/com/freeletics/khonshu/navigation/ResultOwnerTesting.kt similarity index 100% rename from navigation-testing/src/main/kotlin/com/freeletics/khonshu/navigation/ResultOwnerTesting.kt rename to navigation-testing/src/androidMain/kotlin/com/freeletics/khonshu/navigation/ResultOwnerTesting.kt diff --git a/navigation-testing/src/main/kotlin/com/freeletics/khonshu/navigation/TestNavEventCollector.kt b/navigation-testing/src/androidMain/kotlin/com/freeletics/khonshu/navigation/TestNavEventCollector.kt similarity index 100% rename from navigation-testing/src/main/kotlin/com/freeletics/khonshu/navigation/TestNavEventCollector.kt rename to navigation-testing/src/androidMain/kotlin/com/freeletics/khonshu/navigation/TestNavEventCollector.kt diff --git a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions.kt b/navigation-testing/src/commonMain/kotlin/com/freeletics/khonshu/navigation/deeplinks/DeepLinkDefinitions.kt similarity index 90% rename from deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions.kt rename to navigation-testing/src/commonMain/kotlin/com/freeletics/khonshu/navigation/deeplinks/DeepLinkDefinitions.kt index 8e9e31e61..b3647ff37 100644 --- a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions.kt +++ b/navigation-testing/src/commonMain/kotlin/com/freeletics/khonshu/navigation/deeplinks/DeepLinkDefinitions.kt @@ -1,7 +1,5 @@ -package com.freeletics.khonshu.deeplinks.plugin +package com.freeletics.khonshu.navigation.deeplinks -import com.freeletics.khonshu.navigation.deeplinks.DeepLinkHandler -import com.freeletics.khonshu.navigation.deeplinks.replacePlaceholders import com.freeletics.khonshu.navigation.internal.InternalNavigationApi import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString diff --git a/navigation-testing/src/commonMain/kotlin/com/freeletics/khonshu/navigation/deeplinks/DeepLinkTesting.kt b/navigation-testing/src/commonMain/kotlin/com/freeletics/khonshu/navigation/deeplinks/DeepLinkTesting.kt new file mode 100644 index 000000000..b8be40c63 --- /dev/null +++ b/navigation-testing/src/commonMain/kotlin/com/freeletics/khonshu/navigation/deeplinks/DeepLinkTesting.kt @@ -0,0 +1,29 @@ +package com.freeletics.khonshu.navigation.deeplinks + +import kotlin.test.assertTrue + +public fun Set.matchAllDeepLinks(defaultPrefixes: Set) { + val codePrefixPatternCombinations = flatMapTo(HashSet()) { handler -> + handler.prefixes.ifEmpty { defaultPrefixes }.flatMap { prefix -> + handler.patterns.map { pattern -> + prefix to pattern + } + } + } + + val toml = DeepLinkDefinitions::class.java.getResourceAsStream("deeplinks.toml")!!.readAllBytes().decodeToString() + val definitions = DeepLinkDefinitions.decodeFromString(toml) + val definedPrefixPatternCombinations = definitions.deepLinks.values.flatMapTo(HashSet()) { deepLink -> + deepLink.prefixes.ifEmpty { definitions.prefixes }.flatMap { prefix -> + deepLink.patterns.map { pattern -> + DeepLinkHandler.Prefix("${prefix.scheme}://${prefix.host}") to + DeepLinkHandler.Pattern(pattern.value) + } + } + } + + val codeOnly = codePrefixPatternCombinations - definedPrefixPatternCombinations + assertTrue(codeOnly.isEmpty(), "The following deep links are not defined in TOML but are present in code: $codeOnly") + val tomlOnly = definedPrefixPatternCombinations - codePrefixPatternCombinations + assertTrue(tomlOnly.isEmpty(), "The following deep links are not defined in code but are present in the TOML file: $tomlOnly") +}