From c075c9570777d0946ba48ad88171379b52733416 Mon Sep 17 00:00:00 2001 From: Denis Ambatenne <75973078+d-ambatenne@users.noreply.github.com> Date: Thu, 6 Jul 2023 14:46:12 +0200 Subject: HTML: fix of redundant dot and related autotest (#2289) (#3057) * HTML: fix of redundant dot and related autotest (#2289) * Update plugins/base/src/test/kotlin/renderers/html/SearchbarDataInstallerTest.kt Change after the PR #3057 review Co-authored-by: Ignat Beresnev * Change after the PR #3057 review Co-authored-by: Ignat Beresnev --------- Co-authored-by: Denis Ambatenne Co-authored-by: Ignat Beresnev --- .../renderers/html/SearchbarDataInstaller.kt | 2 +- .../renderers/html/SearchbarDataInstallerTest.kt | 46 ++++++++++++++++++++++ plugins/base/src/test/kotlin/utils/HtmlUtils.kt | 5 +++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 plugins/base/src/test/kotlin/renderers/html/SearchbarDataInstallerTest.kt (limited to 'plugins') diff --git a/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt b/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt index b3d40ca0..20b412a7 100644 --- a/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt +++ b/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt @@ -30,7 +30,7 @@ open class SearchbarDataInstaller(val context: DokkaContext) : PageTransformer { val id: String get() = with(driWithSourceSets.dri) { listOfNotNull( - packageName, + packageName?.takeIf { it.isNotBlank() }, classNames, callable?.name ).joinToString(".") diff --git a/plugins/base/src/test/kotlin/renderers/html/SearchbarDataInstallerTest.kt b/plugins/base/src/test/kotlin/renderers/html/SearchbarDataInstallerTest.kt new file mode 100644 index 00000000..33f86e9f --- /dev/null +++ b/plugins/base/src/test/kotlin/renderers/html/SearchbarDataInstallerTest.kt @@ -0,0 +1,46 @@ +package renderers.html + +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.junit.Test +import org.junit.jupiter.api.Assertions +import utils.TestOutputWriterPlugin +import utils.pagesJson + +class SearchbarDataInstallerTest: BaseAbstractTest() { + + @Test // see #2289 + fun `should display description of root declarations without a leading dot`() { + val configuration = dokkaConfiguration { + moduleName = "Dokka Module" + + sourceSets { + sourceSet { + sourceRoots = listOf("src/kotlin/Test.kt") + } + } + } + + val source = """ + |/src/kotlin/Test.kt + | + |class Test + | + """.trimIndent() + + val writerPlugin = TestOutputWriterPlugin() + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val searchRecords = writerPlugin.writer.pagesJson() + + Assertions.assertEquals( + "Test", + searchRecords.find { record -> record.name == "class Test" }?.description ?: "" + ) + } + } + } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/utils/HtmlUtils.kt b/plugins/base/src/test/kotlin/utils/HtmlUtils.kt index bfba882a..0748d91a 100644 --- a/plugins/base/src/test/kotlin/utils/HtmlUtils.kt +++ b/plugins/base/src/test/kotlin/utils/HtmlUtils.kt @@ -1,11 +1,16 @@ package utils +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import org.jetbrains.dokka.base.renderers.html.SearchRecord import org.jsoup.Jsoup import org.jsoup.nodes.Element import org.jsoup.select.Elements internal fun TestOutputWriter.navigationHtml(): Element = contents.getValue("navigation.html").let { Jsoup.parse(it) } +internal fun TestOutputWriter.pagesJson(): List = jacksonObjectMapper().readValue(contents.getValue("scripts/pages.json")) + internal fun Elements.selectNavigationGrid(): Element { return this.select("div.overview").select("span.nav-link-grid").single() } -- cgit