From e6dead313d90eeaa17787235438dcbf0e9ba2a91 Mon Sep 17 00:00:00 2001 From: Declan Lynch Date: Sat, 21 Oct 2023 10:04:59 -0400 Subject: [PATCH] Added additional tests for the Dynamic PageView Model --- .../SoftwareSystemDynamicPageViewModelTest.kt | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModelTest.kt 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 new file mode 100644 index 00000000..ba69bc42 --- /dev/null +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModelTest.kt @@ -0,0 +1,63 @@ +package nl.avisi.structurizr.site.generatr.site.model + +import assertk.assertThat +import assertk.assertions.containsExactly +import assertk.assertions.isEqualTo +import assertk.assertions.isFalse +import com.structurizr.model.SoftwareSystem +import kotlin.test.Test + +class SoftwareSystemDynamicPageViewModelTest : ViewModelTest() { + private val generatorContext = generatorContext() + private val softwareSystem: SoftwareSystem = generatorContext.workspace.model + .addSoftwareSystem("Software system").also { + val backend = it.addContainer("Backend") + val frontend = it.addContainer("Frontend") + generatorContext.workspace.views.createDynamicView(backend, "backend-dynamic", "Dynamic view 1") + generatorContext.workspace.views.createDynamicView(frontend, "frontend-dynamic", "Dynamic view 2") + } + + @Test + fun `active tab`() { + val viewModel = SoftwareSystemDynamicPageViewModel(generatorContext, softwareSystem) + + assertThat(viewModel.tabs.single { it.link.active }.tab) + .isEqualTo(SoftwareSystemPageViewModel.Tab.DYNAMIC) + } + + @Test + fun `diagrams sorted by key`() { + val viewModel = SoftwareSystemDynamicPageViewModel(generatorContext, softwareSystem) + + assertThat(viewModel.diagrams).containsExactly( + DiagramViewModel( + "backend-dynamic", + "Backend - Dynamic", + """""", + 800, + ImageViewModel(viewModel, "/svg/backend-dynamic.svg"), + ImageViewModel(viewModel, "/png/backend-dynamic.png"), + ImageViewModel(viewModel, "/puml/backend-dynamic.puml") + ), + DiagramViewModel( + "frontend-dynamic", + "Frontend - Dynamic", + """""", + 800, + ImageViewModel(viewModel, "/svg/frontend-dynamic.svg"), + ImageViewModel(viewModel, "/png/frontend-dynamic.png"), + ImageViewModel(viewModel, "/puml/frontend-dynamic.puml") + ) + ) + } + + @Test + fun `hidden view`() { + val viewModel = SoftwareSystemDynamicPageViewModel( + generatorContext, + generatorContext.workspace.model.addSoftwareSystem("Software system 2") + ) + + assertThat(viewModel.visible).isFalse() + } +}