Skip to content

Commit 24fc432

Browse files
committed
test: add tests for KotlinPlaygroundSamples transformer and installers registration to extension points
1 parent 73c2585 commit 24fc432

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

dokka-subprojects/plugin-kotlin-playground-samples/src/test/kotlin/org/jetbrains/dokka/kotlinPlaygroundSamples/KotlinPlaygroundSamplesInstallerTest.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ package org.jetbrains.dokka.kotlinPlaygroundSamples
66

77
import org.jetbrains.dokka.DokkaConfiguration
88
import org.jetbrains.dokka.PluginConfigurationImpl
9+
import org.jetbrains.dokka.base.DokkaBase
910
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
11+
import org.jetbrains.dokka.plugability.plugin
12+
import org.jetbrains.dokka.plugability.query
1013
import utils.TestOutputWriterPlugin
1114
import kotlin.test.Test
1215
import kotlin.test.assertFalse
@@ -24,6 +27,38 @@ class KotlinPlaygroundSamplesInstallerTest : BaseAbstractTest() {
2427

2528
val writerPlugin = TestOutputWriterPlugin()
2629

30+
@Test
31+
fun `KotlinPlaygroundSamplesScriptsInstaller and KotlinPlaygroundSamplesStylesInstaller are applied`() {
32+
testInline(
33+
"""
34+
|/src/main/kotlin/Sample.kt
35+
|package com.example
36+
|
37+
|fun sampleFunction() {
38+
| println("This is a sample")
39+
|}
40+
|
41+
| /**
42+
| * @sample [com.example.sampleFunction]
43+
| */
44+
|class Foo
45+
""".trimMargin(),
46+
configuration = configuration
47+
) {
48+
pluginsSetupStage = { context ->
49+
val htmlPreprocessors = context.plugin<DokkaBase>().query { htmlPreprocessors }
50+
assertTrue(
51+
htmlPreprocessors.any { it is KotlinPlaygroundSamplesScriptsInstaller },
52+
"KotlinPlaygroundSamplesScriptsInstaller should be registered on htmlPreprocessors extension point"
53+
)
54+
assertTrue(
55+
htmlPreprocessors.any { it is KotlinPlaygroundSamplesStylesInstaller },
56+
"KotlinPlaygroundSamplesStylesInstaller should be registered on htmlPreprocessors extension point"
57+
)
58+
}
59+
}
60+
}
61+
2762
@Test
2863
fun `should not inject playground resources when no samples are used`() {
2964
testInline(

dokka-subprojects/plugin-kotlin-playground-samples/src/test/kotlin/org/jetbrains/dokka/kotlinPlaygroundSamples/KotlinPlaygroundSamplesTransformerTest.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
package org.jetbrains.dokka.kotlinPlaygroundSamples
66

7+
import org.jetbrains.dokka.CoreExtensions
78
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
89
import org.jetbrains.dokka.pages.*
910
import kotlin.test.Test
1011
import kotlin.test.assertEquals
12+
import kotlin.test.assertTrue
1113

1214
class KotlinPlaygroundSamplesTransformerTest : BaseAbstractTest() {
1315
private val configuration = dokkaConfiguration {
@@ -18,6 +20,34 @@ class KotlinPlaygroundSamplesTransformerTest : BaseAbstractTest() {
1820
}
1921
}
2022

23+
@Test
24+
fun `KotlinPlaygroundSamplesTransformer is applied`() {
25+
testInline(
26+
"""
27+
|/src/main/kotlin/Sample.kt
28+
|package com.example
29+
|
30+
|fun sampleFunction() {
31+
| println("This is a sample")
32+
|}
33+
|
34+
| /**
35+
| * @sample [com.example.sampleFunction]
36+
| */
37+
|class Foo
38+
""".trimMargin(),
39+
configuration = configuration
40+
) {
41+
pluginsSetupStage = { context ->
42+
val pageTransformers = context[CoreExtensions.pageTransformer]
43+
assertTrue(
44+
pageTransformers.any { it is KotlinPlaygroundSamplesTransformer },
45+
"KotlinPlaygroundSamplesTransformer should be registered on PageTransformer extension point"
46+
)
47+
}
48+
}
49+
}
50+
2151
@Test
2252
fun `1 sample test`() {
2353
testInline(
@@ -278,7 +308,10 @@ class KotlinPlaygroundSamplesTransformerTest : BaseAbstractTest() {
278308

279309
val kotlinPlaygroundSample = kotlinPlaygroundSamples[0]
280310
assertEquals("kotlin", kotlinPlaygroundSample.language)
281-
assertEquals(setOf<Style>(ContentStyle.RunnableSample, TextStyle.Monospace), kotlinPlaygroundSample.style)
311+
assertEquals(
312+
setOf<Style>(ContentStyle.RunnableSample, TextStyle.Monospace),
313+
kotlinPlaygroundSample.style
314+
)
282315

283316
val child = kotlinPlaygroundSample.children[0]
284317
if (child is ContentText) {

0 commit comments

Comments
 (0)