aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/renderers/html/TabbedContentTest.kt
blob: 306925b35fd3443e1bae4cb0d4ef545d7d51fcbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package renderers.html

import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jsoup.nodes.Element
import org.junit.jupiter.api.Test
import signatures.renderedContent
import utils.TestOutputWriterPlugin
import kotlin.test.assertEquals

class TabbedContentTest : BaseAbstractTest() {

    private val configuration = dokkaConfiguration {
        sourceSets {
            sourceSet {
                sourceRoots = listOf("src/")
                classpath = listOf(commonStdlibPath!!)
                externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
            }
        }
    }

    private fun Element.getTabbedRow(type: String) = select(".table-row[data-togglable=$type]")
    private fun Element.getTabbedTable(type: String) = select("div[data-togglable=$type] .table")

    @Test
    fun `should have correct tabbed content type`() {
        val source = """
            |/src/main/kotlin/test/Test.kt
            |package example
            |
            |val p = 0
            |fun foo() = 0
            |
            | class A(val d: Int = 0) {
            |   class Success(): Result()
            |   class Failed(): Result()
            |   
            |   fun fn() = 0
            | }
            | 
            | fun A.fn() = 0
            | fun A.fn2() = 0
            | fun A.fn3() = 0
            | val A.p = 0
            | val A.p2 = 0
            """
        val writerPlugin = TestOutputWriterPlugin()

        testInline(
            source,
            configuration,
            pluginOverrides = listOf(writerPlugin)
        ) {
            renderingStage = { _, _ ->
                val classContent = writerPlugin.writer.renderedContent("root/example/-a/index.html")
                assertEquals(1, classContent.getTabbedTable("CONSTRUCTOR").size)
                assertEquals(1, classContent.getTabbedTable("PROPERTY").size)
                assertEquals(1, classContent.getTabbedTable("CONSTRUCTOR").size)
                assertEquals(1, classContent.getTabbedTable("FUNCTION").size)
                assertEquals(1, classContent.getTabbedTable("TYPE").size)
                assertEquals(3, classContent.getTabbedRow("EXTENSION_FUNCTION").size)
                assertEquals(2, classContent.getTabbedRow("EXTENSION_PROPERTY").size)

                val packagePage = writerPlugin.writer.renderedContent("root/example/index.html")
                assertEquals(1, packagePage.getTabbedTable("TYPE").size)
                assertEquals(1, packagePage.getTabbedTable("PROPERTY").size)
                assertEquals(1, packagePage.getTabbedTable("FUNCTION").size)
                assertEquals(3, packagePage.getTabbedRow("EXTENSION_FUNCTION").size)
                assertEquals(2, packagePage.getTabbedRow("EXTENSION_PROPERTY").size)
            }
        }
    }


    @Test
    fun `should have correct order of members and extensions`() {
        val source = """
            |/src/main/kotlin/test/Test.kt
            |package example
            |
            |val p = 0
            |fun foo() = 0
            |
            |class A(val d: Int = 0) {
            |   fun fn() = 0
            |   fun a() = 0
            |   fun g() = 0
            |}
            | 
            | fun A.fn() = 0
            """
        val writerPlugin = TestOutputWriterPlugin()

        testInline(
            source,
            configuration,
            pluginOverrides = listOf(writerPlugin)
        ) {
            renderingStage = { _, _ ->
                val classContent = writerPlugin.writer.renderedContent("root/example/-a/index.html")
                val funTable = classContent.select("div[data-togglable=FUNCTION] .table")
                val orders =
                    funTable.select(".table-row").map { it.attr("data-togglable") }
                assertEquals(listOf("", "", "EXTENSION_FUNCTION", ""), orders)
                val names =
                    funTable.select(".main-subrow .inline-flex a").map { it.text() }
                assertEquals(listOf("a", "fn", "fn", "g"), names)
            }
        }
    }
}