-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some content tests for All Types and module pages
- Loading branch information
Showing
4 changed files
with
268 additions
and
6 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
plugins/base/src/test/kotlin/content/AllTypesPageTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters