aboutsummaryrefslogtreecommitdiff
path: root/plugins/all-modules-page/src/test/kotlin/org
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2021-01-05 17:59:38 +0100
committerGitHub <noreply@github.com>2021-01-05 17:59:38 +0100
commit1618e552c136e25d86bf0708e0d760841c77c139 (patch)
treec608ce91b020bb0ecbfe75d0f456a0eae84b4c51 /plugins/all-modules-page/src/test/kotlin/org
parentef98e4b6505c3fdd192b1d5057c718079d27b972 (diff)
downloaddokka-1618e552c136e25d86bf0708e0d760841c77c139.tar.gz
dokka-1618e552c136e25d86bf0708e0d760841c77c139.tar.bz2
dokka-1618e552c136e25d86bf0708e0d760841c77c139.zip
Versioning (#1654)
* Adding versioning mechanism for multimodule * Versioning improvement * Refactor configuration, add ordering * Fix integration tests * Change packages, unignore test Co-authored-by: Marcin Aman <marcin.aman@gmail.com>
Diffstat (limited to 'plugins/all-modules-page/src/test/kotlin/org')
-rw-r--r--plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/AddToNavigationCommandResolutionTest.kt137
-rw-r--r--plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/AddToSearchCommandResolutionTest.kt90
-rw-r--r--plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/ResolveLinkCommandResolutionTest.kt107
-rw-r--r--plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/ResolveLinkGfmCommandResolutionTest.kt74
-rw-r--r--plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/SubstitutionCommandResolutionTest.kt69
-rw-r--r--plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/assertHtmlEqualsIgnoringWhitespace.kt18
-rw-r--r--plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/mockedPackageListFactory.kt12
7 files changed, 0 insertions, 507 deletions
diff --git a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/AddToNavigationCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/AddToNavigationCommandResolutionTest.kt
deleted file mode 100644
index f917916a..00000000
--- a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/AddToNavigationCommandResolutionTest.kt
+++ /dev/null
@@ -1,137 +0,0 @@
-package org.jetbrains.dokka.allModulesPage.templates
-
-import kotlinx.html.a
-import kotlinx.html.div
-import kotlinx.html.id
-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.templating.AddToNavigationCommand
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.junit.Rule
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.ValueSource
-import org.junit.rules.TemporaryFolder
-
-class AddToNavigationCommandResolutionTest : MultiModuleAbstractTest() {
- @get:Rule
- val folder: TemporaryFolder = TemporaryFolder()
-
- @Test
- fun `should substitute AddToNavigationCommand in root directory`() =
- addToNavigationTest {
- val output = folder.root.resolve("navigation.html").readText()
- val expected = expectedOutput(
- ModuleWithPrefix("module1"),
- ModuleWithPrefix("module2")
- )
- assertHtmlEqualsIgnoringWhitespace(expected, output)
- }
-
- @ParameterizedTest
- @ValueSource(strings = ["module1", "module2"])
- fun `should substitute AddToNavigationCommand in modules directory`(moduleName: String) =
- addToNavigationTest {
- val output = folder.root.resolve(moduleName).resolve("navigation.html").readText()
- val expected = expectedOutput(
- ModuleWithPrefix("module1", ".."),
- ModuleWithPrefix("module2", "..")
- )
- assertHtmlEqualsIgnoringWhitespace(expected, output)
- }
-
- private fun expectedOutput(vararg modulesWithPrefix: ModuleWithPrefix) = createHTML(prettyPrint = true)
- .div("sideMenu") {
- modulesWithPrefix.forEach { (moduleName, prefix) ->
- val relativePrefix = prefix?.let { "$it/" } ?: ""
- div("sideMenuPart") {
- id = "$moduleName-nav-submenu"
- div("overview") {
- a {
- href = "$relativePrefix$moduleName/module-page.html"
- span {
- +"module-$moduleName"
- }
- }
- }
- div("sideMenuPart") {
- id = "$moduleName-nav-submenu-0"
- div("overview") {
- a {
- href = "$relativePrefix$moduleName/$moduleName/package-page.html"
- span {
- +"package-$moduleName"
- }
- }
- }
- }
- }
- }
- }
-
- private fun inputForModule(moduleName: String) = createHTML()
- .templateCommand(AddToNavigationCommand(moduleName)) {
- div("sideMenuPart") {
- id = "$moduleName-nav-submenu"
- div("overview") {
- a {
- href = "module-page.html"
- span {
- +"module-$moduleName"
- }
- }
- }
- div("sideMenuPart") {
- id = "$moduleName-nav-submenu-0"
- div("overview") {
- a {
- href = "$moduleName/package-page.html"
- span {
- +"package-$moduleName"
- }
- }
- }
- }
- }
- }
-
- private fun addToNavigationTest(test: (DokkaContext) -> Unit) {
- folder.create()
- val module1 = folder.newFolder("module1")
- val module2 = folder.newFolder("module2")
-
- val configuration = dokkaConfiguration {
- modules = listOf(
- DokkaModuleDescriptionImpl(
- name = "module1",
- relativePathToOutputDirectory = module1,
- includes = emptySet(),
- sourceOutputDirectory = module1,
- ),
- DokkaModuleDescriptionImpl(
- name = "module2",
- relativePathToOutputDirectory = module2,
- includes = emptySet(),
- sourceOutputDirectory = module2,
- ),
- )
- this.outputDir = folder.root
- }
-
- val module1Navigation = module1.resolve("navigation.html")
- module1Navigation.writeText(inputForModule("module1"))
- val module2Navigation = module2.resolve("navigation.html")
- module2Navigation.writeText(inputForModule("module2"))
-
- testFromData(configuration, preserveOutputLocation = true) {
- submoduleProcessingStage = { ctx ->
- test(ctx)
- }
- }
- }
-
- private data class ModuleWithPrefix(val moduleName: String, val prefix: String? = null)
-} \ No newline at end of file
diff --git a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/AddToSearchCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/AddToSearchCommandResolutionTest.kt
deleted file mode 100644
index 238134c7..00000000
--- a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/AddToSearchCommandResolutionTest.kt
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.jetbrains.dokka.allModulesPage.templates
-
-import org.jetbrains.dokka.DokkaModuleDescriptionImpl
-import org.jetbrains.dokka.allModulesPage.MultiModuleAbstractTest
-import org.jetbrains.dokka.base.renderers.html.SearchRecord
-import org.jetbrains.dokka.base.templating.AddToSearch
-import org.jetbrains.dokka.base.templating.parseJson
-import org.jetbrains.dokka.base.templating.toJsonString
-import org.junit.Rule
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.ValueSource
-import org.junit.rules.TemporaryFolder
-import java.io.File
-import kotlin.test.assertEquals
-
-class AddToSearchCommandResolutionTest : MultiModuleAbstractTest() {
- companion object {
- val elements = listOf(
- SearchRecord(name = "name1", location = "location1"),
- SearchRecord(name = "name2", location = "location2")
- )
- val fromModule1 = AddToSearch(
- moduleName = "module1",
- elements = elements
- )
- val fromModule2 = AddToSearch(
- moduleName = "module2",
- elements = elements
- )
- }
-
- @get:Rule
- val folder: TemporaryFolder = TemporaryFolder()
-
- @ParameterizedTest
- @ValueSource(strings = ["navigation-pane.json", "pages.json"])
- fun `should merge navigation templates`(fileName: String) {
- val (module1Navigation, module2Navigation) = setupTestDirectoriesWithContent(fileName)
-
- val outputDir = folder.root
- val 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 = outputDir
- }
-
- testFromData(configuration, preserveOutputLocation = true) {
- submoduleProcessingStage = { _ ->
- val expected = elements.map { it.copy(location = "module1/${it.location}") } +
- elements.map { it.copy(location = "module2/${it.location}") }
-
- val output =
- parseJson<List<SearchRecord>>(outputDir.resolve("scripts/${fileName}").readText())
- assertEquals(expected, output.sortedBy { it.location })
-
- val outputFromModule1 = parseJson<List<SearchRecord>>(module1Navigation.readText())
- assertEquals(expected, outputFromModule1.sortedBy { it.location })
-
- val outputFromModule2 = parseJson<List<SearchRecord>>(module2Navigation.readText())
- assertEquals(expected, outputFromModule2.sortedBy { it.location })
- }
- }
- }
-
- private fun setupTestDirectoriesWithContent(fileName: String): List<File> {
- folder.create()
- val scriptsForModule1 = folder.newFolder("module1", "scripts")
- val scriptsForModule2 = folder.newFolder("module2", "scripts")
- folder.newFolder("scripts")
-
- val module1Navigation = scriptsForModule1.resolve(fileName)
- module1Navigation.writeText(toJsonString(fromModule1))
- val module2Navigation = scriptsForModule2.resolve(fileName)
- module2Navigation.writeText(toJsonString(fromModule2))
-
- return listOf(module1Navigation, module2Navigation)
- }
-} \ No newline at end of file
diff --git a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/ResolveLinkCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/ResolveLinkCommandResolutionTest.kt
deleted file mode 100644
index 1b4e8638..00000000
--- a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/ResolveLinkCommandResolutionTest.kt
+++ /dev/null
@@ -1,107 +0,0 @@
-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 java.io.File
-
-class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() {
- @get:Rule
- val folder: TemporaryFolder = TemporaryFolder()
-
- 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/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/org/jetbrains/dokka/allModulesPage/templates/ResolveLinkGfmCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/ResolveLinkGfmCommandResolutionTest.kt
deleted file mode 100644
index 62aa9338..00000000
--- a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/ResolveLinkGfmCommandResolutionTest.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-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()
-
- 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/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())
- }
- }
- }
-
- 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
- }
-} \ No newline at end of file
diff --git a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/SubstitutionCommandResolutionTest.kt b/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/SubstitutionCommandResolutionTest.kt
deleted file mode 100644
index 89984b46..00000000
--- a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/SubstitutionCommandResolutionTest.kt
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.jetbrains.dokka.allModulesPage.templates
-
-import kotlinx.html.a
-import kotlinx.html.div
-import kotlinx.html.id
-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.templating.PathToRootSubstitutionCommand
-import org.junit.Rule
-import org.junit.rules.TemporaryFolder
-import org.junit.jupiter.api.Test
-import java.io.File
-
-class SubstitutionCommandResolutionTest : MultiModuleAbstractTest() {
-
- @get:Rule
- val folder: TemporaryFolder = TemporaryFolder()
-
- @Test
- fun `should handle PathToRootCommand`() {
- val template = createHTML()
- .templateCommand(PathToRootSubstitutionCommand(pattern = "###", default = "default")) {
- a {
- href = "###index.html"
- div {
- id = "logo"
- }
- }
- }
-
- val expected = createHTML().a {
- href = "../index.html"
- div {
- id = "logo"
- }
- }
-
- val testedFile = createDirectoriesAndWriteContent(template)
-
- val configuration = dokkaConfiguration {
- modules = listOf(
- DokkaModuleDescriptionImpl(
- name = "module1",
- relativePathToOutputDirectory = folder.root.resolve("module1"),
- includes = emptySet(),
- sourceOutputDirectory = folder.root.resolve("module1"),
- )
- )
- this.outputDir = folder.root
- }
-
- testFromData(configuration, preserveOutputLocation = true){
- submoduleProcessingStage = {
- assertHtmlEqualsIgnoringWhitespace(expected, testedFile.readText())
- }
- }
- }
-
- private fun createDirectoriesAndWriteContent(content: String): File {
- folder.create()
- val module1 = folder.newFolder("module1")
- val module1Content = module1.resolve("index.html")
- module1Content.writeText(content)
- return module1Content
- }
-
-} \ No newline at end of file
diff --git a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/assertHtmlEqualsIgnoringWhitespace.kt b/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/assertHtmlEqualsIgnoringWhitespace.kt
deleted file mode 100644
index 5a9ff531..00000000
--- a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/assertHtmlEqualsIgnoringWhitespace.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.jetbrains.dokka.allModulesPage.templates
-
-import junit.framework.Assert.assertEquals
-import org.jsoup.Jsoup
-
-/**
- * Parses it using JSOUP, trims whitespace at the end of the line and asserts if they are equal
- * parsing is required to unify the formatting
- */
-fun assertHtmlEqualsIgnoringWhitespace(expected: String, actual: String) {
- assertEquals(
- Jsoup.parse(expected).outerHtml().trimSpacesAtTheEndOfLine(),
- Jsoup.parse(actual).outerHtml().trimSpacesAtTheEndOfLine()
- )
-}
-
-private fun String.trimSpacesAtTheEndOfLine(): String =
- replace(" \n", "\n") \ No newline at end of file
diff --git a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/mockedPackageListFactory.kt b/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/mockedPackageListFactory.kt
deleted file mode 100644
index 7a10041b..00000000
--- a/plugins/all-modules-page/src/test/kotlin/org/jetbrains/dokka/allModulesPage/templates/mockedPackageListFactory.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-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