From 50a3323322265ff3b5dab1d861a25bbb1167812a Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 18 Aug 2022 19:33:53 +0200 Subject: Add deprecation details block (#2622) --- .../test/kotlin/renderers/html/NavigationTest.kt | 109 ++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) (limited to 'plugins/base/src/test/kotlin/renderers/html') diff --git a/plugins/base/src/test/kotlin/renderers/html/NavigationTest.kt b/plugins/base/src/test/kotlin/renderers/html/NavigationTest.kt index 104246cb..13a9e711 100644 --- a/plugins/base/src/test/kotlin/renderers/html/NavigationTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/NavigationTest.kt @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test import utils.TestOutputWriterPlugin import kotlin.test.assertEquals import utils.navigationHtml +import kotlin.test.assertNull class NavigationTest : BaseAbstractTest() { @@ -18,6 +19,106 @@ class NavigationTest : BaseAbstractTest() { } } + @Test + fun `should strike deprecated class link`() { + val writerPlugin = TestOutputWriterPlugin() + testInline( + """ + |/src/main/kotlin/com/example/SimpleDeprecatedClass.kt + |package com.example + | + |@Deprecated("reason") + |class SimpleDeprecatedClass {} + """.trimIndent(), + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val content = writerPlugin.writer.navigationHtml().select("div.sideMenuPart") + assertEquals(3, content.size) + + // Navigation menu should be the following: + // - root + // - com.example + // - SimpleDeprecatedClass + + content[0].assertNavigationLink( + id = "root-nav-submenu", + text = "root", + address = "index.html", + ) + + content[1].assertNavigationLink( + id = "root-nav-submenu-0", + text = "com.example", + address = "root/com.example/index.html", + ) + + content[2].assertNavigationLink( + id = "root-nav-submenu-0-0", + text = "SimpleDeprecatedClass", + address = "root/com.example/-simple-deprecated-class/index.html", + icon = NavigationNodeIcon.CLASS_KT, + isStrikethrough = true + ) + } + } + } + + @Test + fun `should not strike pages where only one of N documentables is deprecated`() { + val writerPlugin = TestOutputWriterPlugin() + testInline( + """ + |/src/main/kotlin/com/example/File.kt + |package com.example + | + |/** + | * First + | */ + |@Deprecated("reason") + |fun functionWithCommonName() + | + |/** + | * Second + | */ + |fun functionWithCommonName() + """.trimIndent(), + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val content = writerPlugin.writer.navigationHtml().select("div.sideMenuPart") + assertEquals(3, content.size) + + // Navigation menu should be the following: + // - root + // - com.example + // - functionWithCommonName + + content[0].assertNavigationLink( + id = "root-nav-submenu", + text = "root", + address = "index.html", + ) + + content[1].assertNavigationLink( + id = "root-nav-submenu-0", + text = "com.example", + address = "root/com.example/index.html", + ) + + content[2].assertNavigationLink( + id = "root-nav-submenu-0-0", + text = "functionWithCommonName()", + address = "root/com.example/function-with-common-name.html", + icon = NavigationNodeIcon.FUNCTION, + isStrikethrough = false + ) + } + } + } + @Test fun `should have expandable classlikes`() { val writerPlugin = TestOutputWriterPlugin() @@ -209,7 +310,7 @@ class NavigationTest : BaseAbstractTest() { } private fun Element.assertNavigationLink( - id: String, text: String, address: String, icon: NavigationNodeIcon? = null + id: String, text: String, address: String, icon: NavigationNodeIcon? = null, isStrikethrough: Boolean = false ) { assertEquals(id, this.id()) @@ -224,5 +325,11 @@ class NavigationTest : BaseAbstractTest() { assertEquals("nav-link-child", iconStyles[0]) assertEquals(icon.style(), "${iconStyles[1]} ${iconStyles[2]}") } + if (isStrikethrough) { + val textInsideStrikethrough = link.selectFirst("strike")?.text() + assertEquals(text, textInsideStrikethrough) + } else { + assertNull(link.selectFirst("strike")) + } } } -- cgit