2023-07-07 17:21:18 +05:30
import { imgSnapshotTest , renderGraph } from '../../helpers/util.ts' ;
2020-07-11 16:54:00 +10:00
describe ( 'Flowchart v2' , ( ) => {
it ( '1: should render a simple flowchart' , ( ) => {
imgSnapshotTest (
` flowchart TD
A [ Christmas ] -- > | Get money | B ( Go shopping )
B -- > C { Let me think }
C -- > | One | D [ Laptop ]
C -- > | Two | E [ iPhone ]
C -- > | Three | F [ fa : fa - car Car ]
` ,
{ }
) ;
} ) ;
it ( '2: should render a simple flowchart with diagramPadding set to 0' , ( ) => {
imgSnapshotTest (
` flowchart TD
A [ Christmas ] -- > | Get money | B ( Go shopping )
B -- > C { Let me think }
% % this is a comment
C -- > | One | D [ Laptop ]
C -- > | Two | E [ iPhone ]
C -- > | Three | F [ fa : fa - car Car ]
` ,
{ flowchart : { diagramPadding : 0 } }
) ;
} ) ;
2020-07-21 12:01:08 +02:00
2021-11-18 19:17:00 +01:00
it ( '3: a link with correct arrowhead to a subgraph' , ( ) => {
2020-07-21 12:01:08 +02:00
imgSnapshotTest (
` flowchart TD
P1
P1 -- > P1 . 5
subgraph P1 . 5
P2
P2 . 5 ( ( A ) )
P3
end
P2 -- > P4
P3 -- > P6
P1 . 5 -- > P5
` ,
2022-08-27 15:03:29 +02:00
{ }
2020-07-21 12:01:08 +02:00
) ;
2020-07-21 12:31:05 +02:00
} ) ;
2020-08-16 13:01:45 +02:00
2020-08-25 17:05:01 +02:00
it ( '4: Length of edges' , ( ) => {
2020-08-16 13:01:45 +02:00
imgSnapshotTest (
` flowchart TD
L1 -- - L2
L2 -- - C
M1 -- - > C
R1 . - > R2
R2 < . - > C
C -- > | Label 1 | E1
C < -- Label 2 -- - > E2
C -- -- > E3
C < - ... - > E4
C === === > E5
` ,
2022-08-27 15:03:29 +02:00
{ }
2020-08-16 13:01:45 +02:00
) ;
} ) ;
2020-08-25 17:05:01 +02:00
it ( '5: should render escaped without html labels' , ( ) => {
2020-08-23 20:02:51 +02:00
imgSnapshotTest (
` flowchart TD
a [ "<strong>Haiya</strong>" ] -- -- > b
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : false , flowchart : { htmlLabels : false } }
2020-08-23 20:02:51 +02:00
) ;
} ) ;
2020-08-25 17:05:01 +02:00
it ( '6: should render non-escaped with html labels' , ( ) => {
2020-08-23 20:02:51 +02:00
imgSnapshotTest (
` flowchart TD
a [ "<strong>Haiya</strong>" ] === > b
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-08-23 20:02:51 +02:00
) ;
} ) ;
2020-08-25 17:05:01 +02:00
it ( '7: should render a flowchart when useMaxWidth is true (default)' , ( ) => {
renderGraph (
` flowchart TD
A [ Christmas ] -- > | Get money | B ( Go shopping )
B -- > C { Let me think }
C -- > | One | D [ Laptop ]
C -- > | Two | E [ iPhone ]
C -- > | Three | F [ fa : fa - car Car ]
` ,
{ flowchart : { useMaxWidth : true } }
) ;
2021-11-18 19:17:00 +01:00
cy . get ( 'svg' ) . should ( ( svg ) => {
expect ( svg ) . to . have . attr ( 'width' , '100%' ) ;
2022-08-28 11:25:09 +02:00
// expect(svg).to.have.attr('height');
2021-11-18 19:17:00 +01:00
// use within because the absolute value can be slightly different depending on the environment ±5%
2022-08-28 11:25:09 +02:00
// const height = parseFloat(svg.attr('height'));
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
2021-11-18 19:17:00 +01:00
const style = svg . attr ( 'style' ) ;
expect ( style ) . to . match ( /^max-width: [\d.]+px;$/ ) ;
const maxWidthValue = parseFloat ( style . match ( /[\d.]+/g ) . join ( '' ) ) ;
expect ( maxWidthValue ) . to . be . within ( 290 * 0.95 - 1 , 290 * 1.05 ) ;
} ) ;
2020-08-25 17:05:01 +02:00
} ) ;
it ( '8: should render a flowchart when useMaxWidth is false' , ( ) => {
renderGraph (
` flowchart TD
A [ Christmas ] -- > | Get money | B ( Go shopping )
B -- > C { Let me think }
C -- > | One | D [ Laptop ]
C -- > | Two | E [ iPhone ]
C -- > | Three | F [ fa : fa - car Car ]
` ,
{ flowchart : { useMaxWidth : false } }
) ;
2021-11-18 19:17:00 +01:00
cy . get ( 'svg' ) . should ( ( svg ) => {
2022-08-28 11:25:09 +02:00
// const height = parseFloat(svg.attr('height'));
2021-11-18 19:17:00 +01:00
const width = parseFloat ( svg . attr ( 'width' ) ) ;
// use within because the absolute value can be slightly different depending on the environment ±5%
2022-08-28 11:25:09 +02:00
// expect(height).to.be.within(446 * 0.95, 446 * 1.05);
2021-11-18 19:17:00 +01:00
expect ( width ) . to . be . within ( 290 * 0.95 - 1 , 290 * 1.05 ) ;
expect ( svg ) . to . not . have . attr ( 'style' ) ;
} ) ;
2020-08-25 17:05:01 +02:00
} ) ;
2020-09-20 12:14:04 +02:00
it ( 'V2 - 16: Render Stadium shape' , ( ) => {
imgSnapshotTest (
` flowchart TD
A ( [ stadium shape test ] )
A -- > | Get money | B ( [ Go shopping ] )
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 ? ] )
C -- > | One | D ( [ Laptop ] )
C -- > | Two | E ( [ iPhone ] )
C -- > | Three | F ( [ Car < br / > wroom wroom ] )
click A "index.html#link-clicked" "link test"
click B testClick "click test"
classDef someclass fill : # f96 ;
class A someclass ;
class C someclass ;
` ,
2021-11-18 19:17:00 +01:00
{ flowchart : { htmlLabels : false } , fontFamily : 'courier' }
2020-09-20 12:14:04 +02:00
) ;
} ) ;
2020-09-02 20:34:24 +02:00
it ( '50: handle nested subgraphs in reverse order' , ( ) => {
imgSnapshotTest (
` flowchart LR
a -- > b
subgraph A
B
end
subgraph B
b
end
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-02 20:34:24 +02:00
) ;
} ) ;
2020-09-06 22:34:13 +02:00
2020-09-02 20:34:24 +02:00
it ( '51: handle nested subgraphs in reverse order' , ( ) => {
imgSnapshotTest (
` flowchart LR
a -- > b
subgraph A
B
end
subgraph B
b
end
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-02 20:34:24 +02:00
) ;
} ) ;
2020-09-06 22:34:13 +02:00
2023-06-16 23:12:03 +05:30
it ( '52: handle nested subgraphs in several levels.' , ( ) => {
2020-09-06 22:34:13 +02:00
imgSnapshotTest (
` flowchart TB
b -- > B
a -- > c
subgraph O
A
end
subgraph B
c
end
subgraph A
a
b
B
end
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-06 22:34:13 +02:00
) ;
} ) ;
it ( '53: handle nested subgraphs with edges in and out' , ( ) => {
imgSnapshotTest (
` flowchart TB
internet
nat
routeur
lb1
lb2
compute1
compute2
subgraph project
routeur
nat
subgraph subnet1
compute1
lb1
end
subgraph subnet2
compute2
lb2
end
end
internet -- > routeur
routeur -- > subnet1 & subnet2
subnet1 & subnet2 -- > nat -- > internet
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-06 22:34:13 +02:00
) ;
} ) ;
it ( '54: handle nested subgraphs with outgoing links' , ( ) => {
imgSnapshotTest (
` flowchart TD
2020-10-07 20:16:36 +02:00
subgraph main
subgraph subcontainer
subcontainer - child
2020-09-06 22:34:13 +02:00
end
2020-10-07 20:16:36 +02:00
subcontainer - child -- > subcontainer - sibling
end
2020-09-06 22:34:13 +02:00
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-06 22:34:13 +02:00
) ;
} ) ;
it ( '55: handle nested subgraphs with outgoing links 2' , ( ) => {
imgSnapshotTest (
` flowchart TD
subgraph one [ One ]
subgraph sub _one [ Sub One ]
_sub _one
end
subgraph sub _two [ Sub Two ]
_sub _two
end
_one
end
% % here , either the first or the second one
sub _one -- > sub _two
_one -- > b
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-06 22:34:13 +02:00
) ;
} ) ;
2020-10-07 20:16:36 +02:00
it ( '56: handle nested subgraphs with outgoing links 3' , ( ) => {
2020-09-06 22:34:13 +02:00
imgSnapshotTest (
2020-10-07 20:16:36 +02:00
` flowchart TB
subgraph container _Beta
process _C -- > Process _D
end
subgraph container _Alpha
process _A -- > process _B
process _A -- > | messages | process _C
2020-09-06 22:34:13 +02:00
end
2020-10-07 20:16:36 +02:00
process _B -- > | via _AWSBatch | container _Beta
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-10-07 20:16:36 +02:00
) ;
} ) ;
it ( '57: handle nested subgraphs with outgoing links 4' , ( ) => {
imgSnapshotTest (
` flowchart LR
subgraph A
a -- > b
end
subgraph B
b
2020-09-06 22:34:13 +02:00
end
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-06 22:34:13 +02:00
) ;
} ) ;
it ( '57: handle nested subgraphs with outgoing links 2' , ( ) => {
imgSnapshotTest (
` flowchart TB
c1 -- > a2
subgraph one
a1 -- > a2
end
subgraph two
b1 -- > b2
end
subgraph three
c1 -- > c2
end
one -- > two
three -- > two
two -- > c2
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-06 22:34:13 +02:00
) ;
} ) ;
2020-10-22 18:47:32 +02:00
it ( '57.x: handle nested subgraphs with outgoing links 5' , ( ) => {
imgSnapshotTest (
` %% this does not produce the desired result
flowchart TB
subgraph container _Beta
process _C -- > Process _D
end
subgraph container _Alpha
process _A -- > process _B
process _B -- > | via _AWSBatch | container _Beta
process _A -- > | messages | process _C
end
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-10-22 18:47:32 +02:00
) ;
} ) ;
2020-09-23 19:51:16 +02:00
it ( '58: handle styling with style expressions' , ( ) => {
imgSnapshotTest (
`
flowchart LR
id1 ( Start ) -- > id2 ( Stop )
style id1 fill : # f9f , stroke : # 333 , stroke - width : 4 px
style id2 fill : # bbf , stroke : # f66 , stroke - width : 2 px , color : # fff , stroke - dasharray : 5 5
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-09-23 19:51:16 +02:00
) ;
} ) ;
2020-10-15 17:45:19 +02:00
it ( '59: handle styling of subgraphs and links' , ( ) => {
imgSnapshotTest (
`
2020-10-15 19:06:38 +02:00
flowchart TD
A [ Christmas ] == > D
A [ Christmas ] -- > | Get money | B ( Go shopping )
A [ Christmas ] == > C
subgraph T [ "Test" ]
A
B
C
end
classDef Test fill : # F84E68 , stroke : # 333 , color : white ;
class A , T Test
classDef TestSub fill : green ;
class T TestSub
linkStyle 0 , 1 color : orange , stroke : orange ;
2020-10-15 17:45:19 +02:00
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-10-15 17:45:19 +02:00
) ;
} ) ;
2021-02-18 19:52:50 +01:00
it ( '60: handle styling for all node shapes - v2' , ( ) => {
2021-01-23 18:10:21 +01:00
imgSnapshotTest (
`
flowchart LR
A [ red text ] -- > | default style | B ( blue text )
C ( [ red text ] ) -- > | default style | D [ [ blue text ] ]
E [ ( red text ) ] -- > | default style | F ( ( blue text ) )
G > red text ] -- > | default style | H { blue text }
I { { red text } } -- > | default style | J [ /blue text/ ]
2021-05-16 10:59:07 +02:00
K [ \ \ red text \ \ ] -- > | default style | L [ / b l u e t e x t \ \ ]
M [ \ \ red text / ] -- > | default style | N [ blue text ] ;
2022-02-17 17:22:38 +01:00
O ( ( ( red text ) ) ) -- > | default style | P ( ( ( blue text ) ) ) ;
2021-01-23 18:10:21 +01:00
linkStyle default color : Sienna ;
2021-05-16 10:59:07 +02:00
style A stroke : # ff0000 , fill : # ffcccc , color : # ff0000 ;
style B stroke : # 0000 ff , fill : # ccccff , color : # 0000 ff ;
style C stroke : # ff0000 , fill : # ffcccc , color : # ff0000 ;
style D stroke : # 0000 ff , fill : # ccccff , color : # 0000 ff ;
style E stroke : # ff0000 , fill : # ffcccc , color : # ff0000 ;
style F stroke : # 0000 ff , fill : # ccccff , color : # 0000 ff ;
style G stroke : # ff0000 , fill : # ffcccc , color : # ff0000 ;
style H stroke : # 0000 ff , fill : # ccccff , color : # 0000 ff ;
style I stroke : # ff0000 , fill : # ffcccc , color : # ff0000 ;
style J stroke : # 0000 ff , fill : # ccccff , color : # 0000 ff ;
style K stroke : # ff0000 , fill : # ffcccc , color : # ff0000 ;
style L stroke : # 0000 ff , fill : # ccccff , color : # 0000 ff ;
style M stroke : # ff0000 , fill : # ffcccc , color : # ff0000 ;
style N stroke : # 0000 ff , fill : # ccccff , color : # 0000 ff ;
2022-02-16 23:05:46 +01:00
style O stroke : # ff0000 , fill : # ffcccc , color : # ff0000 ;
style P stroke : # 0000 ff , fill : # ccccff , color : # 0000 ff ;
2021-01-23 18:10:21 +01:00
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' , logLevel : 2 }
2021-01-23 18:10:21 +01:00
) ;
} ) ;
2020-10-15 19:29:37 +02:00
it ( '61: fontawesome icons in edge labels' , ( ) => {
imgSnapshotTest (
`
flowchart TD
C -- > | fa : fa - car Car | F [ fa : fa - car Car ]
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-10-15 19:29:37 +02:00
) ;
} ) ;
2020-11-17 23:18:11 +01:00
it ( '62: should render styled subgraphs' , ( ) => {
imgSnapshotTest (
`
flowchart TB
A
B
subgraph foo [ Foo SubGraph ]
C
D
end
subgraph bar [ Bar SubGraph ]
E
F
end
G
2020-10-15 19:29:37 +02:00
2020-11-17 23:18:11 +01:00
A -- > B
B -- > C
C -- > D
B -- > D
D -- > E
E -- > A
E -- > F
F -- > D
F -- > G
B -- > G
G -- > D
2020-09-06 22:34:13 +02:00
2020-11-17 23:18:11 +01:00
style foo fill : # F99 , stroke - width : 2 px , stroke : # F0F , color : darkred
style bar fill : # 999 , stroke - width : 10 px , stroke : # 0 F0 , color : blue
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2020-11-17 23:18:11 +01:00
) ;
2021-01-23 21:48:36 +01:00
} ) ;
2021-01-23 16:07:25 +01:00
it ( '63: title on subgraphs should be themable' , ( ) => {
imgSnapshotTest (
`
% % { init : { "theme" : "base" , "themeVariables" : { "primaryColor" : "#411d4e" , "titleColor" : "white" , "darkMode" : true } } } % %
flowchart LR
subgraph A
a -- > b
end
subgraph B
i -- > f
end
A -- > B
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-01-23 16:07:25 +01:00
) ;
2021-03-23 20:10:58 +01:00
} ) ;
2023-08-11 13:58:19 +02:00
it ( '65-1: text-color from classes' , ( ) => {
2021-03-23 19:22:10 +01:00
imgSnapshotTest (
`
flowchart LR
classDef dark fill : # 000 , stroke : # 000 , stroke - width : 4 px , color : # fff
Lorem -- > Ipsum -- > Dolor
class Lorem , Dolor dark
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-03-23 19:22:10 +01:00
) ;
2020-11-17 23:18:11 +01:00
} ) ;
2023-08-11 13:58:19 +02:00
it ( '65-2: bold text from classes' , ( ) => {
imgSnapshotTest (
`
flowchart
classDef cat fill : # f9d5e5 , stroke : # 233 d4d , stroke - width : 2 px , font - weight : bold ;
CS ( A long bold text to be viewed ) : : : cat
` ,
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
) ;
} ) ;
it ( '65-3: bigger font from classes' , ( ) => {
imgSnapshotTest (
`
flowchart
Node1 : : : class1 -- > Node2 : : : class2
Node1 : : : class1 -- > Node3 : : : class2
Node3 -- > Node4 ( ( I am a circle ) ) : : : larger
classDef class1 fill : lightblue
classDef class2 fill : pink
classDef larger font - size : 30 px , fill : yellow
` ,
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
) ;
} ) ;
2021-04-30 09:04:09 +02:00
it ( '66: More nested subgraph cases (TB)' , ( ) => {
imgSnapshotTest (
`
flowchart TB
subgraph two
b1
end
subgraph three
c2
end
three -- > two
two -- > c2
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 09:04:09 +02:00
) ;
} ) ;
it ( '67: More nested subgraph cases (RL)' , ( ) => {
imgSnapshotTest (
`
flowchart RL
subgraph two
b1
end
subgraph three
c2
end
three -- > two
two -- > c2
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 09:04:09 +02:00
) ;
} ) ;
it ( '68: More nested subgraph cases (BT)' , ( ) => {
imgSnapshotTest (
`
flowchart BT
subgraph two
b1
end
subgraph three
c2
end
three -- > two
two -- > c2
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 09:04:09 +02:00
) ;
} ) ;
it ( '69: More nested subgraph cases (LR)' , ( ) => {
imgSnapshotTest (
`
flowchart LR
subgraph two
b1
end
subgraph three
c2
end
three -- > two
two -- > c2
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 09:04:09 +02:00
) ;
} ) ;
it ( '70: Handle nested subgraph cases (TB) link out and link between subgraphs' , ( ) => {
imgSnapshotTest (
`
flowchart TB
subgraph S1
sub1 -- > sub2
end
subgraph S2
sub4
end
S1 -- > S2
sub1 -- > sub4
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 09:04:09 +02:00
) ;
} ) ;
it ( '71: Handle nested subgraph cases (RL) link out and link between subgraphs' , ( ) => {
imgSnapshotTest (
`
flowchart RL
subgraph S1
sub1 -- > sub2
end
subgraph S2
sub4
end
S1 -- > S2
sub1 -- > sub4
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 09:04:09 +02:00
) ;
} ) ;
it ( '72: Handle nested subgraph cases (BT) link out and link between subgraphs' , ( ) => {
imgSnapshotTest (
`
flowchart BT
subgraph S1
sub1 -- > sub2
end
subgraph S2
sub4
end
S1 -- > S2
sub1 -- > sub4
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 09:04:09 +02:00
) ;
} ) ;
it ( '74: Handle nested subgraph cases (RL) link out and link between subgraphs' , ( ) => {
imgSnapshotTest (
`
flowchart RL
subgraph S1
sub1 -- > sub2
end
subgraph S2
sub4
end
S1 -- > S2
sub1 -- > sub4
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 09:04:09 +02:00
) ;
} ) ;
2021-11-18 19:17:00 +01:00
it ( '74: Handle labels for multiple edges from and to the same couple of nodes' , ( ) => {
2021-04-30 10:34:50 +02:00
imgSnapshotTest (
`
flowchart RL
subgraph one
a1 -- l1 -- > a2
a1 -- l2 -- > a2
end
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-04-30 10:34:50 +02:00
) ;
} ) ;
2021-05-18 22:34:24 +02:00
2021-10-21 19:45:15 +02:00
it ( '76: handle unicode encoded character with HTML labels true' , ( ) => {
imgSnapshotTest (
` flowchart TB
a { { "Lorem 'ipsum' dolor 'sit' amet, 'consectetur' adipiscing 'elit'." } }
2021-12-08 08:42:12 +01:00
-- > b { { "Lorem #quot;ipsum#quot; dolor #quot;sit#quot; amet,#quot;consectetur#quot; adipiscing #quot;elit#quot;." } }
2021-10-21 19:45:15 +02:00
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-10-21 19:45:15 +02:00
) ;
} ) ;
2021-11-18 19:17:00 +01:00
it ( '2050: handling of different rendering direction in subgraphs' , ( ) => {
2021-05-18 22:34:24 +02:00
imgSnapshotTest (
`
flowchart LR
subgraph TOP
direction TB
subgraph B1
direction RL
i1 -- > f1
end
subgraph B2
direction BT
i2 -- > f2
end
end
A -- > TOP -- > B
B1 -- > B2
` ,
2021-11-18 19:17:00 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
2021-05-18 22:34:24 +02:00
) ;
} ) ;
2021-11-25 13:35:24 -08:00
it ( '2388: handling default in the node name' , ( ) => {
imgSnapshotTest (
`
flowchart LR
default - index . js -- > dot . template . js
index . js -- > module - utl . js
` ,
2021-12-08 08:42:12 +01:00
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
) ;
} ) ;
2022-08-27 15:03:29 +02:00
it ( '2824: Clipping of edges' , ( ) => {
imgSnapshotTest (
`
flowchart TD
A -- > B
A -- > C
B -- > C
` ,
{ htmlLabels : true , flowchart : { htmlLabels : true } , securityLevel : 'loose' }
) ;
} ) ;
2022-11-16 19:36:51 -08:00
it ( '1433: should render a titled flowchart with titleTopMargin set to 0' , ( ) => {
imgSnapshotTest (
` ---
2022-11-19 12:48:17 -08:00
title : Simple flowchart
-- -
flowchart TD
A -- > B
2023-02-20 11:19:23 +01:00
` ,
2023-07-25 16:42:34 +02:00
{ flowchart : { titleTopMargin : 10 } }
2023-02-20 11:19:23 +01:00
) ;
} ) ;
2023-02-21 13:27:37 +05:30
it ( '3192: It should be possieble to render flowcharts with invisible edges' , ( ) => {
2023-02-20 11:19:23 +01:00
imgSnapshotTest (
` ---
2023-02-21 13:27:37 +05:30
title : Simple flowchart with invisible edges
2023-02-20 11:19:23 +01:00
-- -
flowchart TD
A ~ ~ ~ B
2022-11-19 12:48:17 -08:00
` ,
2023-07-25 16:42:34 +02:00
{ flowchart : { titleTopMargin : 10 } }
2022-11-16 19:36:51 -08:00
) ;
} ) ;
2023-03-30 20:13:31 +00:00
it ( '4023: Should render html labels with images and-or text correctly' , ( ) => {
imgSnapshotTest (
` flowchart TD
B [ < img src = 'https://mermaid.js.org/mermaid-logo.svg' > ]
B -- > C [ < img src = "https://mermaid.js.org/mermaid-logo.svg" > more text < img src = 'https://mermaid.js.org/mermaid-logo.svg' > ]
B -- > D ( < img src = 'https://mermaid.js.org/mermaid-logo.svg' > some text )
B -- > E ( plain ) ` ,
{ }
) ;
} ) ;
2023-06-16 16:32:11 +02:00
2023-06-16 16:37:34 +02:00
it ( '4439: Should render the graph even if some images are missing' , ( ) => {
2023-06-16 16:32:11 +02:00
imgSnapshotTest (
` flowchart TD
B [ < img > ]
B -- > C [ < img > ] ` ,
{ }
) ;
} ) ;
2023-11-24 09:42:21 +05:30
it ( '5064: Should render when subgraph child has links to outside node and subgraph' , ( ) => {
imgSnapshotTest (
` flowchart TB
Out -- > In
subgraph Sub
In
end
Sub -- > In `
) ;
} ) ;
2023-04-03 12:12:51 +02:00
describe ( 'Markdown strings flowchart (#4220)' , ( ) => {
describe ( 'html labels' , ( ) => {
it ( 'With styling and classes' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": true}} }%%
flowchart LR
A : : : someclass -- > B [ "\`The **cat** in the hat\`" ] : : : someclass
id1 ( Start ) -- > id2 ( Stop )
style id1 fill : # f9f , stroke : # 333 , stroke - width : 4 px
style id2 fill : # bbf , stroke : # f66 , stroke - width : 2 px , color : # fff , stroke - dasharray : 5 5
classDef someclass fill : # f96
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
it ( 'With formatting in a node' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": true}} }%%
flowchart LR
a { "\`The **cat** in the hat\`" } -- 1 o -- > b
a -- 2 o -- > c
a -- 3 o -- > d
g -- 2 i -- > a
d -- 1 i -- > a
h -- 3 i -- > a
b -- > d ( The dog in the hog )
c -- > d
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
it ( 'New line in node and formatted edge label' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": true}} }%%
flowchart LR
b ( " \ ` The dog in **the** hog.(1)
NL \ ` ") --" \` 1o **bold** \` "--> c
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
it ( 'Wrapping long text with a new line' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": true}} }%%
flowchart LR
b ( " \ ` The dog in **the** hog.(1).. a a a a *very long text* about it
Word !
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 . Another line with many , many words . \ ` ") --> c
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
it ( 'Sub graphs and markdown strings' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": true}} }%%
flowchart LR
subgraph "One"
a ( " \ ` The **cat**
in the hat \ ` ") -- "1o" --> b{{" \` The **dog** in the hog \` "}}
end
subgraph "\`**Two**\`"
c ( " \ ` The **cat**
in the hat \ ` ") -- " \` 1o **ipa** \` " --> d("The dog in the hog")
end
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
} ) ;
describe ( 'svg text labels' , ( ) => {
it ( 'With styling and classes' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
A : : : someclass -- > B [ "\`The **cat** in the hat\`" ] : : : someclass
id1 ( Start ) -- > id2 ( Stop )
style id1 fill : # f9f , stroke : # 333 , stroke - width : 4 px
style id2 fill : # bbf , stroke : # f66 , stroke - width : 2 px , color : # fff , stroke - dasharray : 5 5
classDef someclass fill : # f96
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
it ( 'With formatting in a node' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
a { "\`The **cat** in the hat\`" } -- 1 o -- > b
a -- 2 o -- > c
a -- 3 o -- > d
g -- 2 i -- > a
d -- 1 i -- > a
h -- 3 i -- > a
b -- > d ( The dog in the hog )
c -- > d
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
it ( 'New line in node and formatted edge label' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
b ( " \ ` The dog in **the** hog.(1)
NL \ ` ") --" \` 1o **bold** \` "--> c
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
it ( 'Wrapping long text with a new line' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
b ( " \ ` The dog in **the** hog.(1).. a a a a *very long text* about it
Word !
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 . Another line with many , many words . \ ` ") --> c
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
it ( 'Sub graphs and markdown strings' , ( ) => {
imgSnapshotTest (
` %%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
subgraph "One"
a ( " \ ` The **cat**
in the hat \ ` ") -- "1o" --> b{{" \` The **dog** in the hog \` "}}
end
subgraph "\`**Two**\`"
c ( " \ ` The **cat**
in the hat \ ` ") -- " \` 1o **ipa** \` " --> d("The dog in the hog")
end
` ,
2023-06-27 20:58:39 +03:00
{ flowchart : { titleTopMargin : 0 } }
2023-04-03 12:12:51 +02:00
) ;
} ) ;
} ) ;
} ) ;
2023-11-17 20:49:54 -03:00
describe ( 'Subgraph title margins' , ( ) => {
it ( 'Should render subgraphs with title margins set (LR)' , ( ) => {
imgSnapshotTest (
` flowchart LR
subgraph TOP
direction TB
subgraph B1
direction RL
i1 -- > f1
end
subgraph B2
direction BT
i2 -- > f2
end
end
A -- > TOP -- > B
B1 -- > B2
` ,
{ flowchart : { subGraphTitleMargin : { top : 10 , bottom : 5 } } }
) ;
} ) ;
it ( 'Should render subgraphs with title margins set (TD)' , ( ) => {
imgSnapshotTest (
` flowchart TD
subgraph TOP
direction LR
subgraph B1
direction RL
i1 -- > f1
end
subgraph B2
direction BT
i2 -- > f2
end
end
A -- > TOP -- > B
B1 -- > B2
` ,
{ flowchart : { subGraphTitleMargin : { top : 8 , bottom : 16 } } }
) ;
} ) ;
it ( 'Should render subgraphs with title margins set (LR) and htmlLabels set to false' , ( ) => {
imgSnapshotTest (
` flowchart LR
subgraph TOP
direction TB
subgraph B1
direction RL
i1 -- > f1
end
subgraph B2
direction BT
i2 -- > f2
end
end
A -- > TOP -- > B
B1 -- > B2
` ,
{
htmlLabels : false ,
flowchart : { htmlLabels : false , subGraphTitleMargin : { top : 10 , bottom : 5 } } ,
}
) ;
} ) ;
2023-11-27 22:12:41 -03:00
it ( 'Should render subgraphs with title margins and edge labels' , ( ) => {
imgSnapshotTest (
` flowchart LR
subgraph TOP
direction TB
subgraph B1
direction RL
i1 -- lb1 -- > f1
end
subgraph B2
direction BT
i2 -- lb2 -- > f2
end
end
A -- lb3 -- > TOP -- lb4 -- > B
B1 -- lb5 -- > B2
` ,
{ flowchart : { subGraphTitleMargin : { top : 10 , bottom : 5 } } }
) ;
} ) ;
2023-11-17 20:49:54 -03:00
} ) ;
2020-07-11 16:54:00 +10:00
} ) ;