aboutsummaryrefslogtreecommitdiff
path: root/plugins/all-modules-page/src/test/kotlin/templates
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/all-modules-page/src/test/kotlin/templates')
-rw-r--r--plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt108
-rw-r--r--plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt74
-rw-r--r--plugins/all-modules-page/src/test/kotlin/templates/mockedPackageListFactory.kt12
3 files changed, 194 insertions, 0 deletions
diff --git a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt
new file mode 100644
index 00000000..cbf254a0
--- /dev/null
+++ b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkCommandResolutionTest.kt
@@ -0,0 +1,108 @@
+package org.jetbrains.dokka.allModulesPage.templates
+
+import kotlinx.html.a
+import kotlinx.html.span
+import kotlinx.html.stream.createHTML
+import org.jetbrains.dokka.DokkaModuleDescriptionImpl
+import org.jetbrains.dokka.allModulesPage.MultiModuleAbstractTest
+import org.jetbrains.dokka.base.renderers.html.templateCommand
+import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
+import org.jetbrains.dokka.base.templating.ResolveLinkCommand
+import org.jetbrains.dokka.links.DRI
+import org.junit.Rule
+import org.junit.jupiter.api.Test
+import org.junit.rules.TemporaryFolder
+import utils.assertHtmlEqualsIgnoringWhitespace
+import java.io.File
+
+class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() {
+ @get:Rule
+ val folder: TemporaryFolder = TemporaryFolder()
+
+ private fun configuration() = dokkaConfiguration {
+ modules = listOf(
+ DokkaModuleDescriptionImpl(
+ name = "module1",
+ relativePathToOutputDirectory = folder.root.resolve("module1"),
+ includes = emptySet(),
+ sourceOutputDirectory = folder.root.resolve("module1"),
+ ),
+ DokkaModuleDescriptionImpl(
+ name = "module2",
+ relativePathToOutputDirectory = folder.root.resolve("module2"),
+ includes = emptySet(),
+ sourceOutputDirectory = folder.root.resolve("module2"),
+ )
+ )
+ this.outputDir = folder.root
+ }
+
+ @Test
+ fun `should resolve link to another module`() {
+ val testedDri = DRI(
+ packageName = "package2",
+ classNames = "Sample",
+ )
+ val link = createHTML().templateCommand(ResolveLinkCommand(testedDri)) {
+ span {
+ +"Sample"
+ }
+ }
+
+ val expected = createHTML().a {
+ href = "../../module2/package2/-sample/index.html"
+ span {
+ +"Sample"
+ }
+ }
+
+ val contentFile = setup(link)
+ val configuration = configuration()
+
+ testFromData(configuration, preserveOutputLocation = true) {
+ submoduleProcessingStage = {
+ assertHtmlEqualsIgnoringWhitespace(expected, contentFile.readText())
+ }
+ }
+ }
+
+ @Test
+ fun `should produce content when link is not resolvable`() {
+ val testedDri = DRI(
+ packageName = "not-resolvable-package",
+ classNames = "Sample",
+ )
+ val link = createHTML().templateCommand(ResolveLinkCommand(testedDri)) {
+ span {
+ +"Sample"
+ }
+ }
+
+ val expected = createHTML().span {
+ attributes["data-unresolved-link"] = testedDri.toString()
+ span {
+ +"Sample"
+ }
+ }
+
+ val contentFile = setup(link)
+ val configuration = configuration()
+
+ testFromData(configuration, preserveOutputLocation = true) {
+ submoduleProcessingStage = {
+ assertHtmlEqualsIgnoringWhitespace(expected, contentFile.readText())
+ }
+ }
+ }
+
+ fun setup(content: String): File {
+ folder.create()
+ val innerModule1 = folder.newFolder("module1", "module1")
+ val innerModule2 = folder.newFolder("module2", "module2")
+ val packageList = innerModule2.resolve("package-list")
+ packageList.writeText(mockedPackageListForPackages(RecognizedLinkFormat.DokkaHtml, "package2"))
+ val contentFile = innerModule1.resolve("index.html")
+ contentFile.writeText(content)
+ return contentFile
+ }
+} \ No newline at end of file
diff --git a/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt
new file mode 100644
index 00000000..75576727
--- /dev/null
+++ b/plugins/all-modules-page/src/test/kotlin/templates/ResolveLinkGfmCommandResolutionTest.kt
@@ -0,0 +1,74 @@
+package org.jetbrains.dokka.allModulesPage.templates
+
+import org.jetbrains.dokka.DokkaModuleDescriptionImpl
+import org.jetbrains.dokka.allModulesPage.MultiModuleAbstractTest
+import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
+import org.jetbrains.dokka.gfm.GfmCommand.Companion.templateCommand
+import org.jetbrains.dokka.gfm.GfmPlugin
+import org.jetbrains.dokka.gfm.ResolveLinkGfmCommand
+import org.jetbrains.dokka.gfm.templateProcessing.GfmTemplateProcessingPlugin
+import org.jetbrains.dokka.links.DRI
+import org.junit.Rule
+import org.junit.jupiter.api.Test
+import org.junit.rules.TemporaryFolder
+import java.io.File
+import kotlin.test.assertEquals
+
+class ResolveLinkGfmCommandResolutionTest : MultiModuleAbstractTest() {
+ @get:Rule
+ val folder: TemporaryFolder = TemporaryFolder()
+
+ private fun configuration() = dokkaConfiguration {
+ modules = listOf(
+ DokkaModuleDescriptionImpl(
+ name = "module1",
+ relativePathToOutputDirectory = folder.root.resolve("module1"),
+ includes = emptySet(),
+ sourceOutputDirectory = folder.root.resolve("module1"),
+ ),
+ DokkaModuleDescriptionImpl(
+ name = "module2",
+ relativePathToOutputDirectory = folder.root.resolve("module2"),
+ includes = emptySet(),
+ sourceOutputDirectory = folder.root.resolve("module2"),
+ )
+ )
+ this.outputDir = folder.root
+ }
+
+ @Test
+ fun `should resolve link to another module`(){
+ val testedDri = DRI(
+ packageName = "package2",
+ classNames = "Sample",
+ )
+
+ val link = StringBuilder().apply {
+ templateCommand(ResolveLinkGfmCommand(testedDri)){
+ append("Sample text inside")
+ }
+ }.toString()
+
+ val expected = "[Sample text inside](../../module2/package2/-sample/index.md)"
+
+ val content = setup(link)
+ val configuration = configuration()
+
+ testFromData(configuration, pluginOverrides = listOf(GfmTemplateProcessingPlugin(), GfmPlugin()), preserveOutputLocation = true) {
+ submoduleProcessingStage = {
+ assertEquals(expected, content.readText().trim())
+ }
+ }
+ }
+
+ private fun setup(content: String): File {
+ folder.create()
+ val innerModule1 = folder.newFolder("module1", "module1")
+ val innerModule2 = folder.newFolder("module2", "module2")
+ val packageList = innerModule2.resolve("package-list")
+ packageList.writeText(mockedPackageListForPackages(RecognizedLinkFormat.DokkaGFM, "package2"))
+ val contentFile = innerModule1.resolve("index.md")
+ contentFile.writeText(content)
+ return contentFile
+ }
+}
diff --git a/plugins/all-modules-page/src/test/kotlin/templates/mockedPackageListFactory.kt b/plugins/all-modules-page/src/test/kotlin/templates/mockedPackageListFactory.kt
new file mode 100644
index 00000000..7a10041b
--- /dev/null
+++ b/plugins/all-modules-page/src/test/kotlin/templates/mockedPackageListFactory.kt
@@ -0,0 +1,12 @@
+package org.jetbrains.dokka.allModulesPage.templates
+
+import org.jetbrains.dokka.base.renderers.PackageListService
+import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
+
+internal fun mockedPackageListForPackages(format: RecognizedLinkFormat, vararg packages: String): String =
+ """
+ ${PackageListService.DOKKA_PARAM_PREFIX}.format:${format.formatName}
+ ${PackageListService.DOKKA_PARAM_PREFIX}.linkExtension:${format.linkExtension}
+
+ ${packages.sorted().joinToString(separator = "\n", postfix = "\n") { it }}
+ """.trimIndent() \ No newline at end of file