From 04cf1cdd3a909fa62e5ffda5b7d04695c749177e Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Thu, 9 Jul 2020 10:45:06 +0200 Subject: Implement javadoc search --- .../javadoc/AbstractJavadocTemplateMapTest.kt | 7 ++- .../javadoc/search/JavadocIndexSearchTest.kt | 59 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 plugins/javadoc/src/test/kotlin/javadoc/search/JavadocIndexSearchTest.kt (limited to 'plugins/javadoc/src/test') diff --git a/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt index 7cd42942..f4f35ef0 100644 --- a/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt +++ b/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt @@ -8,6 +8,7 @@ import org.jetbrains.dokka.javadoc.JavadocPlugin import org.jetbrains.dokka.model.withDescendants import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest @@ -58,9 +59,10 @@ internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() { fun testTemplateMapInline( query: String, configuration: DokkaConfigurationImpl = config, + pluginsOverride: List = emptyList(), assertions: Result.() -> Unit ) { - testInline(query, configuration) { + testInline(query, configuration, pluginOverrides = pluginsOverride) { renderingStage = { rootPageNode, dokkaContext -> val transformedRootPageNode = preprocessors.fold(rootPageNode) { acc, pageTransformer -> pageTransformer(acc) @@ -75,6 +77,7 @@ internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() { kotlin: String? = null, java: String? = null, configuration: DokkaConfigurationImpl = config, + pluginsOverride: List = emptyList(), assertions: Result.() -> Unit ) { val kotlinException = kotlin?.let { @@ -82,6 +85,7 @@ internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() { testTemplateMapInline( query = kotlin, configuration = configuration, + pluginsOverride = pluginsOverride, assertions = assertions ) }.exceptionOrNull() @@ -92,6 +96,7 @@ internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() { testTemplateMapInline( query = java, configuration = configuration, + pluginsOverride = pluginsOverride, assertions = assertions ) }.exceptionOrNull() diff --git a/plugins/javadoc/src/test/kotlin/javadoc/search/JavadocIndexSearchTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/search/JavadocIndexSearchTest.kt new file mode 100644 index 00000000..6abed98d --- /dev/null +++ b/plugins/javadoc/src/test/kotlin/javadoc/search/JavadocIndexSearchTest.kt @@ -0,0 +1,59 @@ +package javadoc.search + +import javadoc.AbstractJavadocTemplateMapTest +import org.junit.jupiter.api.Test +import utils.TestOutputWriterPlugin +import org.junit.jupiter.api.Assertions.* + +internal class JavadocIndexSearchTest : AbstractJavadocTemplateMapTest() { + @Test + fun `javadoc index search tag`(){ + val writerPlugin = TestOutputWriterPlugin() + dualTestTemplateMapInline( + java = """ + /src/ClassA.java + package package0 + /** + * Documentation for ClassA + * Defines the implementation of the system Java compiler and its command line equivalent, {@index javac}, as well as javah. + */ + class ClassA { + + } + """, + pluginsOverride = listOf(writerPlugin) + ) { + val contents = writerPlugin.writer.contents + val expectedSearchTagJson = """var tagSearchIndex = [{"p":"package0","c":"ClassA","l":"javac","url":"package0/ClassA.html#javac"}]""" + assertEquals(expectedSearchTagJson, contents["tag-search-index.js"]) + } + } + + @Test + fun `javadoc type with member search`(){ + val writerPlugin = TestOutputWriterPlugin() + dualTestTemplateMapInline( + java = """ + /src/ClassA.java + package package0 + class ClassA { + public String propertyOfClassA = "Sample"; + + public void sampleFunction(){ + + } + } + """, + pluginsOverride = listOf(writerPlugin) + ) { + val contents = writerPlugin.writer.contents + val expectedPackageJson = """var packageSearchIndex = [{"l":"package0","url":"package0/package-summary.html"}, {"l":"All packages","url":"index.html"}]""" + val expectedClassesJson = """var typeSearchIndex = [{"p":"package0","l":"ClassA","url":"package0/ClassA.html"}, {"l":"All classes","url":"allclasses.html"}]""" + val expectedMembersJson = """var memberSearchIndex = [{"p":"package0","c":"ClassA","l":"sampleFunction()","url":"package0/ClassA.html#sampleFunction()"}, {"p":"package0","c":"ClassA","l":"propertyOfClassA","url":"package0/ClassA.html#propertyOfClassA"}]""" + + assertEquals(expectedPackageJson, contents["package-search-index.js"]) + assertEquals(expectedClassesJson, contents["type-search-index.js"]) + assertEquals(expectedMembersJson, contents["member-search-index.js"]) + } + } +} \ No newline at end of file -- cgit