diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2020-08-19 15:42:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-19 15:42:29 +0200 |
commit | 6bd58a22b06c6e879b8e93ade631ca6f119976e3 (patch) | |
tree | 737ab304f41cc9efa64457acde4144aa7c852ffb /plugins/javadoc/src/test/kotlin/org | |
parent | 3100728f92e8d4ce828609d7447c3b486230218a (diff) | |
download | dokka-6bd58a22b06c6e879b8e93ade631ca6f119976e3.tar.gz dokka-6bd58a22b06c6e879b8e93ade631ca6f119976e3.tar.bz2 dokka-6bd58a22b06c6e879b8e93ade631ca6f119976e3.zip |
Index page for javadoc (#1244)
Diffstat (limited to 'plugins/javadoc/src/test/kotlin/org')
-rw-r--r-- | plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/JavadocIndexTest.kt | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/JavadocIndexTest.kt b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/JavadocIndexTest.kt new file mode 100644 index 00000000..9b2c4121 --- /dev/null +++ b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/JavadocIndexTest.kt @@ -0,0 +1,125 @@ +package org.jetbrains.dokka.javadoc + +import org.jetbrains.dokka.javadoc.pages.IndexPage +import org.jetbrains.dokka.javadoc.renderer.TemplateMap +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +internal class JavadocIndexTest : AbstractJavadocTemplateMapTest() { + + @Test + fun `generates correct number of index pages`() { + testIndexPages { indexPages -> + assertEquals(13, indexPages.size) + } + } + + @Test + fun `handles correct number of elements`() { + //We are checking whether we will have an additional function for enum classes + fun hasAdditionalFunction() = + AnnotationTarget.ANNOTATION_CLASS::class.java.methods.any { it.name == "describeConstable" } + + testIndexPages { indexPages -> + assertEquals(if (hasAdditionalFunction()) 41 else 40, indexPages.sumBy { it.elements.size }) + } + } + + @Test + fun `templateMap for class index`() { + testIndexPagesTemplateMaps { templateMaps -> + val element = (templateMaps[2]["elements"] as List<TemplateMap>)[1] + assertEquals("../package0/ClassA.html", element["address"]) + assertEquals("ClassA", element["name"]) + assertEquals("class", element["type"]) + assertEquals("Documentation for ClassA", element["description"]) + assertEquals("package0", element["origin"]) + + } + } + + @Test + fun `templateMap for enum entry index`() { + testIndexPagesTemplateMaps { templateMaps -> + val element = (templateMaps[0]["elements"] as List<TemplateMap>).last() + assertEquals("../package1/ClassCEnum.html#A", element["address"]) + assertEquals("A", element["name"]) + assertEquals("enum entry", element["type"]) + assertEquals(" ", element["description"]) + assertEquals("package1.<a href=../package1/ClassCEnum.html>ClassCEnum</a>", element["origin"]) + + } + } + + @Test + fun `templateMap for function index`() { + testIndexPagesTemplateMaps { templateMaps -> + val element = (templateMaps[0]["elements"] as List<TemplateMap>).first() + assertEquals("../package0/ClassA.html#a()", element["address"]) + assertEquals("a()", element["name"]) + assertEquals("function", element["type"]) + assertEquals(" ", element["description"]) + assertEquals("package0.<a href=../package0/ClassA.html>ClassA</a>", element["origin"]) + + } + } + + private val query = """ + /src/source0.kt + package package0 + /** + * Documentation for ClassA + */ + class ClassA { + fun a() {} + fun b() {} + fun c() {} + } + + /src/source1.kt + package package1 + /** + * Documentation for ClassB + */ + class ClassB { + fun d() {} + fun e() {} + fun f() {} + } + + /src/source2.kt + package package1 + /** + * Documentation for ClassB + */ + class ClassC { + fun g() {} + fun h() {} + fun j() {} + + class InnerClass { + fun k() {} + } + } + + /src/source3.kt + package package1 + /** + * Documentation for ClassCEnum + */ + enum class ClassCEnum { + A, D, E + } + """.trimIndent() + + private fun testIndexPages(operation: (List<IndexPage>) -> Unit) { + testTemplateMapInline(query) { + operation(allPagesOfType()) + } + } + + private fun testIndexPagesTemplateMaps(operation: (List<TemplateMap>) -> Unit) = + testTemplateMapInline(query) { + operation(allPagesOfType<IndexPage>().map { it.templateMap }) + } +}
\ No newline at end of file |