From addf5db5382bc99caf842d543e0b417b5e997dd9 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 13 May 2020 01:30:37 +0200 Subject: Add tests for divergent content rendering --- .../test/kotlin/renderers/html/DivergentTest.kt | 330 +++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt (limited to 'plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt') diff --git a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt new file mode 100644 index 00000000..fc6d22ac --- /dev/null +++ b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt @@ -0,0 +1,330 @@ +package renderers.html + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.SourceRootImpl +import org.jetbrains.dokka.base.renderers.html.HtmlRenderer +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.pages.ContentDivergentGroup +import org.jetbrains.dokka.pages.TextStyle +import org.junit.jupiter.api.Test +import renderers.Div +import renderers.RenderingOnlyTestBase +import renderers.TestPage +import renderers.match + +class DivergentTest : RenderingOnlyTestBase() { + private val js = SourceSetData("root", "JS", Platform.js, listOf(SourceRootImpl("pl1"))) + private val jvm = SourceSetData("root", "JVM", Platform.jvm, listOf(SourceRootImpl("pl1"))) + private val native = SourceSetData("root", "NATIVE", Platform.native, listOf(SourceRootImpl("pl1"))) + + @Test + fun simpleWrappingCase() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("a") + } + } + } + } + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div("a"))) + } + + @Test + fun noPlatformHintCase() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test"), implicitlySourceSetHinted = false) { + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("a") + } + } + } + } + HtmlRenderer(context).render(page) + renderedContent.match("a") + } + + @Test + fun divergentBetweenSourceSets() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("a") + } + } + instance(setOf(DRI("test", "Test")), setOf(jvm)) { + divergent { + text("b") + } + } + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("c") + } + } + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div("a"), Div("b"), Div("c"))) + } + + @Test + fun divergentInOneSourceSet() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("a") + } + } + instance(setOf(DRI("test", "Test2")), setOf(js)) { + divergent { + text("b") + } + } + instance(setOf(DRI("test", "Test3")), setOf(js)) { + divergent { + text("c") + } + } + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div("abc"))) + } + + @Test + fun divergentInAndBetweenSourceSets() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("a") + } + } + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("b") + } + } + instance(setOf(DRI("test", "Test")), setOf(jvm)) { + divergent { + text("c") + } + } + instance(setOf(DRI("test", "Test2")), setOf(js)) { + divergent { + text("d") + } + } + instance(setOf(DRI("test", "Test3")), setOf(native)) { + divergent { + text("e") + } + } + } + } + + HtmlRenderer(context).render(page) + renderedContent.match(Div(Div("ae"), Div("bd"), Div("c"))) + } + + @Test + fun divergentInAndBetweenSourceSetsWithGrouping() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("a") + } + after { + text("a+") + } + } + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("b") + } + after { + text("bd+") + } + } + instance(setOf(DRI("test", "Test")), setOf(jvm)) { + divergent { + text("c") + } + } + instance(setOf(DRI("test", "Test2")), setOf(js)) { + divergent { + text("d") + } + after { + text("bd+") + } + } + instance(setOf(DRI("test", "Test3")), setOf(native)) { + divergent { + text("e") + } + after { + text("e+") + } + } + } + } + + HtmlRenderer(context).render(page) + renderedContent.match( + Div(Div("a")), + "a+", + Div(Div("bd")), + "bd+", + Div(Div("c")), + Div(Div("e")), + "e+" + ) + } + + @Test + fun divergentSameBefore() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + before { + text("ab-") + } + divergent { + text("a") + } + } + instance(setOf(DRI("test", "Test2")), setOf(native)) { + before { + text("ab-") + } + divergent { + text("b") + } + } + } + } + + HtmlRenderer(context).render(page) + renderedContent.match( + "ab-", + Div(Div("ab")) + ) + } + + @Test + fun divergentSameAfter() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("a") + } + after { + text("ab+") + } + } + instance(setOf(DRI("test", "Test2")), setOf(native)) { + divergent { + text("b") + } + after { + text("ab+") + } + } + } + } + + HtmlRenderer(context).render(page) + renderedContent.match( + Div(Div("ab")), + "ab+" + ) + } + + @Test + fun divergentGroupedByBeforeAndAfter() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + before { + text("ab-") + } + divergent { + text("a") + } + after { + text("ab+") + } + } + instance(setOf(DRI("test", "Test2")), setOf(native)) { + before { + text("ab-") + } + divergent { + text("b") + } + after { + text("ab+") + } + } + } + } + + HtmlRenderer(context).render(page) + renderedContent.match( + "ab-", + Div(Div("ab")), + "ab+" + ) + } + + @Test + fun divergentDifferentBeforeAndAfter() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + before { + text("a-") + } + divergent { + text("a") + } + after { + text("ab+") + } + } + instance(setOf(DRI("test", "Test2")), setOf(native)) { + before { + text("b-") + } + divergent { + text("b") + } + after { + text("ab+") + } + } + } + } + + HtmlRenderer(context).render(page) + renderedContent.match( + "a-", + Div(Div("a")), + "ab+b-", + Div(Div("b")), + "ab+" + ) + } +} \ No newline at end of file -- cgit From 5451627eb0cf8d95dafd23e96665e062ef023d75 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Mon, 18 May 2020 17:14:23 +0200 Subject: Add test utils for ContentDivergent and fix the tests --- .../documentables/DefaultPageCreator.kt | 1 - .../documentables/PageContentBuilder.kt | 33 +- .../kotlin/content/params/ContentForParamsTest.kt | 341 +++++++++++++-------- .../content/seealso/ContentForSeeAlsoTest.kt | 238 ++++++++------ .../test/kotlin/renderers/html/DivergentTest.kt | 28 +- plugins/base/src/test/kotlin/utils/contentUtils.kt | 68 ++-- .../kotlin/matchers/content/ContentMatchersDsl.kt | 17 +- 7 files changed, 446 insertions(+), 280 deletions(-) (limited to 'plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt') diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index b0687a06..4252de3b 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -207,7 +207,6 @@ open class DefaultPageCreator( } } } - } } diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index 2f04e2a0..9c80a9ea 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -212,14 +212,14 @@ open class PageContentBuilder( styles: Set