1+ /*
2+ * Copyright 2026 znai maintainers
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org.testingisdocumenting.znai.diagrams.mermaid
18+
19+ import org.testingisdocumenting.znai.extensions.include.PluginsTestUtils
20+ import org.testingisdocumenting.znai.extensions.PluginParamsFactory
21+ import org.junit.Test
22+
23+ import static org.testingisdocumenting.znai.parser.TestComponentsRegistry.TEST_COMPONENTS_REGISTRY
24+ import static org.testingisdocumenting.webtau.Matchers.code
25+ import static org.testingisdocumenting.webtau.Matchers.throwException
26+
27+ class MermaidFencePluginTest {
28+ static PluginParamsFactory pluginParamsFactory = TEST_COMPONENTS_REGISTRY . pluginParamsFactory()
29+ @Test
30+ void " should process mermaid diagram without iconpacks parameter" () {
31+ def mermaidContent = ''' graph TD
32+ A[Start] --> B[Process]
33+ B --> C[End]'''
34+
35+ def elements = process(mermaidContent, [wide : true ])
36+
37+ elements. should == [
38+ mermaid : mermaidContent,
39+ wide : true ,
40+ ]
41+ }
42+
43+ @Test
44+ void " should process mermaid diagram with iconpacks parameter" () {
45+ def mermaidContent = ''' graph TD
46+ A[Start] --> B[Process]
47+ B --> C[End]'''
48+
49+ def elements = process(mermaidContent, [iconpacks : [[name : " test" , url : " /test-icons.json" ]]])
50+
51+ elements. should == [
52+ mermaid : mermaidContent,
53+ iconpacks : [[name : " test" , url : " /test-doc/test-icons.json" ]]]
54+ }
55+
56+ @Test
57+ void " should process simple mermaid diagram without any parameters" () {
58+ def mermaidContent = ''' graph TD
59+ A --> B'''
60+
61+ def elements = process(mermaidContent, Collections . emptyMap())
62+
63+ elements. should == [
64+ mermaid : mermaidContent
65+ ]
66+ }
67+
68+
69+ @Test
70+ void " should throw exception when iconpack missing name attribute" () {
71+ def mermaidContent = ''' graph TD
72+ A[Start] --> B[Process]
73+ B --> C[End]'''
74+
75+ code {
76+ process(mermaidContent, [iconpacks : [[url : " /test-icons.json" ]]])
77+ } should throwException(IllegalArgumentException . class, " iconpack name is missing" )
78+ }
79+
80+ @Test
81+ void " should throw exception when iconpack missing url attribute" () {
82+ def mermaidContent = ''' graph TD
83+ A[Start] --> B[Process]
84+ B --> C[End]'''
85+
86+ code {
87+ process(mermaidContent, [iconpacks : [[name : " test" ]]])
88+ } should throwException(IllegalArgumentException . class, " iconpack url is missing" )
89+ }
90+
91+ private static def process (String content , Map<String , ?> params ) {
92+ return PluginsTestUtils . processFenceAndGetProps(pluginParamsFactory. create(" mermaid" , " " , params), content)
93+ }
94+ }
0 commit comments