collab/mermaid/cypress/integration/rendering/flowchart-elk.spec.jsblame
View source
6dd74de1import { imgSnapshotTest, renderGraph, verifyNumber } from '../../helpers/util.ts';
6dd74de2
6dd74de3describe('Flowchart ELK', () => {
6dd74de4 it('1-elk: should render a simple flowchart', () => {
6dd74de5 imgSnapshotTest(
6dd74de6 `flowchart-elk TD
6dd74de7 A[Christmas] -->|Get money| B(Go shopping)
6dd74de8 B --> C{Let me think}
6dd74de9 C -->|One| D[Laptop]
6dd74de10 C -->|Two| E[iPhone]
6dd74de11 C -->|Three| F[fa:fa-car Car]
6dd74de12 `,
6dd74de13 {}
6dd74de14 );
6dd74de15 imgSnapshotTest(
6dd74de16 `flowchart TD
6dd74de17 A[Christmas] -->|Get money| B(Go shopping)
6dd74de18 B --> C{Let me think}
6dd74de19 C -->|One| D[Laptop]
6dd74de20 C -->|Two| E[iPhone]
6dd74de21 C -->|Three| F[fa:fa-car Car]
6dd74de22 `,
6dd74de23 { flowchart: { defaultRenderer: 'elk' } }
6dd74de24 );
6dd74de25 });
6dd74de26
6dd74de27 it('2-elk: should render a simple flowchart with diagramPadding set to 0', () => {
6dd74de28 imgSnapshotTest(
6dd74de29 `flowchart-elk TD
6dd74de30 A[Christmas] -->|Get money| B(Go shopping)
6dd74de31 B --> C{Let me think}
6dd74de32 %% this is a comment
6dd74de33 C -->|One| D[Laptop]
6dd74de34 C -->|Two| E[iPhone]
6dd74de35 C -->|Three| F[fa:fa-car Car]
6dd74de36 `,
6dd74de37 { flowchart: { diagramPadding: 0 } }
6dd74de38 );
6dd74de39 });
6dd74de40
6dd74de41 it('3-elk: a link with correct arrowhead to a subgraph', () => {
6dd74de42 imgSnapshotTest(
6dd74de43 `flowchart-elk TD
6dd74de44 P1
6dd74de45 P1 -->P1.5
6dd74de46 subgraph P1.5
6dd74de47 P2
6dd74de48 P2.5(( A ))
6dd74de49 P3
6dd74de50 end
6dd74de51 P2 --> P4
6dd74de52 P3 --> P6
6dd74de53 P1.5 --> P5
6dd74de54 `,
6dd74de55 {}
6dd74de56 );
6dd74de57 });
6dd74de58
6dd74de59 it('4-elk: Length of edges', () => {
6dd74de60 imgSnapshotTest(
6dd74de61 `flowchart-elk TD
6dd74de62 L1 --- L2
6dd74de63 L2 --- C
6dd74de64 M1 ---> C
6dd74de65 R1 .-> R2
6dd74de66 R2 <.-> C
6dd74de67 C -->|Label 1| E1
6dd74de68 C <-- Label 2 ---> E2
6dd74de69 C ----> E3
6dd74de70 C <-...-> E4
6dd74de71 C ======> E5
6dd74de72 `,
6dd74de73 {}
6dd74de74 );
6dd74de75 });
6dd74de76 it('5-elk: should render escaped without html labels', () => {
6dd74de77 imgSnapshotTest(
6dd74de78 `flowchart-elk TD
6dd74de79 a["<strong>Haiya</strong>"]---->b
6dd74de80 `,
6dd74de81 { htmlLabels: false, flowchart: { htmlLabels: false } }
6dd74de82 );
6dd74de83 });
6dd74de84 it('6-elk: should render non-escaped with html labels', () => {
6dd74de85 imgSnapshotTest(
6dd74de86 `flowchart-elk TD
6dd74de87 a["<strong>Haiya</strong>"]===>b
6dd74de88 `,
6dd74de89 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de90 );
6dd74de91 });
6dd74de92 it('7-elk: should render a flowchart when useMaxWidth is true (default)', () => {
6dd74de93 renderGraph(
6dd74de94 `flowchart-elk TD
6dd74de95 A[Christmas] -->|Get money| B(Go shopping)
6dd74de96 B --> C{Let me think}
6dd74de97 C -->|One| D[Laptop]
6dd74de98 C -->|Two| E[iPhone]
6dd74de99 C -->|Three| F[fa:fa-car Car]
6dd74de100 `,
6dd74de101 { flowchart: { useMaxWidth: true } }
6dd74de102 );
6dd74de103 cy.get('svg').should((svg) => {
6dd74de104 expect(svg).to.have.attr('width', '100%');
6dd74de105 // expect(svg).to.have.attr('height');
6dd74de106 // use within because the absolute value can be slightly different depending on the environment ±5%
6dd74de107 // const height = parseFloat(svg.attr('height'));
6dd74de108 // expect(height).to.be.within(446 * 0.95, 446 * 1.05);
6dd74de109 const style = svg.attr('style');
6dd74de110 expect(style).to.match(/^max-width: [\d.]+px;$/);
6dd74de111 const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
6dd74de112 verifyNumber(maxWidthValue, 380, 15);
6dd74de113 });
6dd74de114 });
6dd74de115 it('8-elk: should render a flowchart when useMaxWidth is false', () => {
6dd74de116 renderGraph(
6dd74de117 `flowchart-elk TD
6dd74de118 A[Christmas] -->|Get money| B(Go shopping)
6dd74de119 B --> C{Let me think}
6dd74de120 C -->|One| D[Laptop]
6dd74de121 C -->|Two| E[iPhone]
6dd74de122 C -->|Three| F[fa:fa-car Car]
6dd74de123 `,
6dd74de124 { flowchart: { useMaxWidth: false } }
6dd74de125 );
6dd74de126 cy.get('svg').should((svg) => {
6dd74de127 // const height = parseFloat(svg.attr('height'));
6dd74de128 const width = parseFloat(svg.attr('width'));
6dd74de129 // use within because the absolute value can be slightly different depending on the environment ±5%
6dd74de130 // expect(height).to.be.within(446 * 0.95, 446 * 1.05);
6dd74de131 verifyNumber(width, 380, 15);
6dd74de132 expect(svg).to.not.have.attr('style');
6dd74de133 });
6dd74de134 });
6dd74de135
6dd74de136 it('V2 elk - 16: Render Stadium shape', () => {
6dd74de137 imgSnapshotTest(
6dd74de138 ` flowchart-elk TD
6dd74de139 A([stadium shape test])
6dd74de140 A -->|Get money| B([Go shopping])
6dd74de141 B --> C([Let me think...<br />Do I want something for work,<br />something to spend every free second with,<br />or something to get around?])
6dd74de142 C -->|One| D([Laptop])
6dd74de143 C -->|Two| E([iPhone])
6dd74de144 C -->|Three| F([Car<br/>wroom wroom])
6dd74de145 click A "index.html#link-clicked" "link test"
6dd74de146 click B testClick "click test"
6dd74de147 classDef someclass fill:#f96;
6dd74de148 class A someclass;
6dd74de149 class C someclass;
6dd74de150 `,
6dd74de151 { flowchart: { htmlLabels: false }, fontFamily: 'courier' }
6dd74de152 );
6dd74de153 });
6dd74de154
6dd74de155 it('50-elk: handle nested subgraphs in reverse order', () => {
6dd74de156 imgSnapshotTest(
6dd74de157 `flowchart-elk LR
6dd74de158 a -->b
6dd74de159 subgraph A
6dd74de160 B
6dd74de161 end
6dd74de162 subgraph B
6dd74de163 b
6dd74de164 end
6dd74de165 `,
6dd74de166 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de167 );
6dd74de168 });
6dd74de169
6dd74de170 it('51-elk: handle nested subgraphs in reverse order', () => {
6dd74de171 imgSnapshotTest(
6dd74de172 `flowchart-elk LR
6dd74de173 a -->b
6dd74de174 subgraph A
6dd74de175 B
6dd74de176 end
6dd74de177 subgraph B
6dd74de178 b
6dd74de179 end
6dd74de180 `,
6dd74de181 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de182 );
6dd74de183 });
6dd74de184
6dd74de185 it('52-elk: handle nested subgraphs in several levels', () => {
6dd74de186 imgSnapshotTest(
6dd74de187 `flowchart-elk TB
6dd74de188 b-->B
6dd74de189 a-->c
6dd74de190 subgraph O
6dd74de191 A
6dd74de192 end
6dd74de193 subgraph B
6dd74de194 c
6dd74de195 end
6dd74de196 subgraph A
6dd74de197 a
6dd74de198 b
6dd74de199 B
6dd74de200 end
6dd74de201 `,
6dd74de202 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de203 );
6dd74de204 });
6dd74de205
6dd74de206 it('53-elk: handle nested subgraphs with edges in and out', () => {
6dd74de207 imgSnapshotTest(
6dd74de208 `flowchart-elk TB
6dd74de209 internet
6dd74de210 nat
6dd74de211 router
6dd74de212 lb1
6dd74de213 lb2
6dd74de214 compute1
6dd74de215 compute2
6dd74de216 subgraph project
6dd74de217 router
6dd74de218 nat
6dd74de219 subgraph subnet1
6dd74de220 compute1
6dd74de221 lb1
6dd74de222 end
6dd74de223 subgraph subnet2
6dd74de224 compute2
6dd74de225 lb2
6dd74de226 end
6dd74de227 end
6dd74de228 internet --> router
6dd74de229 router --> subnet1 & subnet2
6dd74de230 subnet1 & subnet2 --> nat --> internet
6dd74de231 `,
6dd74de232 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de233 );
6dd74de234 });
6dd74de235
6dd74de236 it('54-elk: handle nested subgraphs with outgoing links', () => {
6dd74de237 imgSnapshotTest(
6dd74de238 `flowchart-elk TD
6dd74de239 subgraph main
6dd74de240 subgraph subcontainer
6dd74de241 subcontainer-child
6dd74de242 end
6dd74de243 subcontainer-child--> subcontainer-sibling
6dd74de244 end
6dd74de245 `,
6dd74de246 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de247 );
6dd74de248 });
6dd74de249
6dd74de250 it('55-elk: handle nested subgraphs with outgoing links 2', () => {
6dd74de251 imgSnapshotTest(
6dd74de252 `flowchart-elk TD
6dd74de253
6dd74de254subgraph one[One]
6dd74de255 subgraph sub_one[Sub One]
6dd74de256 _sub_one
6dd74de257 end
6dd74de258 subgraph sub_two[Sub Two]
6dd74de259 _sub_two
6dd74de260 end
6dd74de261 _one
6dd74de262end
6dd74de263
6dd74de264%% here, either the first or the second one
6dd74de265sub_one --> sub_two
6dd74de266_one --> b
6dd74de267 `,
6dd74de268 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de269 );
6dd74de270 });
6dd74de271
6dd74de272 it('56-elk: handle nested subgraphs with outgoing links 3', () => {
6dd74de273 imgSnapshotTest(
6dd74de274 `flowchart-elk TB
6dd74de275 subgraph container_Beta
6dd74de276 process_C-->Process_D
6dd74de277 end
6dd74de278 subgraph container_Alpha
6dd74de279 process_A-->process_B
6dd74de280 process_A-->|messages|process_C
6dd74de281 end
6dd74de282 process_B-->|via_AWSBatch|container_Beta
6dd74de283 `,
6dd74de284 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de285 );
6dd74de286 });
6dd74de287 it('57-elk: handle nested subgraphs with outgoing links 4', () => {
6dd74de288 imgSnapshotTest(
6dd74de289 `flowchart-elk LR
6dd74de290subgraph A
6dd74de291a -->b
6dd74de292end
6dd74de293subgraph B
6dd74de294b
6dd74de295end
6dd74de296 `,
6dd74de297 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de298 );
6dd74de299 });
6dd74de300
6dd74de301 it('57-elk: handle nested subgraphs with outgoing links 2', () => {
6dd74de302 imgSnapshotTest(
6dd74de303 `flowchart-elk TB
6dd74de304 c1-->a2
6dd74de305 subgraph one
6dd74de306 a1-->a2
6dd74de307 end
6dd74de308 subgraph two
6dd74de309 b1-->b2
6dd74de310 end
6dd74de311 subgraph three
6dd74de312 c1-->c2
6dd74de313 end
6dd74de314 one --> two
6dd74de315 three --> two
6dd74de316 two --> c2
6dd74de317 `,
6dd74de318 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de319 );
6dd74de320 });
6dd74de321 it('57.x: handle nested subgraphs with outgoing links 5', () => {
6dd74de322 imgSnapshotTest(
6dd74de323 `%% this does not produce the desired result
6dd74de324flowchart-elk TB
6dd74de325 subgraph container_Beta
6dd74de326 process_C-->Process_D
6dd74de327 end
6dd74de328 subgraph container_Alpha
6dd74de329 process_A-->process_B
6dd74de330 process_B-->|via_AWSBatch|container_Beta
6dd74de331 process_A-->|messages|process_C
6dd74de332 end
6dd74de333 `,
6dd74de334 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de335 );
6dd74de336 });
6dd74de337 it('58-elk: handle styling with style expressions', () => {
6dd74de338 imgSnapshotTest(
6dd74de339 `
6dd74de340 flowchart-elk LR
6dd74de341 id1(Start)-->id2(Stop)
6dd74de342 style id1 fill:#f9f,stroke:#333,stroke-width:4px
6dd74de343 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de344 `,
6dd74de345 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de346 );
6dd74de347 });
6dd74de348 it('59-elk: handle styling of subgraphs and links', () => {
6dd74de349 imgSnapshotTest(
6dd74de350 `
6dd74de351flowchart-elk TD
6dd74de352 A[Christmas] ==> D
6dd74de353 A[Christmas] -->|Get money| B(Go shopping)
6dd74de354 A[Christmas] ==> C
6dd74de355 subgraph T ["Test"]
6dd74de356 A
6dd74de357 B
6dd74de358 C
6dd74de359 end
6dd74de360
6dd74de361 classDef Test fill:#F84E68,stroke:#333,color:white;
6dd74de362 class A,T Test
6dd74de363 classDef TestSub fill:green;
6dd74de364 class T TestSub
6dd74de365 linkStyle 0,1 color:orange, stroke: orange;
6dd74de366 `,
6dd74de367 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de368 );
6dd74de369 });
6dd74de370 it('60-elk: handle styling for all node shapes - v2', () => {
6dd74de371 imgSnapshotTest(
6dd74de372 `
6dd74de373 flowchart-elk LR
6dd74de374 A[red text] -->|default style| B(blue text)
6dd74de375 C([red text]) -->|default style| D[[blue text]]
6dd74de376 E[(red text)] -->|default style| F((blue text))
6dd74de377 G>red text] -->|default style| H{blue text}
6dd74de378 I{{red text}} -->|default style| J[/blue text/]
6dd74de379 K[\\ red text\\] -->|default style| L[/blue text\\]
6dd74de380 M[\\ red text/] -->|default style| N[blue text];
6dd74de381 O(((red text))) -->|default style| P(((blue text)));
6dd74de382 linkStyle default color:Sienna;
6dd74de383 style A stroke:#ff0000,fill:#ffcccc,color:#ff0000;
6dd74de384 style B stroke:#0000ff,fill:#ccccff,color:#0000ff;
6dd74de385 style C stroke:#ff0000,fill:#ffcccc,color:#ff0000;
6dd74de386 style D stroke:#0000ff,fill:#ccccff,color:#0000ff;
6dd74de387 style E stroke:#ff0000,fill:#ffcccc,color:#ff0000;
6dd74de388 style F stroke:#0000ff,fill:#ccccff,color:#0000ff;
6dd74de389 style G stroke:#ff0000,fill:#ffcccc,color:#ff0000;
6dd74de390 style H stroke:#0000ff,fill:#ccccff,color:#0000ff;
6dd74de391 style I stroke:#ff0000,fill:#ffcccc,color:#ff0000;
6dd74de392 style J stroke:#0000ff,fill:#ccccff,color:#0000ff;
6dd74de393 style K stroke:#ff0000,fill:#ffcccc,color:#ff0000;
6dd74de394 style L stroke:#0000ff,fill:#ccccff,color:#0000ff;
6dd74de395 style M stroke:#ff0000,fill:#ffcccc,color:#ff0000;
6dd74de396 style N stroke:#0000ff,fill:#ccccff,color:#0000ff;
6dd74de397 style O stroke:#ff0000,fill:#ffcccc,color:#ff0000;
6dd74de398 style P stroke:#0000ff,fill:#ccccff,color:#0000ff;
6dd74de399 `,
6dd74de400 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose', logLevel: 2 }
6dd74de401 );
6dd74de402 });
6dd74de403 it('61-elk: fontawesome icons in edge labels', () => {
6dd74de404 imgSnapshotTest(
6dd74de405 `
6dd74de406 flowchart-elk TD
6dd74de407 C -->|fa:fa-car Car| F[fa:fa-car Car]
6dd74de408 `,
6dd74de409 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de410 );
6dd74de411 });
6dd74de412 it('62-elk: should render styled subgraphs', () => {
6dd74de413 imgSnapshotTest(
6dd74de414 `
6dd74de415 flowchart-elk TB
6dd74de416 A
6dd74de417 B
6dd74de418 subgraph foo[Foo SubGraph]
6dd74de419 C
6dd74de420 D
6dd74de421 end
6dd74de422 subgraph bar[Bar SubGraph]
6dd74de423 E
6dd74de424 F
6dd74de425 end
6dd74de426 G
6dd74de427
6dd74de428 A-->B
6dd74de429 B-->C
6dd74de430 C-->D
6dd74de431 B-->D
6dd74de432 D-->E
6dd74de433 E-->A
6dd74de434 E-->F
6dd74de435 F-->D
6dd74de436 F-->G
6dd74de437 B-->G
6dd74de438 G-->D
6dd74de439
6dd74de440 style foo fill:#F99,stroke-width:2px,stroke:#F0F,color:darkred
6dd74de441 style bar fill:#999,stroke-width:10px,stroke:#0F0,color:blue
6dd74de442 `,
6dd74de443 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de444 );
6dd74de445 });
6dd74de446 it('63-elk: title on subgraphs should be themeable', () => {
6dd74de447 imgSnapshotTest(
6dd74de448 `
6dd74de449 %%{init:{"theme":"base", "themeVariables": {"primaryColor":"#411d4e", "titleColor":"white", "darkMode":true}}}%%
6dd74de450 flowchart-elk LR
6dd74de451 subgraph A
6dd74de452 a --> b
6dd74de453 end
6dd74de454 subgraph B
6dd74de455 i -->f
6dd74de456 end
6dd74de457 A --> B
6dd74de458 `,
6dd74de459 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de460 );
6dd74de461 });
6dd74de462 it('65-elk: text-color from classes', () => {
6dd74de463 imgSnapshotTest(
6dd74de464 `
6dd74de465 flowchart-elk LR
6dd74de466 classDef dark fill:#000,stroke:#000,stroke-width:4px,color:#fff
6dd74de467 Lorem --> Ipsum --> Dolor
6dd74de468 class Lorem,Dolor dark
6dd74de469 `,
6dd74de470 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de471 );
6dd74de472 });
6dd74de473 it('66-elk: More nested subgraph cases (TB)', () => {
6dd74de474 imgSnapshotTest(
6dd74de475 `
6dd74de476flowchart-elk TB
6dd74de477 subgraph two
6dd74de478 b1
6dd74de479 end
6dd74de480 subgraph three
6dd74de481 c2
6dd74de482 end
6dd74de483
6dd74de484 three --> two
6dd74de485 two --> c2
6dd74de486
6dd74de487 `,
6dd74de488 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de489 );
6dd74de490 });
6dd74de491 it('67-elk: More nested subgraph cases (RL)', () => {
6dd74de492 imgSnapshotTest(
6dd74de493 `
6dd74de494flowchart-elk RL
6dd74de495 subgraph two
6dd74de496 b1
6dd74de497 end
6dd74de498 subgraph three
6dd74de499 c2
6dd74de500 end
6dd74de501
6dd74de502 three --> two
6dd74de503 two --> c2
6dd74de504
6dd74de505 `,
6dd74de506 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de507 );
6dd74de508 });
6dd74de509 it('68-elk: More nested subgraph cases (BT)', () => {
6dd74de510 imgSnapshotTest(
6dd74de511 `
6dd74de512flowchart-elk BT
6dd74de513 subgraph two
6dd74de514 b1
6dd74de515 end
6dd74de516 subgraph three
6dd74de517 c2
6dd74de518 end
6dd74de519
6dd74de520 three --> two
6dd74de521 two --> c2
6dd74de522
6dd74de523 `,
6dd74de524 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de525 );
6dd74de526 });
6dd74de527 it('69-elk: More nested subgraph cases (LR)', () => {
6dd74de528 imgSnapshotTest(
6dd74de529 `
6dd74de530flowchart-elk LR
6dd74de531 subgraph two
6dd74de532 b1
6dd74de533 end
6dd74de534 subgraph three
6dd74de535 c2
6dd74de536 end
6dd74de537
6dd74de538 three --> two
6dd74de539 two --> c2
6dd74de540
6dd74de541 `,
6dd74de542 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de543 );
6dd74de544 });
6dd74de545 it('70-elk: Handle nested subgraph cases (TB) link out and link between subgraphs', () => {
6dd74de546 imgSnapshotTest(
6dd74de547 `
6dd74de548flowchart-elk TB
6dd74de549 subgraph S1
6dd74de550 sub1 -->sub2
6dd74de551 end
6dd74de552 subgraph S2
6dd74de553 sub4
6dd74de554 end
6dd74de555 S1 --> S2
6dd74de556 sub1 --> sub4
6dd74de557 `,
6dd74de558 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de559 );
6dd74de560 });
6dd74de561 it('71-elk: Handle nested subgraph cases (RL) link out and link between subgraphs', () => {
6dd74de562 imgSnapshotTest(
6dd74de563 `
6dd74de564flowchart-elk RL
6dd74de565 subgraph S1
6dd74de566 sub1 -->sub2
6dd74de567 end
6dd74de568 subgraph S2
6dd74de569 sub4
6dd74de570 end
6dd74de571 S1 --> S2
6dd74de572 sub1 --> sub4
6dd74de573 `,
6dd74de574 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de575 );
6dd74de576 });
6dd74de577 it('72-elk: Handle nested subgraph cases (BT) link out and link between subgraphs', () => {
6dd74de578 imgSnapshotTest(
6dd74de579 `
6dd74de580flowchart-elk BT
6dd74de581 subgraph S1
6dd74de582 sub1 -->sub2
6dd74de583 end
6dd74de584 subgraph S2
6dd74de585 sub4
6dd74de586 end
6dd74de587 S1 --> S2
6dd74de588 sub1 --> sub4
6dd74de589 `,
6dd74de590 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de591 );
6dd74de592 });
6dd74de593 it('74-elk: Handle nested subgraph cases (RL) link out and link between subgraphs', () => {
6dd74de594 imgSnapshotTest(
6dd74de595 `
6dd74de596flowchart-elk RL
6dd74de597 subgraph S1
6dd74de598 sub1 -->sub2
6dd74de599 end
6dd74de600 subgraph S2
6dd74de601 sub4
6dd74de602 end
6dd74de603 S1 --> S2
6dd74de604 sub1 --> sub4
6dd74de605 `,
6dd74de606 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de607 );
6dd74de608 });
6dd74de609 it('74-elk: Handle labels for multiple edges from and to the same couple of nodes', () => {
6dd74de610 imgSnapshotTest(
6dd74de611 `
6dd74de612flowchart-elk RL
6dd74de613 subgraph one
6dd74de614 a1 -- l1 --> a2
6dd74de615 a1 -- l2 --> a2
6dd74de616 end
6dd74de617 `,
6dd74de618 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de619 );
6dd74de620 });
6dd74de621
6dd74de622 it('76-elk: handle unicode encoded character with HTML labels true', () => {
6dd74de623 imgSnapshotTest(
6dd74de624 `flowchart-elk TB
6dd74de625 a{{"Lorem 'ipsum' dolor 'sit' amet, 'consectetur' adipiscing 'elit'."}}
6dd74de626 --> b{{"Lorem #quot;ipsum#quot; dolor #quot;sit#quot; amet,#quot;consectetur#quot; adipiscing #quot;elit#quot;."}}
6dd74de627 `,
6dd74de628 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de629 );
6dd74de630 });
6dd74de631
6dd74de632 it('2050-elk: handling of different rendering direction in subgraphs', () => {
6dd74de633 imgSnapshotTest(
6dd74de634 `
6dd74de635 flowchart-elk LR
6dd74de636
6dd74de637 subgraph TOP
6dd74de638 direction TB
6dd74de639 subgraph B1
6dd74de640 direction RL
6dd74de641 i1 -->f1
6dd74de642 end
6dd74de643 subgraph B2
6dd74de644 direction BT
6dd74de645 i2 -->f2
6dd74de646 end
6dd74de647 end
6dd74de648 A --> TOP --> B
6dd74de649 B1 --> B2
6dd74de650 `,
6dd74de651 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de652 );
6dd74de653 });
6dd74de654
6dd74de655 it('2388-elk: handling default in the node name', () => {
6dd74de656 imgSnapshotTest(
6dd74de657 `
6dd74de658 flowchart-elk LR
6dd74de659 default-index.js --> dot.template.js
6dd74de660 index.js --> module-utl.js
6dd74de661 `,
6dd74de662 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de663 );
6dd74de664 });
6dd74de665 it('2824-elk: Clipping of edges', () => {
6dd74de666 imgSnapshotTest(
6dd74de667 `
6dd74de668 flowchart-elk TD
6dd74de669 A --> B
6dd74de670 A --> C
6dd74de671 B --> C
6dd74de672 `,
6dd74de673 { htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
6dd74de674 );
6dd74de675 });
6dd74de676 it('1433-elk: should render a titled flowchart with titleTopMargin set to 0', () => {
6dd74de677 imgSnapshotTest(
6dd74de678 `---
6dd74de679title: Simple flowchart
6dd74de680---
6dd74de681flowchart-elk TD
6dd74de682A --> B
6dd74de683`,
6dd74de684 { flowchart: { titleTopMargin: 0 } }
6dd74de685 );
6dd74de686 });
6dd74de687 it('elk: should include classes on the edges', () => {
6dd74de688 renderGraph(
6dd74de689 `flowchart-elk TD
6dd74de690 A --> B --> C --> D
6dd74de691 `,
6dd74de692 {}
6dd74de693 );
6dd74de694 cy.get('svg').should((svg) => {
6dd74de695 const edges = svg[0].querySelectorAll('.edges > path');
6dd74de696 edges.forEach((edge) => {
6dd74de697 expect(edge).to.have.class('flowchart-link');
6dd74de698 });
6dd74de699 });
6dd74de700 });
6dd74de701 describe('Markdown strings flowchart-elk (#4220)', () => {
6dd74de702 describe('html labels', () => {
6dd74de703 it('With styling and classes', () => {
6dd74de704 imgSnapshotTest(
6dd74de705 `%%{init: {"flowchart": {"htmlLabels": true}} }%%
6dd74de706flowchart-elk LR
6dd74de707 A:::someclass --> B["\`The **cat** in the hat\`"]:::someclass
6dd74de708 id1(Start)-->id2(Stop)
6dd74de709 style id1 fill:#f9f,stroke:#333,stroke-width:4px
6dd74de710 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de711 classDef someclass fill:#f96
6dd74de712`,
6dd74de713 { flowchart: { titleTopMargin: 0 } }
6dd74de714 );
6dd74de715 });
6dd74de716 it('With formatting in a node', () => {
6dd74de717 imgSnapshotTest(
6dd74de718 `%%{init: {"flowchart": {"htmlLabels": true}} }%%
6dd74de719flowchart-elk LR
6dd74de720 a{"\`The **cat** in the hat\`"} -- 1o --> b
6dd74de721 a -- 2o --> c
6dd74de722 a -- 3o --> d
6dd74de723 g --2i--> a
6dd74de724 d --1i--> a
6dd74de725 h --3i -->a
6dd74de726 b --> d(The dog in the hog)
6dd74de727 c --> d
6dd74de728`,
6dd74de729 { flowchart: { titleTopMargin: 0 } }
6dd74de730 );
6dd74de731 });
6dd74de732 it('New line in node and formatted edge label', () => {
6dd74de733 imgSnapshotTest(
6dd74de734 `%%{init: {"flowchart": {"htmlLabels": true}} }%%
6dd74de735flowchart-elk LR
6dd74de736b("\`The dog in **the** hog.(1)
6dd74de737NL\`") --"\`1o **bold**\`"--> c
6dd74de738`,
6dd74de739 { flowchart: { titleTopMargin: 0 } }
6dd74de740 );
6dd74de741 });
6dd74de742 it.skip('Wrapping long text with a new line', () => {
6dd74de743 imgSnapshotTest(
6dd74de744 `%%{init: {"flowchart": {"htmlLabels": true}} }%%
6dd74de745flowchart-elk LR
6dd74de746b(\`The dog in **the** hog.(1).. a a a a *very long text* about it
6dd74de747Word!
6dd74de748
6dd74de749Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. \`) --> c
6dd74de750
6dd74de751`,
6dd74de752 { flowchart: { titleTopMargin: 0 } }
6dd74de753 );
6dd74de754 });
6dd74de755 it('Sub graphs and markdown strings', () => {
6dd74de756 imgSnapshotTest(
6dd74de757 `%%{init: {"flowchart": {"htmlLabels": true}} }%%
6dd74de758flowchart-elk LR
6dd74de759subgraph "One"
6dd74de760 a("\`The **cat**
6dd74de761 in the hat\`") -- "1o" --> b{{"\`The **dog** in the hog\`"}}
6dd74de762end
6dd74de763subgraph "\`**Two**\`"
6dd74de764 c("\`The **cat**
6dd74de765 in the hat\`") -- "\`1o **ipa**\`" --> d("The dog in the hog")
6dd74de766end
6dd74de767
6dd74de768`,
6dd74de769 { flowchart: { titleTopMargin: 0 } }
6dd74de770 );
6dd74de771 });
6dd74de772 });
6dd74de773
6dd74de774 describe('svg text labels', () => {
6dd74de775 it('With styling and classes', () => {
6dd74de776 imgSnapshotTest(
6dd74de777 `%%{init: {"flowchart": {"htmlLabels": false}} }%%
6dd74de778flowchart-elk LR
6dd74de779 A:::someclass --> B["\`The **cat** in the hat\`"]:::someclass
6dd74de780 id1(Start)-->id2(Stop)
6dd74de781 style id1 fill:#f9f,stroke:#333,stroke-width:4px
6dd74de782 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
6dd74de783 classDef someclass fill:#f96
6dd74de784`,
6dd74de785 { flowchart: { titleTopMargin: 0 } }
6dd74de786 );
6dd74de787 });
6dd74de788 it('With formatting in a node', () => {
6dd74de789 imgSnapshotTest(
6dd74de790 `%%{init: {"flowchart": {"htmlLabels": false}} }%%
6dd74de791flowchart-elk LR
6dd74de792 a{"\`The **cat** in the hat\`"} -- 1o --> b
6dd74de793 a -- 2o --> c
6dd74de794 a -- 3o --> d
6dd74de795 g --2i--> a
6dd74de796 d --1i--> a
6dd74de797 h --3i -->a
6dd74de798 b --> d(The dog in the hog)
6dd74de799 c --> d
6dd74de800`,
6dd74de801 { flowchart: { titleTopMargin: 0 } }
6dd74de802 );
6dd74de803 });
6dd74de804 it('New line in node and formatted edge label', () => {
6dd74de805 imgSnapshotTest(
6dd74de806 `%%{init: {"flowchart": {"htmlLabels": false}} }%%
6dd74de807flowchart-elk LR
6dd74de808b("\`The dog in **the** hog.(1)
6dd74de809NL\`") --"\`1o **bold**\`"--> c
6dd74de810`,
6dd74de811 { flowchart: { titleTopMargin: 0 } }
6dd74de812 );
6dd74de813 });
6dd74de814 it('Wrapping long text with a new line', () => {
6dd74de815 imgSnapshotTest(
6dd74de816 `%%{init: {"flowchart": {"htmlLabels": false}} }%%
6dd74de817flowchart-elk LR
6dd74de818b("\`The dog in **the** hog.(1).. a a a a *very long text* about it
6dd74de819Word!
6dd74de820
6dd74de821Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. Another line with many, many words. \`") --> c
6dd74de822
6dd74de823`,
6dd74de824 { flowchart: { titleTopMargin: 0 } }
6dd74de825 );
6dd74de826 });
6dd74de827 it('Sub graphs and markdown strings', () => {
6dd74de828 imgSnapshotTest(
6dd74de829 `%%{init: {"flowchart": {"htmlLabels": false}} }%%
6dd74de830flowchart-elk LR
6dd74de831subgraph "One"
6dd74de832 a("\`The **cat**
6dd74de833 in the hat\`") -- "1o" --> b{{"\`The **dog** in the hog\`"}}
6dd74de834end
6dd74de835subgraph "\`**Two**\`"
6dd74de836 c("\`The **cat**
6dd74de837 in the hat\`") -- "\`1o **ipa**\`" --> d("The dog in the hog")
6dd74de838end
6dd74de839
6dd74de840`,
6dd74de841 { flowchart: { titleTopMargin: 0 } }
6dd74de842 );
6dd74de843 });
6dd74de844 it('Sub graphs', () => {
6dd74de845 imgSnapshotTest(
6dd74de846 `---
6dd74de847config:
6dd74de848 layout: elk
6dd74de849---
6dd74de850
6dd74de851flowchart LR
6dd74de852 subgraph subgraph_ko6czgs5u["Untitled subgraph"]
6dd74de853 D["Option 1"]
6dd74de854 end
6dd74de855 C{"Evaluate"} -- One --> D
6dd74de856 C -- Two --> E(("Option 2"))
6dd74de857 D --> E
6dd74de858 A["A"]
6dd74de859
6dd74de860`,
6dd74de861 { flowchart: { titleTopMargin: 0 } }
6dd74de862 );
6dd74de863 });
6dd74de864 it('6080: should handle diamond shape intersections', () => {
6dd74de865 imgSnapshotTest(
6dd74de866 `---
6dd74de867config:
6dd74de868 layout: elk
6dd74de869---
6dd74de870flowchart LR
6dd74de871 subgraph s1["Untitled subgraph"]
6dd74de872 n1["Evaluate"]
6dd74de873 n2["Option 1"]
6dd74de874 n3["Option 2"]
6dd74de875 n4["fa:fa-car Option 3"]
6dd74de876 end
6dd74de877 subgraph s2["Untitled subgraph"]
6dd74de878 n5["Evaluate"]
6dd74de879 n6["Option 1"]
6dd74de880 n7["Option 2"]
6dd74de881 n8["fa:fa-car Option 3"]
6dd74de882 end
6dd74de883 A["Start"] -- Some text --> B("Continue")
6dd74de884 B --> C{"Evaluate"}
6dd74de885 C -- One --> D["Option 1"]
6dd74de886 C -- Two --> E["Option 2"]
6dd74de887 C -- Three --> F["fa:fa-car Option 3"]
6dd74de888 n1 -- One --> n2
6dd74de889 n1 -- Two --> n3
6dd74de890 n1 -- Three --> n4
6dd74de891 n5 -- One --> n6
6dd74de892 n5 -- Two --> n7
6dd74de893 n5 -- Three --> n8
6dd74de894 n1@{ shape: diam}
6dd74de895 n2@{ shape: rect}
6dd74de896 n3@{ shape: rect}
6dd74de897 n4@{ shape: rect}
6dd74de898 n5@{ shape: diam}
6dd74de899 n6@{ shape: rect}
6dd74de900 n7@{ shape: rect}
6dd74de901 n8@{ shape: rect}
6dd74de902
6dd74de903`,
6dd74de904 { flowchart: { titleTopMargin: 0 } }
6dd74de905 );
6dd74de906 });
6dd74de907
6dd74de908 it('6088-1: should handle diamond shape intersections', () => {
6dd74de909 imgSnapshotTest(
6dd74de910 `---
6dd74de911config:
6dd74de912 layout: elk
6dd74de913---
6dd74de914 flowchart LR
6dd74de915 subgraph S2
6dd74de916 subgraph s1["APA"]
6dd74de917 D{"Use the editor"}
6dd74de918 end
6dd74de919
6dd74de920
6dd74de921 D -- Mermaid js --> I{"fa:fa-code Text"}
6dd74de922 D --> I
6dd74de923 D --> I
6dd74de924
6dd74de925 end
6dd74de926`,
6dd74de927 { flowchart: { titleTopMargin: 0 } }
6dd74de928 );
6dd74de929 });
6dd74de930
6dd74de931 it('6088-2: should handle diamond shape intersections', () => {
6dd74de932 imgSnapshotTest(
6dd74de933 `---
6dd74de934config:
6dd74de935 layout: elk
6dd74de936---
6dd74de937 flowchart LR
6dd74de938 a
6dd74de939 subgraph s0["APA"]
6dd74de940 subgraph s8["APA"]
6dd74de941 subgraph s1["APA"]
6dd74de942 D{"X"}
6dd74de943 E[Q]
6dd74de944 end
6dd74de945 subgraph s3["BAPA"]
6dd74de946 F[Q]
6dd74de947 I
6dd74de948 end
6dd74de949 D --> I
6dd74de950 D --> I
6dd74de951 D --> I
6dd74de952
6dd74de953 I{"X"}
6dd74de954 end
6dd74de955 end
6dd74de956
6dd74de957`,
6dd74de958 { flowchart: { titleTopMargin: 0 } }
6dd74de959 );
6dd74de960 });
6dd74de961
6dd74de962 it('6088-3: should handle diamond shape intersections', () => {
6dd74de963 imgSnapshotTest(
6dd74de964 `---
6dd74de965config:
6dd74de966 layout: elk
6dd74de967---
6dd74de968 flowchart LR
6dd74de969 a
6dd74de970 D{"Use the editor"}
6dd74de971
6dd74de972 D -- Mermaid js --> I{"fa:fa-code Text"}
6dd74de973 D-->I
6dd74de974 D-->I
6dd74de975
6dd74de976`,
6dd74de977 { flowchart: { titleTopMargin: 0 } }
6dd74de978 );
6dd74de979 });
6dd74de980
6dd74de981 it('6088-4: should handle diamond shape intersections', () => {
6dd74de982 imgSnapshotTest(
6dd74de983 `---
6dd74de984config:
6dd74de985 layout: elk
6dd74de986---
6dd74de987flowchart LR
6dd74de988 subgraph s1["Untitled subgraph"]
6dd74de989 n1["Evaluate"]
6dd74de990 n2["Option 1"]
6dd74de991 n3["Option 2"]
6dd74de992 n4["fa:fa-car Option 3"]
6dd74de993 end
6dd74de994 subgraph s2["Untitled subgraph"]
6dd74de995 n5["Evaluate"]
6dd74de996 n6["Option 1"]
6dd74de997 n7["Option 2"]
6dd74de998 n8["fa:fa-car Option 3"]
6dd74de999 end
6dd74de1000 A["Start"] -- Some text --> B("Continue")
6dd74de1001 B --> C{"Evaluate"}
6dd74de1002 C -- One --> D["Option 1"]
6dd74de1003 C -- Two --> E["Option 2"]
6dd74de1004 C -- Three --> F["fa:fa-car Option 3"]
6dd74de1005 n1 -- One --> n2
6dd74de1006 n1 -- Two --> n3
6dd74de1007 n1 -- Three --> n4
6dd74de1008 n5 -- One --> n6
6dd74de1009 n5 -- Two --> n7
6dd74de1010 n5 -- Three --> n8
6dd74de1011 n1@{ shape: diam}
6dd74de1012 n2@{ shape: rect}
6dd74de1013 n3@{ shape: rect}
6dd74de1014 n4@{ shape: rect}
6dd74de1015 n5@{ shape: diam}
6dd74de1016 n6@{ shape: rect}
6dd74de1017 n7@{ shape: rect}
6dd74de1018 n8@{ shape: rect}
6dd74de1019
6dd74de1020`,
6dd74de1021 { flowchart: { titleTopMargin: 0 } }
6dd74de1022 );
6dd74de1023 });
6dd74de1024
6dd74de1025 it('6088-5: should handle diamond shape intersections', () => {
6dd74de1026 imgSnapshotTest(
6dd74de1027 `---
6dd74de1028config:
6dd74de1029 layout: elk
6dd74de1030---
6dd74de1031flowchart LR
6dd74de1032 A{A} --> B & C
6dd74de1033
6dd74de1034`,
6dd74de1035 { flowchart: { titleTopMargin: 0 } }
6dd74de1036 );
6dd74de1037 });
6dd74de1038 it('6088-6: should handle diamond shape intersections', () => {
6dd74de1039 imgSnapshotTest(
6dd74de1040 `---
6dd74de1041config:
6dd74de1042 layout: elk
6dd74de1043---
6dd74de1044flowchart LR
6dd74de1045 A{A} --> B & C
6dd74de1046 subgraph "subbe"
6dd74de1047 A
6dd74de1048 end
6dd74de1049
6dd74de1050`,
6dd74de1051 { flowchart: { titleTopMargin: 0 } }
6dd74de1052 );
6dd74de1053 });
6dd74de1054 });
6dd74de1055 });
6dd74de1056
6dd74de1057 it('6647-elk: should keep node order when using elk layout unless it would add crossings', () => {
6dd74de1058 imgSnapshotTest(
6dd74de1059 `---
6dd74de1060config:
6dd74de1061 layout: elk
6dd74de1062---
6dd74de1063 flowchart TB
6dd74de1064 a --> a1 & a2 & a3 & a4
6dd74de1065 b --> b1 & b2
6dd74de1066 b2 --> b3
6dd74de1067 b1 --> b4
6dd74de1068 `
6dd74de1069 );
6dd74de1070 });
6dd74de1071});
6dd74de1072
6dd74de1073describe('Title and arrow styling #4813', () => {
6dd74de1074 it('should render a flowchart with title', () => {
6dd74de1075 const titleString = 'Test Title';
6dd74de1076 renderGraph(
6dd74de1077 `---
6dd74de1078 title: ${titleString}
6dd74de1079 ---
6dd74de1080 flowchart LR
6dd74de1081 A-->B
6dd74de1082 A-->C`,
6dd74de1083 { layout: 'elk' }
6dd74de1084 );
6dd74de1085 cy.get('svg').should((svg) => {
6dd74de1086 const title = svg[0].querySelector('text');
6dd74de1087 expect(title.textContent).to.contain(titleString);
6dd74de1088 });
6dd74de1089 });
6dd74de1090
6dd74de1091 it('Render with stylized arrows', () => {
6dd74de1092 renderGraph(
6dd74de1093 `
6dd74de1094 flowchart LR
6dd74de1095 A-->B
6dd74de1096 B-.-oC
6dd74de1097 C==xD
6dd74de1098 D ~~~ A`,
6dd74de1099 { layout: 'elk' }
6dd74de1100 );
6dd74de1101 cy.get('svg').should((svg) => {
6dd74de1102 const edges = svg[0].querySelectorAll('.edges path');
6dd74de1103 expect(edges[0].getAttribute('class')).to.contain('edge-pattern-solid');
6dd74de1104 expect(edges[1].getAttribute('class')).to.contain('edge-pattern-dotted');
6dd74de1105 expect(edges[2].getAttribute('class')).to.contain('edge-thickness-thick');
6dd74de1106 expect(edges[3].getAttribute('class')).to.contain('edge-thickness-invisible');
6dd74de1107 });
6dd74de1108 });
6dd74de1109});