diff options
Diffstat (limited to 'plugins/templating/src')
3 files changed, 64 insertions, 72 deletions
diff --git a/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/AddToNavigationCommandResolutionTest.kt b/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/AddToNavigationCommandResolutionTest.kt index 81d39752..06edfabd 100644 --- a/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/AddToNavigationCommandResolutionTest.kt +++ b/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/AddToNavigationCommandResolutionTest.kt @@ -9,39 +9,42 @@ import org.jetbrains.dokka.DokkaModuleDescriptionImpl 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.api.io.TempDir import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource -import org.junit.rules.TemporaryFolder import utils.assertHtmlEqualsIgnoringWhitespace +import java.io.File +import kotlin.test.Test class AddToNavigationCommandResolutionTest : TemplatingAbstractTest() { - @get:Rule - val folder: TemporaryFolder = TemporaryFolder() @Test - fun `should substitute AddToNavigationCommand in root directory`() = - addToNavigationTest { - val output = folder.root.resolve("navigation.html").readText() + fun `should substitute AddToNavigationCommand in root directory`(@TempDir outputDirectory: File) { + addToNavigationTest(outputDirectory) { + val output = outputDirectory.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() + fun `should substitute AddToNavigationCommand in modules directory`( + moduleName: String, + @TempDir outputDirectory: File + ) { + addToNavigationTest(outputDirectory) { + val output = outputDirectory.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") { @@ -98,10 +101,9 @@ class AddToNavigationCommandResolutionTest : TemplatingAbstractTest() { } } - private fun addToNavigationTest(test: (DokkaContext) -> Unit) { - folder.create() - val module1 = folder.newFolder("module1") - val module2 = folder.newFolder("module2") + private fun addToNavigationTest(outputDirectory: File, test: (DokkaContext) -> Unit) { + val module1 = outputDirectory.resolve("module1").also { it.mkdirs() } + val module2 = outputDirectory.resolve("module2").also { it.mkdirs() } val configuration = dokkaConfiguration { modules = listOf( @@ -118,7 +120,7 @@ class AddToNavigationCommandResolutionTest : TemplatingAbstractTest() { sourceOutputDirectory = module2, ), ) - this.outputDir = folder.root + this.outputDir = outputDirectory } val module1Navigation = module1.resolve("navigation.html") diff --git a/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/AddToSearchCommandResolutionTest.kt b/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/AddToSearchCommandResolutionTest.kt index 45c70469..b62f0f61 100644 --- a/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/AddToSearchCommandResolutionTest.kt +++ b/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/AddToSearchCommandResolutionTest.kt @@ -5,54 +5,35 @@ 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.api.io.TempDir 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 : TemplatingAbstractTest() { - 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 = ["pages.json"]) - fun `should merge navigation templates`(fileName: String) { - setupTestDirectoriesWithContent(fileName) + fun `should merge navigation templates`(fileName: String, @TempDir outputDirectory: File) { + setupTestDirectoriesWithContent(outputDirectory, fileName) - val outputDir = folder.root val configuration = dokkaConfiguration { modules = listOf( DokkaModuleDescriptionImpl( name = "module1", - relativePathToOutputDirectory = folder.root.resolve("module1"), + relativePathToOutputDirectory = outputDirectory.resolve("module1"), includes = emptySet(), - sourceOutputDirectory = folder.root.resolve("module1"), + sourceOutputDirectory = outputDirectory.resolve("module1"), ), DokkaModuleDescriptionImpl( name = "module2", - relativePathToOutputDirectory = folder.root.resolve("module2"), + relativePathToOutputDirectory = outputDirectory.resolve("module2"), includes = emptySet(), - sourceOutputDirectory = folder.root.resolve("module2"), + sourceOutputDirectory = outputDirectory.resolve("module2"), ), ) - this.outputDir = outputDir + this.outputDir = outputDirectory } testFromData(configuration, useOutputLocationFromConfig = true) { @@ -61,17 +42,16 @@ class AddToSearchCommandResolutionTest : TemplatingAbstractTest() { elements.map { it.copy(location = "module2/${it.location}") } val output = - parseJson<List<SearchRecord>>(outputDir.resolve("scripts/${fileName}").readText()) + parseJson<List<SearchRecord>>(outputDirectory.resolve("scripts/${fileName}").readText()) assertEquals(expected, output.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") + private fun setupTestDirectoriesWithContent(outputDirectory: File, fileName: String): List<File> { + val scriptsForModule1 = outputDirectory.resolve("module1/scripts").also { it.mkdirs() } + val scriptsForModule2 = outputDirectory.resolve("module2/scripts").also { it.mkdirs() } + outputDirectory.resolve("scripts").also { it.mkdirs() } val module1Navigation = scriptsForModule1.resolve(fileName) module1Navigation.writeText(toJsonString(fromModule1)) @@ -80,4 +60,19 @@ class AddToSearchCommandResolutionTest : TemplatingAbstractTest() { return listOf(module1Navigation, module2Navigation) } + + 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 + ) + } } diff --git a/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/SubstitutionCommandResolutionTest.kt b/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/SubstitutionCommandResolutionTest.kt index c31f63c7..d03a1b36 100644 --- a/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/SubstitutionCommandResolutionTest.kt +++ b/plugins/templating/src/test/kotlin/org/jetbrains/dokka/templates/SubstitutionCommandResolutionTest.kt @@ -9,19 +9,15 @@ import org.jetbrains.dokka.DokkaModuleDescriptionImpl import org.jetbrains.dokka.base.renderers.html.templateCommand import org.jetbrains.dokka.base.renderers.html.templateCommandAsHtmlComment import org.jetbrains.dokka.base.templating.PathToRootSubstitutionCommand -import org.junit.Rule -import org.junit.jupiter.api.Test -import org.junit.rules.TemporaryFolder +import org.junit.jupiter.api.io.TempDir import utils.assertHtmlEqualsIgnoringWhitespace import java.io.File +import kotlin.test.Test class SubstitutionCommandResolutionTest : TemplatingAbstractTest() { - @get:Rule - val folder: TemporaryFolder = TemporaryFolder() - @Test - fun `should handle PathToRootCommand`() { + fun `should handle PathToRootCommand`(@TempDir outputDirectory: File) { val template = createHTML() .templateCommand(PathToRootSubstitutionCommand(pattern = "###", default = "default")) { a { @@ -38,11 +34,11 @@ class SubstitutionCommandResolutionTest : TemplatingAbstractTest() { id = "logo" } } - checkSubstitutedResult(template, expected) + checkSubstitutedResult(outputDirectory, template, expected) } @Test - fun `should handle PathToRootCommand as HTML comment`() { + fun `should handle PathToRootCommand as HTML comment`(@TempDir outputDirectory: File) { val template = createHTML().span { templateCommandAsHtmlComment(PathToRootSubstitutionCommand(pattern = "###", default = "default")) { this@span.a { @@ -76,30 +72,22 @@ class SubstitutionCommandResolutionTest : TemplatingAbstractTest() { } } } - checkSubstitutedResult(template, expected) - } - - private fun createDirectoriesAndWriteContent(content: String): File { - folder.create() - val module1 = folder.newFolder("module1") - val module1Content = module1.resolve("index.html") - module1Content.writeText(content) - return module1Content + checkSubstitutedResult(outputDirectory, template, expected) } - private fun checkSubstitutedResult(template: String, expected:String) { - val testedFile = createDirectoriesAndWriteContent(template) + private fun checkSubstitutedResult(outputDirectory: File, template: String, expected:String) { + val testedFile = createDirectoriesAndWriteContent(outputDirectory, template) val configuration = dokkaConfiguration { modules = listOf( DokkaModuleDescriptionImpl( name = "module1", - relativePathToOutputDirectory = folder.root.resolve("module1"), + relativePathToOutputDirectory = outputDirectory.resolve("module1"), includes = emptySet(), - sourceOutputDirectory = folder.root.resolve("module1"), + sourceOutputDirectory = outputDirectory.resolve("module1"), ) ) - this.outputDir = folder.root + this.outputDir = outputDirectory } testFromData(configuration, useOutputLocationFromConfig = true){ @@ -108,4 +96,11 @@ class SubstitutionCommandResolutionTest : TemplatingAbstractTest() { } } } + + private fun createDirectoriesAndWriteContent(outputDirectory: File, content: String): File { + val module1 = outputDirectory.resolve("module1").also { it.mkdirs() } + val module1Content = module1.resolve("index.html") + module1Content.writeText(content) + return module1Content + } } |