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
|
package org.jetbrains.dokka.templates
import org.jetbrains.dokka.DokkaModuleDescriptionImpl
import org.jetbrains.dokka.base.renderers.html.SearchRecord
import org.jetbrains.dokka.base.templating.AddToSearch
import org.jetbrains.dokka.base.templating.parseJson
import org.jetbrains.dokka.base.templating.toJsonString
import org.junit.Rule
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import org.junit.rules.TemporaryFolder
import java.io.File
import kotlin.test.assertEquals
class AddToSearchCommandResolutionTest : TemplatingAbstractTest() {
companion object {
val elements = listOf(
SearchRecord(name = "name1", location = "location1"),
SearchRecord(name = "name2", location = "location2")
)
val fromModule1 = AddToSearch(
moduleName = "module1",
elements = elements
)
val fromModule2 = AddToSearch(
moduleName = "module2",
elements = elements
)
}
@get:Rule
val folder: TemporaryFolder = TemporaryFolder()
@ParameterizedTest
@ValueSource(strings = ["navigation-pane.json", "pages.json"])
fun `should merge navigation templates`(fileName: String) {
val (module1Navigation, module2Navigation) = setupTestDirectoriesWithContent(fileName)
val outputDir = folder.root
val configuration = dokkaConfiguration {
modules = listOf(
DokkaModuleDescriptionImpl(
name = "module1",
relativePathToOutputDirectory = folder.root.resolve("module1"),
includes = emptySet(),
sourceOutputDirectory = folder.root.resolve("module1"),
),
DokkaModuleDescriptionImpl(
name = "module2",
relativePathToOutputDirectory = folder.root.resolve("module2"),
includes = emptySet(),
sourceOutputDirectory = folder.root.resolve("module2"),
),
)
this.outputDir = outputDir
}
testFromData(configuration, preserveOutputLocation = true) {
submoduleProcessingStage = { _ ->
val expected = elements.map { it.copy(location = "module1/${it.location}") } +
elements.map { it.copy(location = "module2/${it.location}") }
val output =
parseJson<List<SearchRecord>>(outputDir.resolve("scripts/${fileName}").readText())
assertEquals(expected, output.sortedBy { it.location })
val outputFromModule1 = parseJson<List<SearchRecord>>(module1Navigation.readText())
assertEquals(expected, outputFromModule1.sortedBy { it.location })
val outputFromModule2 = parseJson<List<SearchRecord>>(module2Navigation.readText())
assertEquals(expected, outputFromModule2.sortedBy { it.location })
}
}
}
private fun setupTestDirectoriesWithContent(fileName: String): List<File> {
folder.create()
val scriptsForModule1 = folder.newFolder("module1", "scripts")
val scriptsForModule2 = folder.newFolder("module2", "scripts")
folder.newFolder("scripts")
val module1Navigation = scriptsForModule1.resolve(fileName)
module1Navigation.writeText(toJsonString(fromModule1))
val module2Navigation = scriptsForModule2.resolve(fileName)
module2Navigation.writeText(toJsonString(fromModule2))
return listOf(module1Navigation, module2Navigation)
}
}
|