Skip to content

Commit

Permalink
Add some content tests for All Types and module pages
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed Oct 27, 2023
1 parent 0a62c38 commit d83bca7
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 6 deletions.
132 changes: 132 additions & 0 deletions plugins/base/src/test/kotlin/content/AllTypesPageTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package content

import matchers.content.*
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.pages.AllTypesPageNode
import org.jetbrains.dokka.pages.RootPageNode
import kotlin.test.Test
import kotlin.test.assertNotNull
import kotlin.test.assertNull

class AllTypesPageTest : BaseAbstractTest() {
private val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}

private fun RootPageNode.allTypesPageNode(): AllTypesPageNode? =
children.singleOrNull { it is AllTypesPageNode } as? AllTypesPageNode

@Test
fun `all types page generated when there are types`() {
testInline(
"""
|/src/Test.kt
|package sample
|/**
| * Hello World!
| *
| * Some other comment which should not be on All Types page
| */
|public class Test
|
|/**
| * Hello type
| */
|public typealias Alias = Int
""".trimIndent(),
configuration
) {
pagesTransformationStage = { rootPage ->
assertNotNull(rootPage.allTypesPageNode()).content.assertNode {
group {
header { +"root" } // module name
}
header { +"All Types" }
table {
group {
link { +"sample.Alias" }
group {
group {
+"Hello type"
}
}
}
group {
link { +"sample.Test" }
group {
group {
+"Hello World!"
}
}
}
}
}
}
}
}

@Test
fun `all types page isn't generated when there are NO types`() {
testInline(
"""
|/src/Test.kt
|package sample
|/**
| * Hello World!
| */
|public fun test() {}
""".trimIndent(),
configuration
) {
pagesTransformationStage = { rootPage ->
assertNull(rootPage.allTypesPageNode())
}
}
}

@Test
fun `all types sorting depends only on simple name`() {
testInline(
"""
|/src/A.kt
|package bbb
|public class A
|/src/B.kt
|package xxx
|public class B
|/src/C.kt
|package aaa
|public class C
""".trimIndent(),
configuration
) {
pagesTransformationStage = { rootPage ->
assertNotNull(rootPage.allTypesPageNode()).content.assertNode {
group {
header { +"root" } // module name
}
header { +"All Types" }
table {
group {
link { +"bbb.A" }
}
group {
link { +"xxx.B" }
}
group {
link { +"aaa.C" }
}
}
}
}
}
}
}
114 changes: 114 additions & 0 deletions plugins/base/src/test/kotlin/content/ModulePageTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package content

import matchers.content.*
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.pages.AllTypesPageNode
import org.jetbrains.dokka.pages.ContentDRILink
import org.jetbrains.dokka.pages.ModulePageNode
import kotlin.test.Test
import kotlin.test.assertEquals

class ModulePageTest : BaseAbstractTest() {
private val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}

@Test
fun `show packages content`() {
testInline(
"""
|/src/A.kt
|package bbb
|public class A
|/src/B.kt
|package xxx
|public class B
|/src/C.kt
|package aaa
|public class C
""".trimIndent(),
configuration
) {
pagesTransformationStage = { rootPage ->
(rootPage as ModulePageNode).content.assertNode {
group {
header { +"root" } // module name
}
header { +"Packages" }
table {
group {
link { +"aaa" }
}
group {
link { +"bbb" }
}
group {
link { +"xxx" }
}
}
header { +"Index" }
link { +"All Types" }
}
}
}
}

@Test
fun `show link to all types page when there are types`() {
testInline(
"""
|/src/Test.kt
|package sample
|public class Test
""".trimIndent(),
configuration
) {
pagesTransformationStage = { rootPage ->
(rootPage as ModulePageNode).content.assertNode {
group {
header { +"root" } // module name
}
header { +"Packages" }
table { skipAllNotMatching() }
header { +"Index" }
link {
+"All Types"
check {
assertEquals(AllTypesPageNode.DRI, (this as ContentDRILink).address)
}
}
}
}
}
}

