Skip to content

Commit

Permalink
Added additional tests for the Dynamic PageView Model
Browse files Browse the repository at this point in the history
  • Loading branch information
qtzar committed Oct 21, 2023
1 parent 906706b commit e6dead3
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
ImageViewModel(viewModel, "/svg/backend-dynamic.svg"),
ImageViewModel(viewModel, "/png/backend-dynamic.png"),
ImageViewModel(viewModel, "/puml/backend-dynamic.puml")
),
DiagramViewModel(
"frontend-dynamic",
"Frontend - Dynamic",
"""<svg viewBox="0 0 800 900"></svg>""",
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()
}
}

0 comments on commit e6dead3

Please sign in to comment.