-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #642 from jenspav/diagrams-titles
Always use diagram and image titles and keep natural sorting
- Loading branch information
Showing
21 changed files
with
94 additions
and
50 deletions.
There are no files selected for viewing
13 changes: 11 additions & 2 deletions
13
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramIndexViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model | ||
|
||
data class IndexEntry(val key: String, val title: String) | ||
|
||
data class DiagramIndexViewModel( | ||
val diagrams: List<DiagramViewModel> = emptyList(), | ||
val images: List<ImageViewViewModel> = emptyList()) { | ||
private val diagrams: List<DiagramViewModel> = emptyList(), | ||
private val images: List<ImageViewViewModel> = emptyList()) { | ||
|
||
val entries = diagrams.map { IndexEntry(it.key, it.indexTitle()) } + | ||
images.map { IndexEntry(it.key, it.indexTitle()) } | ||
|
||
val visible: Boolean = (diagrams.count() + images.count()) > 1 | ||
|
||
private fun DiagramViewModel.indexTitle() = if (description.isNullOrBlank()) title else "$title ($description)" | ||
private fun ImageViewViewModel.indexTitle() = if (description.isNullOrBlank()) title else "$title ($description)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/DiagramIndexViewModelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import assertk.assertions.isFalse | ||
import assertk.assertions.isTrue | ||
import kotlin.test.Test | ||
|
||
class DiagramIndexViewModelTest : ViewModelTest() { | ||
private val generatorContext = generatorContext() | ||
|
||
@Test | ||
fun `index without diagrams` () { | ||
val viewModel = DiagramIndexViewModel(diagramViewModels()) | ||
|
||
assertThat(viewModel.entries).isEqualTo(listOf()) | ||
} | ||
|
||
@Test | ||
fun `index with diagram` () { | ||
val softwareSystem = generatorContext.workspace.model.addSoftwareSystem("Software system") | ||
generatorContext.workspace.views.createSystemContextView(softwareSystem, "system-1", "") | ||
val viewModel = DiagramIndexViewModel(diagramViewModels()) | ||
|
||
assertThat(viewModel.entries).isEqualTo(listOf(IndexEntry("system-1", "Software system - System Context"))) | ||
} | ||
|
||
@Test | ||
fun `index with diagram with description` () { | ||
val softwareSystem = generatorContext.workspace.model.addSoftwareSystem("Software system") | ||
generatorContext.workspace.views.createSystemContextView(softwareSystem, "system-1", "Some description") | ||
val viewModel = DiagramIndexViewModel(diagramViewModels()) | ||
|
||
assertThat(viewModel.entries).isEqualTo(listOf(IndexEntry("system-1", "Software system - System Context (Some description)"))) | ||
} | ||
|
||
@Test | ||
fun `index with exactly one diagram` () { | ||
val softwareSystem = generatorContext.workspace.model.addSoftwareSystem("Software system") | ||
generatorContext.workspace.views.createSystemContextView(softwareSystem, "system-1", "") | ||
val viewModel = DiagramIndexViewModel(diagramViewModels()) | ||
|
||
assertThat(viewModel.visible).isFalse() | ||
} | ||
|
||
@Test | ||
fun `index with diagram and image with description` () { | ||
val softwareSystem = generatorContext.workspace.model.addSoftwareSystem("Software system") | ||
generatorContext.workspace.views.createSystemContextView(softwareSystem, "system-1", "Some description") | ||
generatorContext.workspace.views.createImageView(softwareSystem, "image-1") | ||
val viewModel = DiagramIndexViewModel(diagramViewModels(), imageViewViewModels()) | ||
|
||
assertThat(viewModel.visible).isTrue() | ||
assertThat(viewModel.entries).isEqualTo(listOf( | ||
IndexEntry("system-1", "Software system - System Context (Some description)"), | ||
IndexEntry("imageview-2", "Image View Title (Image View Description)") | ||
)) | ||
} | ||
|
||
private fun diagramViewModels() = generatorContext.workspace.views.systemContextViews | ||
.map { DiagramViewModel.forView(this.pageViewModel(), it, generatorContext.svgFactory) } | ||
|
||
private fun imageViewViewModels() = listOf( | ||
ImageViewViewModel(createImageView(generatorContext.workspace, generatorContext.workspace.model.addSoftwareSystem("Software system2"))) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters