From 421b46579d4279aa5a7274cc0736abe83fdbdb85 Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Tue, 26 Nov 2024 11:58:44 +0100 Subject: [PATCH] feat: add diagram index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only show the index if there is more than one diagram/image. Co-authored-by: Kamil GaƂuszka --- .../site/model/DiagramIndexViewModel.kt | 7 +++++ .../generatr/site/model/DiagramViewModel.kt | 5 +++- ...stemContainerComponentCodePageViewModel.kt | 1 + ...eSystemContainerComponentsPageViewModel.kt | 2 ++ .../SoftwareSystemContainerPageViewModel.kt | 1 + .../SoftwareSystemContextPageViewModel.kt | 1 + .../SoftwareSystemDeploymentPageViewModel.kt | 1 + .../SoftwareSystemDynamicPageViewModel.kt | 1 + .../site/generatr/site/model/ToHtml.kt | 2 +- .../site/generatr/site/views/Diagram.kt | 2 +- .../site/generatr/site/views/DiagramIndex.kt | 28 +++++++++++++++++++ .../site/generatr/site/views/Image.kt | 3 +- ...oftwareSystemContainerComponentCodePage.kt | 1 + .../SoftwareSystemContainerComponentsPage.kt | 1 + .../site/views/SoftwareSystemContainerPage.kt | 1 + .../site/views/SoftwareSystemContextPage.kt | 5 ++-- .../views/SoftwareSystemDeploymentPage.kt | 5 ++-- .../site/views/SoftwareSystemDynamicPage.kt | 5 ++-- .../generatr/site/model/AsciidocToHtmlTest.kt | 2 +- .../generatr/site/model/MarkdownToHtmlTest.kt | 2 +- ...ContainerComponentCodePageViewModelTest.kt | 14 ++++++++++ ...temContainerComponentsPageViewModelTest.kt | 16 +++++++++++ ...oftwareSystemContainerPageViewModelTest.kt | 19 +++++++++++++ .../SoftwareSystemContextPageViewModelTest.kt | 18 ++++++++++++ ...ftwareSystemDeploymentPageViewModelTest.kt | 18 ++++++++++++ .../SoftwareSystemDynamicPageViewModelTest.kt | 19 +++++++++++++ .../site/generatr/site/model/ViewModelTest.kt | 2 +- 27 files changed, 166 insertions(+), 16 deletions(-) create mode 100644 src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramIndexViewModel.kt create mode 100644 src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/DiagramIndex.kt diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramIndexViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramIndexViewModel.kt new file mode 100644 index 00000000..c9bc464f --- /dev/null +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramIndexViewModel.kt @@ -0,0 +1,7 @@ +package nl.avisi.structurizr.site.generatr.site.model + +data class DiagramIndexViewModel( + val diagrams: List = emptyList(), + val images: List = emptyList()) { + val visible: Boolean = (diagrams.count() + images.count()) > 1 +} diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramViewModel.kt index b1b9ef91..9aae893e 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramViewModel.kt @@ -5,6 +5,7 @@ import com.structurizr.view.View data class DiagramViewModel( val key: String, val name: String, + val title: String?, val description: String?, val svg: String?, val diagramWidthInPixels: Int?, @@ -14,12 +15,13 @@ data class DiagramViewModel( ) { companion object { fun forView(pageViewModel: PageViewModel, view: View, svgFactory: (key: String, url: String) -> String?) = - forView(pageViewModel, view.key, view.name, view.description.ifBlank { null }, svgFactory) + forView(pageViewModel, view.key, view.name, view.title, view.description.ifBlank { null }, svgFactory) fun forView( pageViewModel: PageViewModel, key: String, name: String, + title: String?, description: String?, svgFactory: (key: String, url: String) -> String? ): DiagramViewModel { @@ -27,6 +29,7 @@ data class DiagramViewModel( return DiagramViewModel( key, name, + title, description, svg, extractDiagramWidthInPixels(svg), diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentCodePageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentCodePageViewModel.kt index 06b97e62..1faa92d0 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentCodePageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentCodePageViewModel.kt @@ -16,6 +16,7 @@ class SoftwareSystemContainerComponentCodePageViewModel(generatorContext: Genera val visible = images.isNotEmpty() val containerTabs = createContainersCodeTabViewModel(generatorContext, container.softwareSystem) val componentTabs = createComponentsTabViewModel(generatorContext, container) + val diagramIndex = DiagramIndexViewModel(images = images) companion object { fun url(container: Container, component: Component?) = "${url(container.softwareSystem, Tab.CODE)}/${container.name.normalize()}/${component?.name?.normalize()}" diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentsPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentsPageViewModel.kt index 1791783b..a7f61b44 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentsPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentsPageViewModel.kt @@ -21,6 +21,8 @@ class SoftwareSystemContainerComponentsPageViewModel(generatorContext: Generator val propertiesTable = createPropertiesTableViewModel(container.includedProperties) val visible = diagrams.isNotEmpty() or images.isNotEmpty() or hasProperties val containerTabs = createContainersComponentTabViewModel(generatorContext, container.softwareSystem) + val diagramIndex = DiagramIndexViewModel(diagrams, images) + companion object { fun url(container: Container) = "${url(container.softwareSystem, Tab.COMPONENT)}/${container.name.normalize()}" } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModel.kt index 2a8d03b4..8db18030 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModel.kt @@ -15,4 +15,5 @@ class SoftwareSystemContainerPageViewModel(generatorContext: GeneratorContext, s .sortedBy { it.key } .map { ImageViewViewModel(it) } val visible = generatorContext.workspace.views.hasContainerViews(generatorContext.workspace, softwareSystem) || images.isNotEmpty() + val diagramIndex = DiagramIndexViewModel(diagrams, images) } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContextPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContextPageViewModel.kt index 1b96e36d..f64a75cd 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContextPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContextPageViewModel.kt @@ -11,4 +11,5 @@ class SoftwareSystemContextPageViewModel(generatorContext: GeneratorContext, sof .sortedBy { it.key } .map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) } val visible = generatorContext.workspace.views.hasSystemContextViews(softwareSystem) + val diagramIndex = DiagramIndexViewModel(diagrams) } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDeploymentPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDeploymentPageViewModel.kt index e84dcb9b..6485f872 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDeploymentPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDeploymentPageViewModel.kt @@ -11,4 +11,5 @@ class SoftwareSystemDeploymentPageViewModel(generatorContext: GeneratorContext, .sortedBy { it.key } .map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) } val visible = generatorContext.workspace.views.hasDeploymentViews(softwareSystem) + val diagramIndex = DiagramIndexViewModel(diagrams) } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModel.kt index 8e9264ca..e3f209dd 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModel.kt @@ -11,4 +11,5 @@ class SoftwareSystemDynamicPageViewModel(generatorContext: GeneratorContext, sof .sortedBy { it.key } .map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) } val visible = generatorContext.workspace.views.hasDynamicViews(softwareSystem) + val diagramIndex = DiagramIndexViewModel(diagrams) } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ToHtml.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ToHtml.kt index 6379d09f..c4581c03 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ToHtml.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ToHtml.kt @@ -168,7 +168,7 @@ fun Element.transformEmbeddedDiagramElements( val key = it.attr("src").substring(embedPrefix.length) val name = it.attr("alt").ifBlank { key } val html = createHTML().div { - diagram(DiagramViewModel.forView(pageViewModel, key, name, null, svgFactory)) + diagram(DiagramViewModel.forView(pageViewModel, key, name, null, null, svgFactory)) } it.parent()?.append(html) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/Diagram.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/Diagram.kt index e380138a..9cfc7e2d 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/Diagram.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/Diagram.kt @@ -10,7 +10,7 @@ fun FlowContent.diagram(viewModel: DiagramViewModel) { figure { style = "width: min(100%, ${viewModel.diagramWidthInPixels}px);" - + attributes["id"] = viewModel.key rawHtml(viewModel.svg) figcaption { a { diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/DiagramIndex.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/DiagramIndex.kt new file mode 100644 index 00000000..f791d508 --- /dev/null +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/DiagramIndex.kt @@ -0,0 +1,28 @@ +package nl.avisi.structurizr.site.generatr.site.views + +import kotlinx.html.* +import nl.avisi.structurizr.site.generatr.site.model.DiagramIndexViewModel + +fun FlowContent.diagramIndex(viewModel: DiagramIndexViewModel) { + if(viewModel.visible) { + p(classes = "subtitle is-6") { + +"Index:" + } + ul { + viewModel.diagrams.forEach { + li { + a(href = "#${it.key}") { + +(it.title ?: it.name) + } + } + } + viewModel.images.forEach { + li { + a(href = "#${it.key}") { + +it.title + } + } + } + } + } +} diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/Image.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/Image.kt index b5578b21..b74f01ca 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/Image.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/Image.kt @@ -8,7 +8,8 @@ fun FlowContent.image(viewModel: ImageViewViewModel) { figure { style = "width: fit-content;" - + attributes["id"] = viewModel.key + p(classes = "has-text-weight-bold") { +viewModel.title } img { src = viewModel.content } figcaption { diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerComponentCodePage.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerComponentCodePage.kt index 6853bf3e..96c476c6 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerComponentCodePage.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerComponentCodePage.kt @@ -29,6 +29,7 @@ fun HTML.softwareSystemContainerComponentCodePage(viewModel: SoftwareSystemConta } } } + diagramIndex(viewModel.diagramIndex) viewModel.images.forEach { image(it) } } } else diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerComponentsPage.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerComponentsPage.kt index 39ebc18e..fed508ce 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerComponentsPage.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerComponentsPage.kt @@ -16,6 +16,7 @@ fun HTML.softwareSystemContainerComponentsPage(viewModel: SoftwareSystemContaine } } } + diagramIndex(viewModel.diagramIndex) viewModel.diagrams.forEach { diagram(it) } viewModel.images.forEach { image(it) } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerPage.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerPage.kt index 27d28664..550dfc2e 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerPage.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContainerPage.kt @@ -6,6 +6,7 @@ import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContainerPage fun HTML.softwareSystemContainerPage(viewModel: SoftwareSystemContainerPageViewModel) { if (viewModel.visible) softwareSystemPage(viewModel) { + diagramIndex(viewModel.diagramIndex) viewModel.diagrams.forEach { diagram(it) } viewModel.images.forEach { image(it) } } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContextPage.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContextPage.kt index 4eb62796..7be51f81 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContextPage.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemContextPage.kt @@ -6,9 +6,8 @@ import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContextPageVi fun HTML.softwareSystemContextPage(viewModel: SoftwareSystemContextPageViewModel) { if (viewModel.visible) softwareSystemPage(viewModel) { - viewModel.diagrams.forEach { - diagram(it) - } + diagramIndex(viewModel.diagramIndex) + viewModel.diagrams.forEach { diagram(it) } } else redirectUpPage() diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDeploymentPage.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDeploymentPage.kt index a1b41469..7636b0bd 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDeploymentPage.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDeploymentPage.kt @@ -6,9 +6,8 @@ import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemDeploymentPag fun HTML.softwareSystemDeploymentPage(viewModel: SoftwareSystemDeploymentPageViewModel) { if (viewModel.visible) softwareSystemPage(viewModel) { - viewModel.diagrams.forEach { - diagram(it) - } + diagramIndex(viewModel.diagramIndex) + viewModel.diagrams.forEach { diagram(it) } } else redirectUpPage() diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDynamicPage.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDynamicPage.kt index 588e4f73..b0a8f436 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDynamicPage.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDynamicPage.kt @@ -6,9 +6,8 @@ import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemDynamicPageVi fun HTML.softwareSystemDynamicPage(viewModel: SoftwareSystemDynamicPageViewModel) { if (viewModel.visible) softwareSystemPage(viewModel) { - viewModel.diagrams.forEach { - diagram(it) - } + diagramIndex(viewModel.diagramIndex) + viewModel.diagrams.forEach { diagram(it) } } else redirectUpPage() diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/AsciidocToHtmlTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/AsciidocToHtmlTest.kt index dcfd379f..ade72e6c 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/AsciidocToHtmlTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/AsciidocToHtmlTest.kt @@ -206,7 +206,7 @@ class AsciidocToHtmlTest : ViewModelTest() {
-
+
diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/MarkdownToHtmlTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/MarkdownToHtmlTest.kt index bc35cd4d..42a587a7 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/MarkdownToHtmlTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/MarkdownToHtmlTest.kt @@ -288,7 +288,7 @@ class MarkdownToHtmlTest : ViewModelTest() { """

-
+
diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentCodePageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentCodePageViewModelTest.kt index d02e96db..b48bdd88 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentCodePageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentCodePageViewModelTest.kt @@ -107,4 +107,18 @@ class SoftwareSystemContainerComponentCodePageViewModelTest : ViewModelTest() { assertThat(viewModel.visible).isFalse() } + + @Test + fun `no index`() { + val viewModel = SoftwareSystemContainerComponentCodePageViewModel(generatorContext, backendContainer, backendComponent) + assertThat(viewModel.diagramIndex.visible).isFalse() + } + + @Test + fun `index visible`() { + createImageView(generatorContext.workspace, backendComponent, "other-imageview") + val viewModel = SoftwareSystemContainerComponentCodePageViewModel(generatorContext, backendContainer, backendComponent) + + assertThat(viewModel.diagramIndex.visible).isTrue() + } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentsPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentsPageViewModelTest.kt index 4e3a6220..63eeb93c 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentsPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerComponentsPageViewModelTest.kt @@ -72,6 +72,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() { DiagramViewModel( "component-1-backend", "Software system - Backend - Components", + null, "Component view 1 - Backend", """""", 800, @@ -82,6 +83,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() { DiagramViewModel( "component-2-backend", "Software system - Backend - Components", + null, "Component view 2 - Backend", """""", 800, @@ -97,6 +99,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() { DiagramViewModel( "component-1-frontend", "Software system - Frontend - Components", + null, "Component view 1 - Frontend", """""", 800, @@ -107,6 +110,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() { DiagramViewModel( "component-2-frontend", "Software system - Frontend - Components", + null, "Component view 2 - Frontend", """""", 800, @@ -144,4 +148,16 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() { val viewModel = SoftwareSystemContainerComponentsPageViewModel(generatorContext, softwareSystem.addContainer("Container")) assertThat(viewModel.visible).isFalse() } + + @Test + fun `no index`() { + val viewModel = SoftwareSystemContainerComponentsPageViewModel(generatorContext, apiContainer) + assertThat(viewModel.diagramIndex.visible).isFalse() + } + + @Test + fun `has index`() { + val viewModel = SoftwareSystemContainerComponentsPageViewModel(generatorContext, backendContainer) + assertThat(viewModel.diagramIndex.visible).isTrue() + } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModelTest.kt index 6a00c416..e8eb25ee 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModelTest.kt @@ -35,6 +35,7 @@ class SoftwareSystemContainerPageViewModelTest : ViewModelTest() { DiagramViewModel( "container-1", "Software system - Containers", + null, "Container view 1", """""", 800, @@ -45,6 +46,7 @@ class SoftwareSystemContainerPageViewModelTest : ViewModelTest() { DiagramViewModel( "container-2", "Software system - Containers", + null, "Container view 2", """""", 800, @@ -73,4 +75,21 @@ class SoftwareSystemContainerPageViewModelTest : ViewModelTest() { assertThat(viewModel.visible).isFalse() } + + @Test + fun `no index`() { + val viewModel = SoftwareSystemContainerPageViewModel( + generatorContext, + generatorContext.workspace.model.addSoftwareSystem("Software system 2").also { + generatorContext.workspace.views.createContainerView(it, "container-3", "Container view 3") + } + ) + assertThat(viewModel.diagramIndex.visible).isFalse() + } + + @Test + fun `has index`() { + val viewModel = SoftwareSystemContainerPageViewModel(generatorContext, softwareSystem) + assertThat(viewModel.diagramIndex.visible).isTrue() + } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContextPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContextPageViewModelTest.kt index 894195dd..560dece4 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContextPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContextPageViewModelTest.kt @@ -3,6 +3,7 @@ package nl.avisi.structurizr.site.generatr.site.model import assertk.assertThat import assertk.assertions.containsExactly import assertk.assertions.isFalse +import assertk.assertions.isTrue import com.structurizr.model.SoftwareSystem import kotlin.test.Test @@ -22,6 +23,7 @@ class SoftwareSystemContextPageViewModelTest : ViewModelTest() { DiagramViewModel( "context-1", "Software system - System Context", + null, "System context view 1", """""", 800, @@ -32,6 +34,7 @@ class SoftwareSystemContextPageViewModelTest : ViewModelTest() { DiagramViewModel( "context-2", "Software system - System Context", + null, "System context view 2", """""", 800, @@ -51,4 +54,19 @@ class SoftwareSystemContextPageViewModelTest : ViewModelTest() { assertThat(viewModel.visible).isFalse() } + + @Test + fun `no index`() { + val viewModel = SoftwareSystemContextPageViewModel(generatorContext, generatorContext.workspace.model + .addSoftwareSystem("Software system 2").also { + generatorContext.workspace.views.createSystemContextView(it, "context-3", "System context view 3") + }) + assertThat(viewModel.diagramIndex.visible).isFalse() + } + + @Test + fun `has index`() { + val viewModel = SoftwareSystemContextPageViewModel(generatorContext, softwareSystem) + assertThat(viewModel.diagramIndex.visible).isTrue() + } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDeploymentPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDeploymentPageViewModelTest.kt index 2222e470..b9110a00 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDeploymentPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDeploymentPageViewModelTest.kt @@ -4,6 +4,7 @@ import assertk.assertThat import assertk.assertions.containsExactly import assertk.assertions.isEqualTo import assertk.assertions.isFalse +import assertk.assertions.isTrue import com.structurizr.model.SoftwareSystem import kotlin.test.Test @@ -31,6 +32,7 @@ class SoftwareSystemDeploymentPageViewModelTest : ViewModelTest() { DiagramViewModel( "deployment-1", "Software system - Deployment - Default", + null, "Deployment view 1", """""", 800, @@ -41,6 +43,7 @@ class SoftwareSystemDeploymentPageViewModelTest : ViewModelTest() { DiagramViewModel( "deployment-2", "Software system - Deployment - Default", + null, "Deployment view 2", """""", 800, @@ -60,4 +63,19 @@ class SoftwareSystemDeploymentPageViewModelTest : ViewModelTest() { assertThat(viewModel.visible).isFalse() } + + @Test + fun `no index`() { + val viewModel = SoftwareSystemDeploymentPageViewModel(generatorContext, generatorContext.workspace.model + .addSoftwareSystem("Software system 2").also { + generatorContext.workspace.views.createDeploymentView(it, "deployment-3", "Deployment view 3") + }) + assertThat(viewModel.diagramIndex.visible).isFalse() + } + + @Test + fun `has index`() { + val viewModel = SoftwareSystemDeploymentPageViewModel(generatorContext, softwareSystem) + assertThat(viewModel.diagramIndex.visible).isTrue() + } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModelTest.kt index a2bf6831..8a21313e 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModelTest.kt @@ -4,6 +4,7 @@ import assertk.assertThat import assertk.assertions.containsExactly import assertk.assertions.isEqualTo import assertk.assertions.isFalse +import assertk.assertions.isTrue import com.structurizr.model.SoftwareSystem import kotlin.test.Test @@ -33,6 +34,7 @@ class SoftwareSystemDynamicPageViewModelTest : ViewModelTest() { DiagramViewModel( "backend-dynamic", "Backend - Dynamic", + null, "Dynamic view 1", """""", 800, @@ -43,6 +45,7 @@ class SoftwareSystemDynamicPageViewModelTest : ViewModelTest() { DiagramViewModel( "frontend-dynamic", "Frontend - Dynamic", + null, "Dynamic view 2", """""", 800, @@ -62,4 +65,20 @@ class SoftwareSystemDynamicPageViewModelTest : ViewModelTest() { assertThat(viewModel.visible).isFalse() } + + @Test + fun `no index`() { + val viewModel = SoftwareSystemDynamicPageViewModel(generatorContext, generatorContext.workspace.model + .addSoftwareSystem("Software system 2").also { + val backend = it.addContainer("Api") + generatorContext.workspace.views.createDynamicView(backend, "api-dynamic", "Dynamic view 3") + }) + assertThat(viewModel.diagramIndex.visible).isFalse() + } + + @Test + fun `has index`() { + val viewModel = SoftwareSystemDynamicPageViewModel(generatorContext, softwareSystem) + assertThat(viewModel.diagramIndex.visible).isTrue() + } } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ViewModelTest.kt index d67b4765..063da6c3 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/ViewModelTest.kt @@ -41,7 +41,7 @@ abstract class ViewModelTest { protected fun createSection(content: String = "# Content") = Section(Format.Markdown, content) - protected fun createImageView(workspace: Workspace, element: Element): ImageView = workspace.views.createImageView(element, "imageview-${element.id}").also { + protected fun createImageView(workspace: Workspace, element: Element, key:String = "imageview-${element.id}"): ImageView = workspace.views.createImageView(element, key).also { it.description = "Image View Description" it.title = "Image View Title" it.contentType = "image/png"