@Test
fun `no link to all types page when there are no types`() {
testInline(
"""
|/src/Test.kt
|package sample
|public fun test() {}
""".trimIndent(),
configuration
) {
pagesTransformationStage = { rootPage ->
(rootPage as ModulePageNode).content.assertNode {
group {
header { +"root" } // module name
}
header { +"Packages" }
table { skipAllNotMatching() }
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SinceKotlinTest : AbstractRenderingTest() {
fun setSystemProperty() {
System.setProperty(SinceKotlinTransformer.SHOULD_DISPLAY_SINCE_KOTLIN_SYS_PROP, "true")
}

@AfterTest
fun clearSystemProperty() {
System.clearProperty(SinceKotlinTransformer.SHOULD_DISPLAY_SINCE_KOTLIN_SYS_PROP)
Expand Down Expand Up @@ -70,13 +71,21 @@ class SinceKotlinTest : AbstractRenderingTest() {
|typealias Str = String
|@SinceKotlin("1.5")
|val str = "str"
|@SinceKotlin("1.5")
|class A
""".trimIndent(),
testConfiguration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
println(writerPlugin.writer.contents.keys)
// 5 = 2 functions, 1 typealias, 1 property, 1 class
val content = writerPlugin.renderedContent("root/test/index.html")
assertEquals(4, content.getElementsContainingOwnText("Since Kotlin").count())
assertEquals(5, content.getElementsContainingOwnText("Since Kotlin").count())

// 2 = 1 typealias, 1 class
val allTypesContent = writerPlugin.renderedContent("root/-all -types.html")
assertEquals(2, allTypesContent.getElementsContainingOwnText("Since Kotlin").count())
}
}
}
Expand Down Expand Up @@ -105,7 +114,7 @@ class SinceKotlinTest : AbstractRenderingTest() {
Platform.jvm to SinceKotlinVersion("1.5"),
)

for(i in sinceKotlin) {
for (i in sinceKotlin) {
val tag =
find { it.sourceSets.first().analysisPlatform == i.key }?.documentation?.values?.first()
?.dfs { it is CustomTagWrapper && it.name == "Since Kotlin" }
Expand All @@ -119,7 +128,7 @@ class SinceKotlinTest : AbstractRenderingTest() {

@Test
fun `mpp fun without SinceKotlin annotation`() {
val configuration = dokkaConfiguration {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/jvm/")
Expand Down Expand Up @@ -193,7 +202,7 @@ class SinceKotlinTest : AbstractRenderingTest() {
Platform.wasm to SinceKotlinVersion("1.8"),
)

for(i in sinceKotlin) {
for (i in sinceKotlin) {
val tag =
find { it.sourceSets.first().analysisPlatform == i.key }?.documentation?.values?.first()
?.dfs { it is CustomTagWrapper && it.name == "Since Kotlin" }
Expand All @@ -207,7 +216,7 @@ class SinceKotlinTest : AbstractRenderingTest() {

@Test
fun `mpp fun with SinceKotlin annotation`() {
val configuration = dokkaConfiguration {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/jvm/")
Expand Down Expand Up @@ -294,7 +303,7 @@ class SinceKotlinTest : AbstractRenderingTest() {
Platform.wasm to SinceKotlinVersion("1.8"),
)

for(i in sinceKotlin) {
for (i in sinceKotlin) {
val tag =
find { it.sourceSets.first().analysisPlatform == i.key }?.documentation?.values?.first()
?.dfs { it is CustomTagWrapper && it.name == "Since Kotlin" }
Expand Down
7 changes: 7 additions & 0 deletions plugins/base/src/test/kotlin/renderers/html/NavigationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class NavigationTest : BaseAbstractTest() {
// - Sequence interface
// - Sequence()
// - sequence()
// - All Types (should be always in the end)

content[0].assertNavigationLink(
id = "root-nav-submenu",
Expand Down Expand Up @@ -94,6 +95,12 @@ class NavigationTest : BaseAbstractTest() {
address = "root/com.example/sequence.html",
icon = NavigationNodeIcon.FUNCTION
)

content[6].assertNavigationLink(
id = "root-nav-submenu-1",
text = "All Types",
address = "root/-all -types.html",
)
}
}
}
Expand Down

0 comments on commit d83bca7

Please sign in to comment.