diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2022-07-29 14:32:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-29 14:32:24 +0200 |
commit | 7a875ee7d20b67725debd4c2c9e1f93e1889c302 (patch) | |
tree | 075210f83e5e5a7679194ba8c88dc426dead0777 /plugins/base/src/test | |
parent | 26dde5b201b3c7e66212b07ddef333a3e340022a (diff) | |
download | dokka-7a875ee7d20b67725debd4c2c9e1f93e1889c302.tar.gz dokka-7a875ee7d20b67725debd4c2c9e1f93e1889c302.tar.bz2 dokka-7a875ee7d20b67725debd4c2c9e1f93e1889c302.zip |
Add member icons to navigation menu (#2578)
Diffstat (limited to 'plugins/base/src/test')
4 files changed, 343 insertions, 474 deletions
diff --git a/plugins/base/src/test/kotlin/enums/JavaEnumTest.kt b/plugins/base/src/test/kotlin/enums/JavaEnumTest.kt deleted file mode 100644 index 369fbe79..00000000 --- a/plugins/base/src/test/kotlin/enums/JavaEnumTest.kt +++ /dev/null @@ -1,66 +0,0 @@ -package enums - -import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest -import org.jetbrains.dokka.model.DEnum -import org.jetbrains.dokka.model.ObviousMember -import org.junit.jupiter.api.Test -import utils.TestOutputWriterPlugin -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -class JavaEnumTest : BaseAbstractTest() { - - private val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - @Test - fun `should mark synthetic functions generated for Kotlin as obvious`() { - val writerPlugin = TestOutputWriterPlugin() - testInline( - """ - |/src/main/java/basic/JavaEnum.java - |package testpackage - | - |public enum JavaEnum { - | ONE, TWO - |} - """.trimMargin(), - configuration, - pluginOverrides = listOf(writerPlugin) - ) { - documentablesCreationStage = { modules -> - val pckg = modules.flatMap { it.packages }.single { it.packageName == "testpackage" } - val enum = pckg.children.single { it is DEnum } as DEnum - - // there's two with the same name, one inherited from - // java.lang.Enum and one is synthetic for Kotlin interop - enum.functions.filter { it.name == "valueOf" }.let { valueOfMethods -> - assertEquals(2, valueOfMethods.size) - - val valueOfFromKotlin = valueOfMethods[0] - assertEquals( - "testpackage/JavaEnum/valueOf/#java.lang.String/PointingToDeclaration/", - valueOfFromKotlin.dri.toString() - ) - assertNotNull(valueOfFromKotlin.extra[ObviousMember]) - - val valueOfFromJava = valueOfMethods[1] - assertEquals( - "java.lang/Enum/valueOf/#java.lang.Class<T>#java.lang.String/PointingToDeclaration/", - valueOfFromJava.dri.toString() - ) - assertNotNull(valueOfFromJava.extra[ObviousMember]) - } - - val valuesMethod = enum.functions.single { it.name == "values" } - assertEquals("testpackage/JavaEnum/values/#/PointingToDeclaration/", valuesMethod.dri.toString()) - assertNotNull(valuesMethod.extra[ObviousMember]) - } - } - } -} diff --git a/plugins/base/src/test/kotlin/enums/JavaEnumsTest.kt b/plugins/base/src/test/kotlin/enums/JavaEnumsTest.kt index 6a59a57e..939163ca 100644 --- a/plugins/base/src/test/kotlin/enums/JavaEnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/JavaEnumsTest.kt @@ -2,14 +2,25 @@ package enums import org.jetbrains.dokka.SourceLinkDefinitionImpl import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.DEnum +import org.jetbrains.dokka.model.ObviousMember import org.junit.jupiter.api.Test import signatures.renderedContent import utils.TestOutputWriterPlugin import java.net.URL import kotlin.test.assertEquals +import kotlin.test.assertNotNull class JavaEnumsTest : BaseAbstractTest() { + private val basicConfiguration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + // Shouldn't try to give source links to synthetic methods (values, valueOf) if any are present // https://github.com/Kotlin/dokka/issues/2544 @Test @@ -57,4 +68,50 @@ class JavaEnumsTest : BaseAbstractTest() { } } } + + @Test + fun `should mark synthetic functions generated for Kotlin as obvious`() { + val writerPlugin = TestOutputWriterPlugin() + testInline( + """ + |/src/main/java/basic/JavaEnum.java + |package testpackage + | + |public enum JavaEnum { + | ONE, TWO + |} + """.trimMargin(), + basicConfiguration, + pluginOverrides = listOf(writerPlugin) + ) { + documentablesCreationStage = { modules -> + val pckg = modules.flatMap { it.packages }.single { it.packageName == "testpackage" } + val enum = pckg.children.single { it is DEnum } as DEnum + + // there's two with the same name, one inherited from + // java.lang.Enum and one is synthetic for Kotlin interop + enum.functions.filter { it.name == "valueOf" }.let { valueOfMethods -> + assertEquals(2, valueOfMethods.size) + + val valueOfFromKotlin = valueOfMethods[0] + assertEquals( + "testpackage/JavaEnum/valueOf/#java.lang.String/PointingToDeclaration/", + valueOfFromKotlin.dri.toString() + ) + assertNotNull(valueOfFromKotlin.extra[ObviousMember]) + + val valueOfFromJava = valueOfMethods[1] + assertEquals( + "java.lang/Enum/valueOf/#java.lang.Class<T>#java.lang.String/PointingToDeclaration/", + valueOfFromJava.dri.toString() + ) + assertNotNull(valueOfFromJava.extra[ObviousMember]) + } + + val valuesMethod = enum.functions.single { it.name == "values" } + assertEquals("testpackage/JavaEnum/values/#/PointingToDeclaration/", valuesMethod.dri.toString()) + assertNotNull(valuesMethod.extra[ObviousMember]) + } + } + } } diff --git a/plugins/base/src/test/kotlin/enums/KotlinEnumTest.kt b/plugins/base/src/test/kotlin/enums/KotlinEnumTest.kt deleted file mode 100644 index 83430869..00000000 --- a/plugins/base/src/test/kotlin/enums/KotlinEnumTest.kt +++ /dev/null @@ -1,408 +0,0 @@ -package enums - -import matchers.content.* -import org.jetbrains.dokka.pages.* -import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest -import org.jetbrains.dokka.model.* -import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance -import org.jsoup.Jsoup -import org.jsoup.nodes.Element -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test -import signatures.renderedContent -import utils.TestOutputWriter -import utils.TestOutputWriterPlugin - -class KotlinEnumTest : BaseAbstractTest() { - - @Test - fun `should preserve enum source ordering for documentables`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - val writerPlugin = TestOutputWriterPlugin() - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package testpackage - | - |enum class TestEnum { - | ZERO, - | ONE, - | TWO, - | THREE, - | FOUR, - | FIVE, - | SIX, - | SEVEN, - | EIGHT, - | NINE - |} - """.trimMargin(), - configuration, - pluginOverrides = listOf(writerPlugin) - ) { - documentablesTransformationStage = { module -> - val testPackage = module.packages[0] - assertEquals("testpackage", testPackage.name) - - val testEnum = testPackage.classlikes[0] as DEnum - assertEquals("TestEnum", testEnum.name) - - val enumEntries = testEnum.entries - assertEquals(10, enumEntries.count()) - - assertEquals("ZERO", enumEntries[0].name) - assertEquals("ONE", enumEntries[1].name) - assertEquals("TWO", enumEntries[2].name) - assertEquals("THREE", enumEntries[3].name) - assertEquals("FOUR", enumEntries[4].name) - assertEquals("FIVE", enumEntries[5].name) - assertEquals("SIX", enumEntries[6].name) - assertEquals("SEVEN", enumEntries[7].name) - assertEquals("EIGHT", enumEntries[8].name) - assertEquals("NINE", enumEntries[9].name) - } - } - } - - @Test - fun `should preserve enum source ordering for generated pages`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - val writerPlugin = TestOutputWriterPlugin() - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package testpackage - | - |enum class TestEnum { - | ZERO, - | ONE, - | TWO, - | THREE, - | FOUR, - | FIVE, - | SIX, - | SEVEN, - | EIGHT, - | NINE - |} - """.trimMargin(), - configuration, - pluginOverrides = listOf(writerPlugin) - ) { - pagesGenerationStage = { rootPage -> - val packagePage = rootPage.children[0] - assertEquals("testpackage", packagePage.name) - - val testEnumNode = packagePage.children[0] - assertEquals("TestEnum", testEnumNode.name) - - val enumEntries = testEnumNode.children - assertEquals(10, enumEntries.size) - - assertEquals("ZERO", enumEntries[0].name) - assertEquals("ONE", enumEntries[1].name) - assertEquals("TWO", enumEntries[2].name) - assertEquals("THREE", enumEntries[3].name) - assertEquals("FOUR", enumEntries[4].name) - assertEquals("FIVE", enumEntries[5].name) - assertEquals("SIX", enumEntries[6].name) - assertEquals("SEVEN", enumEntries[7].name) - assertEquals("EIGHT", enumEntries[8].name) - assertEquals("NINE", enumEntries[9].name) - } - } - } - - @Test - fun `should preserve enum source ordering for rendered entries`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - val writerPlugin = TestOutputWriterPlugin() - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package testpackage - | - |enum class TestEnum { - | ZERO, - | ONE, - | TWO, - | THREE, - | FOUR, - | FIVE, - | SIX, - | SEVEN, - | EIGHT, - | NINE - |} - """.trimMargin(), - configuration, - pluginOverrides = listOf(writerPlugin) - ) { - renderingStage = { _, _ -> - val enumEntriesOnPage = writerPlugin.writer.renderedContent("root/testpackage/-test-enum/index.html") - .select("div.table[data-togglable=Entries]") - .select("div.table-row") - .select("div.keyValue") - .select("div.title") - .select("a") - - val enumEntries = enumEntriesOnPage.map { it.text() } - assertEquals(10, enumEntries.size) - - assertEquals("ZERO", enumEntries[0]) - assertEquals("ONE", enumEntries[1]) - assertEquals("TWO", enumEntries[2]) - assertEquals("THREE", enumEntries[3]) - assertEquals("FOUR", enumEntries[4]) - assertEquals("FIVE", enumEntries[5]) - assertEquals("SIX", enumEntries[6]) - assertEquals("SEVEN", enumEntries[7]) - assertEquals("EIGHT", enumEntries[8]) - assertEquals("NINE", enumEntries[9]) - } - } - } - - @Test - fun `should preserve enum source ordering for navigation menu`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - val writerPlugin = TestOutputWriterPlugin() - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package testpackage - | - |enum class TestEnum { - | ZERO, - | ONE, - | TWO, - | THREE, - | FOUR, - | FIVE, - | SIX, - | SEVEN, - | EIGHT, - | NINE - |} - """.trimMargin(), - configuration, - pluginOverrides = listOf(writerPlugin) - ) { - renderingStage = { _, _ -> - val sideMenu = writerPlugin.writer.navigationHtml().select("div.sideMenuPart") - - assertEquals("ZERO", sideMenu.select("#root-nav-submenu-0-0-0").text()) - assertEquals("ONE", sideMenu.select("#root-nav-submenu-0-0-1").text()) - assertEquals("TWO", sideMenu.select("#root-nav-submenu-0-0-2").text()) - assertEquals("THREE", sideMenu.select("#root-nav-submenu-0-0-3").text()) - assertEquals("FOUR", sideMenu.select("#root-nav-submenu-0-0-4").text()) - assertEquals("FIVE", sideMenu.select("#root-nav-submenu-0-0-5").text()) - assertEquals("SIX", sideMenu.select("#root-nav-submenu-0-0-6").text()) - assertEquals("SEVEN", sideMenu.select("#root-nav-submenu-0-0-7").text()) - assertEquals("EIGHT", sideMenu.select("#root-nav-submenu-0-0-8").text()) - assertEquals("NINE", sideMenu.select("#root-nav-submenu-0-0-9").text()) - } - } - } - - fun TestOutputWriter.navigationHtml(): Element = contents.getValue("navigation.html").let { Jsoup.parse(it) } - - @Test - fun `should handle companion object within enum`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package testpackage - | - |enum class TestEnum { - | E1, - | E2; - | companion object {} - |} - """.trimMargin(), - configuration - ) { - documentablesTransformationStage = { m -> - m.packages.let { p -> - assertTrue(p.isNotEmpty(), "Package list cannot be empty") - p.first().classlikes.let { c -> - assertTrue(c.isNotEmpty(), "Classlikes list cannot be empty") - - val enum = c.first() as DEnum - assertNotNull(enum.companion) - } - } - } - } - } - - - @Test - fun `should contain synthetic values and valueOf functions`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package testpackage - | - |enum class TestEnum { - | E1, - | E2; - |} - """.trimMargin(), - configuration - ) { - // stage is important because they will get filtered out later on - documentablesCreationStage = { modules -> - val pckg = modules.flatMap { it.packages }.single { it.packageName == "testpackage" } - val enum = pckg.children.single { it is DEnum } as DEnum - - val valueOf = enum.functions.single { it.name == "valueOf" } - assertEquals("testpackage/TestEnum/valueOf/#kotlin.String/PointingToDeclaration/", valueOf.dri.toString()) - assertNotNull(valueOf.extra[ObviousMember]) - - val values = enum.functions.single { it.name == "values" } - assertEquals("testpackage/TestEnum/values/#/PointingToDeclaration/", values.dri.toString()) - assertNotNull(values.extra[ObviousMember]) - } - } - } - - @Test - fun enumWithMethods() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/TestEnum.kt - |package testpackage - | - | - |interface Sample { - | fun toBeImplemented(): String - |} - | - |enum class TestEnum: Sample { - | E1 { - | override fun toBeImplemented(): String = "e1" - | } - |} - """.trimMargin(), - configuration - ) { - documentablesTransformationStage = { m -> - m.packages.let { p -> - p.first().classlikes.let { c -> - val enum = c.first { it is DEnum } as DEnum - val first = enum.entries.first() - - assertNotNull(first.functions.find { it.name == "toBeImplemented" }) - } - } - } - } - } - - @Test - fun enumWithAnnotationsOnEntries() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/TestEnum.kt - |package testpackage - | - |enum class TestEnum { - | /** - | Sample docs for E1 - | **/ - | @SinceKotlin("1.3") // This annotation is transparent due to lack of @MustBeDocumented annotation - | E1 - |} - """.trimMargin(), - configuration - ) { - pagesTransformationStage = { m -> - val entryNode = m.children.first { it.name == "testpackage" }.children.first { it.name == "TestEnum" }.children.firstIsInstance<ClasslikePageNode>() - val signature = (entryNode.content as ContentGroup).dfs { it is ContentGroup && it.dci.toString() == "[testpackage/TestEnum.E1///PointingToDeclaration/{\"org.jetbrains.dokka.links.EnumEntryDRIExtra\":{\"key\":\"org.jetbrains.dokka.links.EnumEntryDRIExtra\"}}][Cover]" } as ContentGroup - - signature.assertNode { - header(1) { +"E1" } - platformHinted { - group { - group { - link { +"E1" } - } - } - group { - group { - group { - +"Sample docs for E1" - } - } - } - } - } - } - } - } -} diff --git a/plugins/base/src/test/kotlin/renderers/html/NavigationIconTest.kt b/plugins/base/src/test/kotlin/renderers/html/NavigationIconTest.kt new file mode 100644 index 00000000..f2c1fca8 --- /dev/null +++ b/plugins/base/src/test/kotlin/renderers/html/NavigationIconTest.kt @@ -0,0 +1,286 @@ +package renderers.html + +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jsoup.Jsoup +import org.jsoup.nodes.Element +import org.jsoup.select.Elements +import org.junit.jupiter.api.Test +import utils.TestOutputWriter +import utils.TestOutputWriterPlugin +import kotlin.test.assertEquals + +class NavigationIconTest : BaseAbstractTest() { + + private val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + + @Test + fun `should include all navigation icons`() { + val source = """ + |/src/main/kotlin/com/example/Empty.kt + |package com.example + | + |class Empty {} + """ + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val navIconAssets = writerPlugin.writer.contents + .filterKeys { it.startsWith("images/nav-icons") } + .keys.sorted() + + assertEquals(15, navIconAssets.size) + assertEquals("images/nav-icons/abstract-class-kotlin.svg", navIconAssets[0]) + assertEquals("images/nav-icons/abstract-class.svg", navIconAssets[1]) + assertEquals("images/nav-icons/annotation-kotlin.svg", navIconAssets[2]) + assertEquals("images/nav-icons/annotation.svg", navIconAssets[3]) + assertEquals("images/nav-icons/class-kotlin.svg", navIconAssets[4]) + assertEquals("images/nav-icons/class.svg", navIconAssets[5]) + assertEquals("images/nav-icons/enum-kotlin.svg", navIconAssets[6]) + assertEquals("images/nav-icons/enum.svg", navIconAssets[7]) + assertEquals("images/nav-icons/exception-class.svg", navIconAssets[8]) + assertEquals("images/nav-icons/field-value.svg", navIconAssets[9]) + assertEquals("images/nav-icons/field-variable.svg", navIconAssets[10]) + assertEquals("images/nav-icons/function.svg", navIconAssets[11]) + assertEquals("images/nav-icons/interface-kotlin.svg", navIconAssets[12]) + assertEquals("images/nav-icons/interface.svg", navIconAssets[13]) + assertEquals("images/nav-icons/object.svg", navIconAssets[14]) + } + } + } + + @Test + fun `should add icon styles to kotlin class navigation item`() { + assertNavigationIcon( + source = kotlinSource("class Clazz {}"), + expectedIconClass = "class-kt", + expectedNavLinkText = "Clazz" + ) + } + + @Test + fun `should add icon styles to java class navigation item`() { + assertNavigationIcon( + source = javaSource( + className = "JavaClazz", + source = "public class JavaClazz {}" + ), + expectedIconClass = "class", + expectedNavLinkText = "JavaClazz" + ) + } + + @Test + fun `should add icon styles to kotlin abstract class navigation item`() { + assertNavigationIcon( + source = kotlinSource("abstract class AbstractClazz {}"), + expectedIconClass = "abstract-class-kt", + expectedNavLinkText = "AbstractClazz" + ) + } + + @Test + fun `should add icon styles to java abstract class navigation item`() { + assertNavigationIcon( + source = javaSource( + className = "AbstractJavaClazz", + source = "public abstract class AbstractJavaClazz {}" + ), + expectedIconClass = "abstract-class", + expectedNavLinkText = "AbstractJavaClazz" + ) + } + + @Test + fun `should add icon styles to kotlin enum navigation item`() { + assertNavigationIcon( + source = kotlinSource("enum class KotlinEnum {}"), + expectedIconClass = "enum-class-kt", + expectedNavLinkText = "KotlinEnum" + ) + } + + @Test + fun `should add icon styles to java enum class navigation item`() { + assertNavigationIcon( + source = javaSource( + className = "JavaEnum", + source = "public enum JavaEnum {}" + ), + expectedIconClass = "enum-class", + expectedNavLinkText = "JavaEnum" + ) + } + + @Test + fun `should add icon styles to kotlin annotation navigation item`() { + assertNavigationIcon( + source = kotlinSource("annotation class KotlinAnnotation"), + expectedIconClass = "annotation-class-kt", + expectedNavLinkText = "KotlinAnnotation" + ) + } + + @Test + fun `should add icon styles to java annotation navigation item`() { + assertNavigationIcon( + source = javaSource( + className = "JavaAnnotation", + source = "public @interface JavaAnnotation {}" + ), + expectedIconClass = "annotation-class", + expectedNavLinkText = "JavaAnnotation" + ) + } + + + @Test + fun `should add icon styles to kotlin interface navigation item`() { + assertNavigationIcon( + source = kotlinSource("interface KotlinInterface"), + expectedIconClass = "interface-kt", + expectedNavLinkText = "KotlinInterface" + ) + } + + @Test + fun `should add icon styles to java interface navigation item`() { + assertNavigationIcon( + source = javaSource( + className = "JavaInterface", + source = "public interface JavaInterface {}" + ), + expectedIconClass = "interface", + expectedNavLinkText = "JavaInterface" + ) + } + + @Test + fun `should add icon styles to kotlin function navigation item`() { + assertNavigationIcon( + source = kotlinSource("fun ktFunction() {}"), + expectedIconClass = "function", + expectedNavLinkText = "ktFunction()" + ) + } + + @Test + fun `should add icon styles to kotlin exception class navigation item`() { + assertNavigationIcon( + source = kotlinSource("class KotlinException : Exception() {}"), + expectedIconClass = "exception-class", + expectedNavLinkText = "KotlinException" + ) + } + + @Test + fun `should add icon styles to kotlin object navigation item`() { + assertNavigationIcon( + source = kotlinSource("object KotlinObject {}"), + expectedIconClass = "object", + expectedNavLinkText = "KotlinObject" + ) + } + + @Test + fun `should add icon styles to kotlin val navigation item`() { + assertNavigationIcon( + source = kotlinSource("val value: String? = null"), + expectedIconClass = "val", + expectedNavLinkText = "value" + ) + } + + @Test + fun `should add icon styles to kotlin var navigation item`() { + assertNavigationIcon( + source = kotlinSource("var variable: String? = null"), + expectedIconClass = "var", + expectedNavLinkText = "variable" + ) + } + + private fun kotlinSource(source: String): String { + return """ + |/src/main/kotlin/com/example/Example.kt + |package com.example + | + |$source + """.trimIndent() + } + + private fun javaSource(className: String, source: String): String { + return """ + |/src/main/java/com/example/$className.java + |package com.example; + | + |$source + """.trimIndent() + } + + private fun assertNavigationIcon(source: String, expectedIconClass: String, expectedNavLinkText: String) { + val writerPlugin = TestOutputWriterPlugin() + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val content = writerPlugin.writer.navigationHtml().select("div.sideMenuPart") + val navigationGrid = content.selectNavigationGrid() + + val classNames = navigationGrid.child(0).classNames().toList() + assertEquals("nav-link-child", classNames[0]) + assertEquals("nav-icon", classNames[1]) + assertEquals(expectedIconClass, classNames[2]) + + val navLinkText = navigationGrid.child(1).text() + assertEquals(expectedNavLinkText, navLinkText) + } + } + } + + @Test + fun `should not generate nav link grids or icons for packages and modules`() { + val writerPlugin = TestOutputWriterPlugin() + testInline( + """ + |/src/main/kotlin/com/example/Example.kt + |package com.example + | + |class Example {} + """.trimIndent(), + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val content = writerPlugin.writer.navigationHtml().select("div.sideMenuPart") + + assertEquals(3, content.size) + assertEquals("root-nav-submenu", content[0].id()) + assertEquals("root-nav-submenu-0", content[1].id()) + assertEquals("root-nav-submenu-0-0", content[2].id()) + + // there's 3 nav items, but only one icon + val navLinkGrids = content.select("span.nav-icon") + assertEquals(1, navLinkGrids.size) + } + } + } + + private fun TestOutputWriter.navigationHtml(): Element = contents.getValue("navigation.html").let { Jsoup.parse(it) } + + private fun Elements.selectNavigationGrid(): Element { + return this.select("div.overview").select("span.nav-link-grid").single() + } +} |