Skip to content

Commit

Permalink
add deep links test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Oct 17, 2023
1 parent 1e7f19f commit 035cc79
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion deeplinks-plugin/deeplinks-plugin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
dependencies {
implementation(libs.toml)
implementation(libs.serialization)
implementation(projects.navigation)
implementation(projects.navigationTesting)

compileOnly(libs.android.gradle.api)

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
27 changes: 21 additions & 6 deletions navigation-testing/navigation-testing.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.freeletics.khonshu.navigation.deeplinks

import kotlin.test.assertTrue

public fun Set<DeepLinkHandler>.matchAllDeepLinks(defaultPrefixes: Set<DeepLinkHandler.Prefix>, toml: String) {
val codePrefixPatternCombinations = flatMapTo(HashSet()) { handler ->
handler.prefixes.ifEmpty { defaultPrefixes }.flatMap { prefix ->
handler.patterns.map { pattern ->
prefix to pattern
}
}
}

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")
}

0 comments on commit 035cc79

Please sign in to comment.