aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/resourceLinks
diff options
context:
space:
mode:
authorFilip Zybała <fzybala@virtuslab.com>2020-06-03 14:43:27 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-06-03 15:18:58 +0200
commit7674ce23f132f727b71545ad3aa62be5059613d6 (patch)
tree687e6ad8aff39e27a1bec6c195089db54daad052 /plugins/base/src/test/kotlin/resourceLinks
parentcb705ba0f457b6e0eb02337d9444d6f0ad1e67a3 (diff)
downloaddokka-7674ce23f132f727b71545ad3aa62be5059613d6.tar.gz
dokka-7674ce23f132f727b71545ad3aa62be5059613d6.tar.bz2
dokka-7674ce23f132f727b71545ad3aa62be5059613d6.zip
Fixed problem with linking absolute links as relative
Diffstat (limited to 'plugins/base/src/test/kotlin/resourceLinks')
-rw-r--r--plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt71
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt b/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt
new file mode 100644
index 00000000..be87813b
--- /dev/null
+++ b/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt
@@ -0,0 +1,71 @@
+package resourceLinks
+
+import org.jetbrains.dokka.base.DokkaBase
+import org.jetbrains.dokka.pages.RootPageNode
+import org.jetbrains.dokka.plugability.DokkaPlugin
+import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
+import org.jetbrains.dokka.transformers.pages.PageTransformer
+import org.jsoup.Jsoup
+import org.junit.jupiter.api.Test
+import utils.TestOutputWriterPlugin
+
+class ResourceLinksTest : AbstractCoreTest() {
+ class TestResourcesAppenderPlugin(val resources: List<String>) : DokkaPlugin() {
+ class TestResourcesAppender(val resources: List<String>) : PageTransformer {
+ override fun invoke(input: RootPageNode) = input.transformContentPagesTree {
+ it.modified(
+ embeddedResources = it.embeddedResources + resources
+ )
+ }
+ }
+
+ val appender by extending {
+ plugin<DokkaBase>().htmlPreprocessors with TestResourcesAppender(resources)
+ }
+ }
+ @Test
+ fun resourceLinksTest() {
+ val configuration = dokkaConfiguration {
+ passes {
+ pass {
+ sourceRoots = listOf("src/main/kotlin/test/Test.kt")
+ }
+ }
+ }
+ val absoluteResources = listOf(
+ "https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css",
+ "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"
+ )
+ val relativeResources = listOf(
+ "test/relativePath.js",
+ "test/relativePath.css"
+ )
+
+ val source =
+ """
+ |/src/main/kotlin/test/Test.kt
+ |package example
+ """.trimIndent()
+ val writerPlugin = TestOutputWriterPlugin()
+ testInline(
+ source,
+ configuration,
+ pluginOverrides = listOf(TestResourcesAppenderPlugin(absoluteResources + relativeResources), writerPlugin)
+ ) {
+ renderingStage = {
+ root, context -> Jsoup
+ .parse(writerPlugin.writer.contents["root/example.html"])
+ .head()
+ .select("link, script")
+ .let {
+ absoluteResources.forEach {
+ r -> assert(it.`is`("[href=$r], [src=$r]"))
+ }
+ relativeResources.forEach {
+ r -> assert(it.`is`("[href=../$r] , [src=../$r]"))
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file