2017-04-11 22:57:57 +08:00
/* eslint-env jasmine */
2019-09-12 12:55:10 -07:00
import { parser } from './parser/sequenceDiagram' ;
import sequenceDb from './sequenceDb' ;
2020-07-29 18:38:59 +02:00
import * as configApi from '../../config' ;
2020-06-17 18:12:01 -04:00
import renderer from './sequenceRenderer' ;
2020-06-11 15:31:59 -04:00
import mermaidAPI from '../../mermaidAPI' ;
2014-12-04 18:06:54 +01:00
2019-09-12 12:55:10 -07:00
function addConf ( conf , key , value ) {
2016-12-07 21:46:58 -05:00
if ( value !== undefined ) {
2019-09-12 12:55:10 -07:00
conf [ key ] = value ;
2016-12-07 21:46:58 -05:00
}
2019-09-12 12:55:10 -07:00
return conf ;
2016-12-07 21:46:58 -05:00
}
2020-06-19 10:52:20 +02:00
2019-09-12 12:55:10 -07:00
describe ( 'when parsing a sequenceDiagram' , function ( ) {
beforeEach ( function ( ) {
parser . yy = sequenceDb ;
parser . yy . clear ( ) ;
} ) ;
2019-10-16 10:08:24 +03:00
it ( 'it should handle a sequenceDiagram definition' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Note right of Bob : Bob thinks
Bob -- > Alice : I am good thanks ! ` ;
2017-04-11 22:14:25 +08:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2017-04-11 22:14:25 +08:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2017-04-11 22:14:25 +08:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 3 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
2020-02-16 15:26:08 +01:00
it ( 'it should not show sequence numbers per default' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Note right of Bob : Bob thinks
Bob -- > Alice : I am good thanks ! ` ;
2020-02-16 15:26:08 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-11 15:31:59 -04:00
expect ( parser . yy . showSequenceNumbers ( ) ) . toBe ( false ) ;
} ) ;
2020-02-16 15:26:08 +01:00
it ( 'it should show sequence numbers when autonumber is enabled' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
autonumber
Alice - > Bob : Hello Bob , how are you ?
Note right of Bob : Bob thinks
Bob -- > Alice : I am good thanks ! ` ;
2020-02-16 15:26:08 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-02-16 15:26:08 +01:00
expect ( parser . yy . showSequenceNumbers ( ) ) . toBe ( true ) ;
} ) ;
2019-09-12 12:55:10 -07:00
it ( 'it should handle a sequenceDiagram definition with a title' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
title : Diagram Title
Alice - > Bob : Hello Bob , how are you ?
Note right of Bob : Bob thinks
Bob -- > Alice : I am good thanks ! ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
const messages = parser . yy . getMessages ( ) ;
const title = parser . yy . getTitle ( ) ;
expect ( messages . length ) . toBe ( 3 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
expect ( title ) . toBe ( 'Diagram Title' ) ;
} ) ;
it ( 'it should space in actor names' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are - you ?
Bob -- > Alice : I am good thanks ! ` ;
2015-01-04 17:56:58 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2015-01-04 17:56:58 +01:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2015-01-04 17:56:58 +01:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 2 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
2020-07-23 20:15:52 -06:00
it ( 'it should handle dashes in actor names' , function ( ) {
const str = `
sequenceDiagram
Alice - in - Wonderland - > Bob : Hello Bob , how are - you ?
Bob -- > Alice - in - Wonderland : I am good thanks ! ` ;
mermaidAPI . parse ( str ) ;
const actors = parser . yy . getActors ( ) ;
expect ( actors [ "Alice-in-Wonderland" ] . description ) . toBe ( 'Alice-in-Wonderland' ) ;
actors . Bob . description = 'Bob' ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 2 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice-in-Wonderland' ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
2019-09-12 12:55:10 -07:00
it ( 'it should alias participants' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant A as Alice
participant B as Bob
A - > B : Hello Bob , how are you ?
B -- > A : I am good thanks ! ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
2021-09-16 20:43:10 +02:00
const actors = parser . yy . getActors ( ) ;
expect ( Object . keys ( actors ) ) . toEqual ( [ 'A' , 'B' ] ) ;
expect ( actors . A . description ) . toBe ( 'Alice' ) ;
expect ( actors . B . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 2 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'A' ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'B' ) ;
} ) ;
it ( 'it should alias a mix of actors and participants apa12' , function ( ) {
const str = `
sequenceDiagram
actor Alice as Alice2
actor Bob
participant John as John2
participant Mandy
Alice - >> Bob : Hi Bob
Bob - >> Alice : Hi Alice
Alice - >> John : Hi John
John - >> Mandy : Hi Mandy
Mandy - >> Joan : Hi Joan ` ;
mermaidAPI . parse ( str ) ;
const actors = parser . yy . getActors ( ) ;
expect ( Object . keys ( actors ) ) . toEqual ( [ 'Alice' , 'Bob' , 'John' , 'Mandy' , 'Joan' ] ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice2' ) ;
expect ( actors . Alice . type ) . toBe ( 'actor' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
expect ( actors . John . type ) . toBe ( 'participant' ) ;
expect ( actors . Joan . type ) . toBe ( 'participant' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 5 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 4 ] . to ) . toBe ( 'Joan' ) ;
} ) ;
it ( 'it should alias actors apa13' , function ( ) {
const str = `
sequenceDiagram
actor A as Alice
actor B as Bob
A - > B : Hello Bob , how are you ?
B -- > A : I am good thanks ! ` ;
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( Object . keys ( actors ) ) . toEqual ( [ 'A' , 'B' ] ) ;
expect ( actors . A . description ) . toBe ( 'Alice' ) ;
expect ( actors . B . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 2 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'A' ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'B' ) ;
} ) ;
it ( 'it should handle in async messages' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - xBob : Hello Bob , how are you ? ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 1 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . SOLID _CROSS ) ;
} ) ;
it ( 'it should handle in async dotted messages' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice -- xBob : Hello Bob , how are you ? ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 1 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED _CROSS ) ;
} ) ;
2021-01-11 23:09:37 +01:00
it ( 'it should handle in sync messages' , function ( ) {
const str = `
sequenceDiagram
Alice - ) Bob : Hello Bob , how are you ? ` ;
mermaidAPI . parse ( str ) ;
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 1 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . SOLID _POINT ) ;
} ) ;
it ( 'it should handle in sync dotted messages' , function ( ) {
const str = `
sequenceDiagram
Alice -- ) Bob : Hello Bob , how are you ? ` ;
mermaidAPI . parse ( str ) ;
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 1 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED _POINT ) ;
} ) ;
2019-09-12 12:55:10 -07:00
it ( 'it should handle in arrow messages' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - >> Bob : Hello Bob , how are you ? ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 1 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . SOLID ) ;
} ) ;
it ( 'it should handle in arrow messages' , function ( ) {
const str = 'sequenceDiagram\n' + 'Alice-->>Bob:Hello Bob, how are you?' ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 1 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED ) ;
} ) ;
it ( 'it should handle actor activation' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice -- >> Bob : Hello Bob , how are you ?
activate Bob
Bob -- >> Alice : Hello Alice , I ' m fine and you ?
deactivate Bob ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 4 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED ) ;
expect ( messages [ 1 ] . type ) . toBe ( parser . yy . LINETYPE . ACTIVE _START ) ;
expect ( messages [ 1 ] . from . actor ) . toBe ( 'Bob' ) ;
expect ( messages [ 2 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED ) ;
expect ( messages [ 3 ] . type ) . toBe ( parser . yy . LINETYPE . ACTIVE _END ) ;
expect ( messages [ 3 ] . from . actor ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle actor one line notation activation' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice -- >> + Bob : Hello Bob , how are you ?
Bob -- >> - Alice : Hello Alice , I ' m fine and you ? ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 4 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED ) ;
expect ( messages [ 1 ] . type ) . toBe ( parser . yy . LINETYPE . ACTIVE _START ) ;
expect ( messages [ 1 ] . from . actor ) . toBe ( 'Bob' ) ;
expect ( messages [ 2 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED ) ;
expect ( messages [ 3 ] . type ) . toBe ( parser . yy . LINETYPE . ACTIVE _END ) ;
expect ( messages [ 3 ] . from . actor ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle stacked activations' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice -- >> + Bob : Hello Bob , how are you ?
Bob -- >> + Carol : Carol , let me introduce Alice ?
Bob -- >> - Alice : Hello Alice , please meet Carol ?
Carol - >> - Bob : Oh Bob , I ' m so happy to be here ! ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 8 ) ;
expect ( messages [ 0 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED ) ;
expect ( messages [ 1 ] . type ) . toBe ( parser . yy . LINETYPE . ACTIVE _START ) ;
expect ( messages [ 1 ] . from . actor ) . toBe ( 'Bob' ) ;
expect ( messages [ 2 ] . type ) . toBe ( parser . yy . LINETYPE . DOTTED ) ;
expect ( messages [ 3 ] . type ) . toBe ( parser . yy . LINETYPE . ACTIVE _START ) ;
expect ( messages [ 3 ] . from . actor ) . toBe ( 'Carol' ) ;
expect ( messages [ 5 ] . type ) . toBe ( parser . yy . LINETYPE . ACTIVE _END ) ;
expect ( messages [ 5 ] . from . actor ) . toBe ( 'Bob' ) ;
expect ( messages [ 7 ] . type ) . toBe ( parser . yy . LINETYPE . ACTIVE _END ) ;
expect ( messages [ 7 ] . from . actor ) . toBe ( 'Carol' ) ;
} ) ;
2020-01-15 20:27:31 +01:00
it ( 'it should handle fail parsing when activating an inactive participant' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant user as End User
participant Server as Server
participant System as System
participant System2 as System2
user - >> + Server : Test
user - >> + Server : Test2
user - >> System : Test
Server - >> - user : Test
Server - >> - user : Test2
% % The following deactivation of Server will fail
Server - >> - user : Test3 ` ;
2020-01-15 20:27:31 +01:00
let error = false ;
try {
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-11 15:31:59 -04:00
} catch ( e ) {
2020-01-15 20:27:31 +01:00
console . log ( e . hash ) ;
error = true ;
}
expect ( error ) . toBe ( true ) ;
} ) ;
2019-09-12 12:55:10 -07:00
it ( 'it should handle comments in a sequenceDiagram' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
Note right of Bob : Bob thinks
Bob -- > Alice : I am good thanks ! ` ;
2014-12-16 20:51:48 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2014-12-16 20:51:48 +01:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2014-12-16 20:51:48 +01:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 3 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle new lines in a sequenceDiagram' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
Note right of Bob : Bob thinks
Bob -- > Alice : I am good thanks !
` ;
2014-12-16 20:51:48 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2015-01-04 17:56:58 +01:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2015-01-04 17:56:58 +01:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 3 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle semicolons' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram ; Alice - > Bob : Hello Bob , how are you ? ; Note right of Bob : Bob thinks ; Bob -- > Alice : I am good thanks ! ; ` ;
2015-11-05 18:30:18 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2015-11-05 18:30:18 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2015-11-05 18:30:18 -05:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 3 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle one leading space in lines in a sequenceDiagram' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
Note right of Bob : Bob thinks
Bob -- > Alice : I am good thanks ! ` ;
2015-01-04 17:56:58 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2015-01-04 17:56:58 +01:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2015-01-04 17:56:58 +01:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 3 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle several leading spaces in lines in a sequenceDiagram' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
Note right of Bob : Bob thinks
Bob -- > Alice : I am good thanks ! ` ;
2017-04-11 22:14:25 +08:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2017-04-11 22:14:25 +08:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2017-04-11 22:14:25 +08:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 3 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle several leading spaces in lines in a sequenceDiagram' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant Alice
participant Bob
Alice - > John : Hello John , how are you ?
loop Healthcheck
John - > John : Fight against hypochondria
end
Note right of John : Rational thoughts < br / > prevail ...
John -- > Alice : Great !
John - > Bob : How about you ?
Bob -- > John : Jolly good ! ` ;
2017-04-11 22:14:25 +08:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2017-04-11 22:14:25 +08:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2017-04-11 22:14:25 +08:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 8 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'John' ) ;
} ) ;
2019-12-21 20:39:32 +01:00
it ( 'it should handle different line breaks' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant 1 as multiline < br > text
participant 2 as multiline < br / > text
participant 3 as multiline < br / > text
participant 4 as multiline < br \ t / > text
1 - >> 2 : multiline < br > text
note right of 2 : multiline < br > text
2 - >> 3 : multiline < br / > text
note right of 3 : multiline < br / > text
3 - >> 4 : multiline < br / > text
note right of 4 : multiline < br / > text
4 - >> 1 : multiline < br \ t / > text
note right of 1 : multiline < br \ t / > text
` ;
2019-12-21 20:39:32 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-12-21 20:39:32 +01:00
const actors = parser . yy . getActors ( ) ;
expect ( actors [ '1' ] . description ) . toBe ( 'multiline<br>text' ) ;
expect ( actors [ '2' ] . description ) . toBe ( 'multiline<br/>text' ) ;
expect ( actors [ '3' ] . description ) . toBe ( 'multiline<br />text' ) ;
2019-12-23 08:52:15 -08:00
expect ( actors [ '4' ] . description ) . toBe ( 'multiline<br \t/>text' ) ;
2019-12-21 20:39:32 +01:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 0 ] . message ) . toBe ( 'multiline<br>text' ) ;
expect ( messages [ 1 ] . message ) . toBe ( 'multiline<br>text' ) ;
expect ( messages [ 2 ] . message ) . toBe ( 'multiline<br/>text' ) ;
expect ( messages [ 3 ] . message ) . toBe ( 'multiline<br/>text' ) ;
expect ( messages [ 4 ] . message ) . toBe ( 'multiline<br />text' ) ;
expect ( messages [ 5 ] . message ) . toBe ( 'multiline<br />text' ) ;
2019-12-23 08:52:15 -08:00
expect ( messages [ 6 ] . message ) . toBe ( 'multiline<br \t/>text' ) ;
expect ( messages [ 7 ] . message ) . toBe ( 'multiline<br \t/>text' ) ;
2019-12-21 20:39:32 +01:00
} ) ;
2020-12-12 02:01:40 -05:00
it ( 'it should handle notes and messages without wrap specified' , function ( ) {
const str = `
sequenceDiagram
participant 1
participant 2
participant 3
participant 4
1 - >> 2 : single - line text
note right of 2 : single - line text
2 - >> 3 : nowrap : single - line text
note right of 3 : nowrap : single - line text
3 - >> 4 : multiline < br / > text
note right of 4 : multiline < br / > text
4 - >> 1 : nowrap : multiline < br / > text
note right of 1 : nowrap : multiline < br / > text
` ;
mermaidAPI . parse ( str ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 0 ] . message ) . toBe ( 'single-line text' ) ;
expect ( messages [ 1 ] . message ) . toBe ( 'single-line text' ) ;
expect ( messages [ 2 ] . message ) . toBe ( 'single-line text' ) ;
expect ( messages [ 3 ] . message ) . toBe ( 'single-line text' ) ;
expect ( messages [ 4 ] . message ) . toBe ( 'multiline<br/>text' ) ;
expect ( messages [ 5 ] . message ) . toBe ( 'multiline<br/>text' ) ;
expect ( messages [ 6 ] . message ) . toBe ( 'multiline<br/>text' ) ;
expect ( messages [ 7 ] . message ) . toBe ( 'multiline<br/>text' ) ;
// wrap indicates whether wrap is specified
expect ( messages [ 0 ] . wrap ) . toBe ( false ) ;
expect ( messages [ 1 ] . wrap ) . toBe ( false ) ;
expect ( messages [ 2 ] . wrap ) . toBe ( false ) ;
expect ( messages [ 3 ] . wrap ) . toBe ( false ) ;
expect ( messages [ 4 ] . wrap ) . toBe ( false ) ;
expect ( messages [ 5 ] . wrap ) . toBe ( false ) ;
expect ( messages [ 6 ] . wrap ) . toBe ( false ) ;
expect ( messages [ 7 ] . wrap ) . toBe ( false ) ;
} )
it ( 'it should handle notes and messages with wrap specified' , function ( ) {
const str = `
sequenceDiagram
participant 1
participant 2
participant 3
participant 4
1 - >> 2 : wrap : single - line text
note right of 2 : wrap : single - line text
2 - >> 3 : wrap : multiline < br / > text
note right of 3 : wrap : multiline < br / > text
` ;
mermaidAPI . parse ( str ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 0 ] . message ) . toBe ( 'single-line text' ) ;
expect ( messages [ 1 ] . message ) . toBe ( 'single-line text' ) ;
expect ( messages [ 2 ] . message ) . toBe ( 'multiline<br/>text' ) ;
expect ( messages [ 3 ] . message ) . toBe ( 'multiline<br/>text' ) ;
expect ( messages [ 0 ] . wrap ) . toBe ( true ) ;
expect ( messages [ 1 ] . wrap ) . toBe ( true ) ;
expect ( messages [ 2 ] . wrap ) . toBe ( true ) ;
expect ( messages [ 3 ] . wrap ) . toBe ( true ) ;
} )
it ( 'it should handle notes and messages with nowrap or line breaks' , function ( ) {
const str = `
sequenceDiagram
participant 1
participant 2
1 - >> 2 : single - line text
note right of 2 : single - line text
` ;
mermaidAPI . parse ( str ) ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 0 ] . message ) . toBe ( 'single-line text' ) ;
expect ( messages [ 1 ] . message ) . toBe ( 'single-line text' ) ;
expect ( messages [ 0 ] . wrap ) . toBe ( false ) ;
expect ( messages [ 1 ] . wrap ) . toBe ( false ) ;
} )
2019-09-12 12:55:10 -07:00
it ( 'it should handle notes over a single actor' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Note over Bob : Bob thinks
` ;
2015-11-06 02:42:03 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2015-11-06 02:42:03 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Bob' ) ;
expect ( messages [ 1 ] . to ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle notes over multiple actors' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Note over Alice , Bob : confusion
Note over Bob , Alice : resolution
` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 1 ] . to ) . toBe ( 'Bob' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
expect ( messages [ 2 ] . to ) . toBe ( 'Alice' ) ;
} ) ;
it ( 'it should handle loop statements' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
Note right of Bob : Bob thinks
loop Multiple happy responses
Bob -- > Alice : I am good thanks !
end ` ;
2014-12-16 20:51:48 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2014-12-16 20:51:48 +01:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2014-12-16 20:51:48 +01:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 5 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should add a rect around sequence' , function ( ) {
2019-07-22 22:47:49 -07:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
rect rgb ( 200 , 255 , 200 )
2019-07-23 21:07:01 -07:00
Note right of Bob : Bob thinks
2019-07-22 22:47:49 -07:00
Bob -- > Alice : I am good thanks
end
2019-09-12 12:55:10 -07:00
` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . type ) . toEqual ( parser . yy . LINETYPE . RECT _START ) ;
expect ( messages [ 1 ] . message ) . toBe ( 'rgb(200, 255, 200)' ) ;
expect ( messages [ 2 ] . type ) . toEqual ( parser . yy . LINETYPE . NOTE ) ;
expect ( messages [ 3 ] . type ) . toEqual ( parser . yy . LINETYPE . DOTTED _OPEN ) ;
expect ( messages [ 4 ] . type ) . toEqual ( parser . yy . LINETYPE . RECT _END ) ;
} ) ;
it ( 'it should allow for nested rects' , function ( ) {
2019-07-23 21:07:01 -07:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
rect rgb ( 200 , 255 , 200 )
rect rgb ( 0 , 0 , 0 )
Note right of Bob : Bob thinks
end
Bob -- > Alice : I am good thanks
end
2019-09-12 12:55:10 -07:00
` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . type ) . toEqual ( parser . yy . LINETYPE . RECT _START ) ;
expect ( messages [ 1 ] . message ) . toBe ( 'rgb(200, 255, 200)' ) ;
expect ( messages [ 2 ] . type ) . toEqual ( parser . yy . LINETYPE . RECT _START ) ;
expect ( messages [ 2 ] . message ) . toBe ( 'rgb(0, 0, 0)' ) ;
expect ( messages [ 3 ] . type ) . toEqual ( parser . yy . LINETYPE . NOTE ) ;
expect ( messages [ 4 ] . type ) . toEqual ( parser . yy . LINETYPE . RECT _END ) ;
expect ( messages [ 5 ] . type ) . toEqual ( parser . yy . LINETYPE . DOTTED _OPEN ) ;
expect ( messages [ 6 ] . type ) . toEqual ( parser . yy . LINETYPE . RECT _END ) ;
} ) ;
it ( 'it should handle opt statements' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
Note right of Bob : Bob thinks
opt Perhaps a happy response
Bob -- > Alice : I am good thanks !
end ` ;
2015-01-05 13:25:37 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2015-01-05 13:25:37 +01:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2015-01-05 13:25:37 +01:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 5 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle alt statements' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
Note right of Bob : Bob thinks
alt isWell
Bob -- > Alice : I am good thanks !
else isSick
Bob -- > Alice : Feel sick ...
end ` ;
2015-01-05 13:25:37 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
2015-01-05 13:25:37 +01:00
2019-09-12 12:55:10 -07:00
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
actors . Bob . description = 'Bob' ;
2015-01-05 13:25:37 +01:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2015-01-05 13:25:37 +01:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 7 ) ;
expect ( messages [ 0 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle alt statements with multiple elses' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
% % Comment
Note right of Bob : Bob thinks
alt isWell
Bob -- > Alice : I am good thanks !
else isSick
Bob -- > Alice : Feel sick ...
else default
Bob -- > Alice : : - )
end ` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages . length ) . toBe ( 9 ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Bob' ) ;
expect ( messages [ 2 ] . type ) . toBe ( parser . yy . LINETYPE . ALT _START ) ;
expect ( messages [ 3 ] . from ) . toBe ( 'Bob' ) ;
expect ( messages [ 4 ] . type ) . toBe ( parser . yy . LINETYPE . ALT _ELSE ) ;
expect ( messages [ 5 ] . from ) . toBe ( 'Bob' ) ;
expect ( messages [ 6 ] . type ) . toBe ( parser . yy . LINETYPE . ALT _ELSE ) ;
expect ( messages [ 7 ] . from ) . toBe ( 'Bob' ) ;
expect ( messages [ 8 ] . type ) . toBe ( parser . yy . LINETYPE . ALT _END ) ;
} ) ;
it ( 'it should handle par statements a sequenceDiagram' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
par Parallel one
Alice - >> Bob : Hello Bob , how are you ?
Bob -- >> Alice : I am good thanks !
and Parallel two
Alice - >> Bob : Are you OK ?
Bob -- >> Alice : Fine !
and Parallel three
Alice - >> Bob : What do you think about it ?
Bob -- >> Alice : It ' s good !
end ` ;
2017-02-02 17:16:26 +09:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
2017-02-02 17:16:26 +09:00
2019-09-12 12:55:10 -07:00
expect ( actors . Alice . description ) . toBe ( 'Alice' ) ;
expect ( actors . Bob . description ) . toBe ( 'Bob' ) ;
2017-02-02 17:16:26 +09:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
2017-02-02 17:16:26 +09:00
2019-09-12 12:55:10 -07:00
expect ( messages . length ) . toBe ( 10 ) ;
expect ( messages [ 0 ] . message ) . toBe ( 'Parallel one' ) ;
expect ( messages [ 1 ] . from ) . toBe ( 'Alice' ) ;
expect ( messages [ 2 ] . from ) . toBe ( 'Bob' ) ;
} ) ;
it ( 'it should handle special characters in signals' , function ( ) {
const str = 'sequenceDiagram\n' + 'Alice->Bob: -:<>,;# comment' ;
2015-11-05 21:54:45 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2015-11-05 21:54:45 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 0 ] . message ) . toBe ( '-:<>,' ) ;
} ) ;
it ( 'it should handle special characters in notes' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Note right of Bob : - : < > , ; # comment ` ;
2015-11-05 21:54:45 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2015-11-05 21:54:45 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '-:<>,' ) ;
} ) ;
it ( 'it should handle special characters in loop' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
loop - : < > , ; # comment
Bob -- > Alice : I am good thanks !
end ` ;
2015-11-05 21:54:45 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2015-11-05 21:54:45 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '-:<>,' ) ;
} ) ;
it ( 'it should handle special characters in opt' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
opt - : < > , ; # comment
Bob -- > Alice : I am good thanks !
end ` ;
2015-11-05 21:54:45 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2015-11-05 21:54:45 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '-:<>,' ) ;
} ) ;
it ( 'it should handle special characters in alt' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
alt - : < > , ; # comment
Bob -- > Alice : I am good thanks !
else , < > : - # ; comment
Bob -- > Alice : I am good thanks !
end ` ;
2015-11-05 21:54:45 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2015-11-05 21:54:45 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '-:<>,' ) ;
expect ( messages [ 3 ] . message ) . toBe ( ',<>:-' ) ;
} ) ;
it ( 'it should handle special characters in par' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
par - : < > , ; # comment
Bob -- > Alice : I am good thanks !
and , < > : - # ; comment
Bob -- > Alice : I am good thanks !
end ` ;
2017-02-02 17:16:26 +09:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2017-02-02 17:16:26 +09:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '-:<>,' ) ;
expect ( messages [ 3 ] . message ) . toBe ( ',<>:-' ) ;
} ) ;
it ( 'it should handle no-label loop' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
loop
Bob -- > Alice : I am good thanks !
end ` ;
2015-11-05 23:03:02 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2015-11-05 23:03:02 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '' ) ;
expect ( messages [ 2 ] . message ) . toBe ( 'I am good thanks!' ) ;
} ) ;
it ( 'it should handle no-label opt' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
opt # comment
Bob -- > Alice : I am good thanks !
end ` ;
2015-11-05 23:03:02 -05:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2015-11-05 23:03:02 -05:00
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '' ) ;
expect ( messages [ 2 ] . message ) . toBe ( 'I am good thanks!' ) ;
} ) ;
it ( 'it should handle no-label alt' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
alt ; Bob -- > Alice : I am good thanks !
else # comment
Bob -- > Alice : I am good thanks !
end ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '' ) ;
expect ( messages [ 2 ] . message ) . toBe ( 'I am good thanks!' ) ;
expect ( messages [ 3 ] . message ) . toBe ( '' ) ;
expect ( messages [ 4 ] . message ) . toBe ( 'I am good thanks!' ) ;
} ) ;
it ( 'it should handle no-label par' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
par ; Bob -- > Alice : I am good thanks !
and # comment
Bob -- > Alice : I am good thanks !
end ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
const messages = parser . yy . getMessages ( ) ;
expect ( messages [ 1 ] . message ) . toBe ( '' ) ;
expect ( messages [ 2 ] . message ) . toBe ( 'I am good thanks!' ) ;
expect ( messages [ 3 ] . message ) . toBe ( '' ) ;
expect ( messages [ 4 ] . message ) . toBe ( 'I am good thanks!' ) ;
} ) ;
2021-08-27 10:56:56 -07:00
it ( 'it should handle links' , function ( ) {
const str = `
sequenceDiagram
participant a as Alice
participant b as Bob
participant c as Charlie
links a : { "Repo" : "https://repo.contoso.com/" , "Dashboard" : "https://dashboard.contoso.com/" }
links b : { "Dashboard" : "https://dashboard.contoso.com/" }
links a : { "On-Call" : "https://oncall.contoso.com/?svc=alice" }
2021-09-10 16:27:07 -07:00
link a : Endpoint @ https : //alice.contoso.com
link a : Swagger @ https : //swagger.contoso.com
link a : Tests @ https : //tests.contoso.com/?svc=alice@contoso.com
2021-08-27 10:56:56 -07:00
` ;
console . log ( str ) ;
mermaidAPI . parse ( str ) ;
const actors = parser . yy . getActors ( ) ;
expect ( actors . a . links [ "Repo" ] ) . toBe ( "https://repo.contoso.com/" ) ;
expect ( actors . b . links [ "Repo" ] ) . toBe ( undefined ) ;
expect ( actors . a . links [ "Dashboard" ] ) . toBe ( "https://dashboard.contoso.com/" ) ;
expect ( actors . b . links [ "Dashboard" ] ) . toBe ( "https://dashboard.contoso.com/" ) ;
expect ( actors . a . links [ "On-Call" ] ) . toBe ( "https://oncall.contoso.com/?svc=alice" ) ;
expect ( actors . c . links [ "Dashboard" ] ) . toBe ( undefined ) ;
2021-09-10 16:27:07 -07:00
expect ( actors . a . links [ "Endpoint" ] ) . toBe ( "https://alice.contoso.com" ) ;
expect ( actors . a . links [ "Swagger" ] ) . toBe ( "https://swagger.contoso.com" ) ;
expect ( actors . a . links [ "Tests" ] ) . toBe ( "https://tests.contoso.com/?svc=alice@contoso.com" ) ;
2021-08-27 10:56:56 -07:00
} ) ;
2021-10-07 21:48:44 +02:00
it ( 'it should handle properties EXPERIMENTAL: USE WITH CAUTION' , function ( ) {
//Be aware that the syntax for "properties" is likely to be changed.
2021-08-27 10:56:56 -07:00
const str = `
sequenceDiagram
participant a as Alice
participant b as Bob
participant c as Charlie
properties a : { "class" : "internal-service-actor" , "icon" : "@clock" }
properties b : { "class" : "external-service-actor" , "icon" : "@computer" }
` ;
console . log ( str ) ;
mermaidAPI . parse ( str ) ;
const actors = parser . yy . getActors ( ) ;
expect ( actors . a . properties [ "class" ] ) . toBe ( "internal-service-actor" ) ;
expect ( actors . b . properties [ "class" ] ) . toBe ( "external-service-actor" ) ;
expect ( actors . a . properties [ "icon" ] ) . toBe ( "@clock" ) ;
expect ( actors . b . properties [ "icon" ] ) . toBe ( "@computer" ) ;
expect ( actors . c . properties [ "class" ] ) . toBe ( undefined ) ;
} ) ;
2019-09-12 12:55:10 -07:00
} ) ;
describe ( 'when checking the bounds in a sequenceDiagram' , function ( ) {
2020-06-26 09:26:56 -04:00
beforeAll ( ( ) => {
let conf = {
2017-04-11 22:14:25 +08:00
diagramMarginX : 50 ,
diagramMarginY : 10 ,
actorMargin : 50 ,
width : 150 ,
2017-04-16 23:48:36 +08:00
// Height of actor boxes
2017-04-11 22:14:25 +08:00
height : 65 ,
boxMargin : 10 ,
messageMargin : 40 ,
boxTextMargin : 15 ,
noteMargin : 25
2019-09-12 12:55:10 -07:00
} ;
2020-06-17 18:14:10 -04:00
mermaidAPI . initialize ( { sequence : conf } ) ;
2020-06-26 09:26:56 -04:00
} ) ;
let conf ;
beforeEach ( function ( ) {
mermaidAPI . reset ( ) ;
parser . yy = sequenceDb ;
parser . yy . clear ( ) ;
2020-06-17 18:14:10 -04:00
renderer . bounds . init ( ) ;
2020-06-26 09:26:56 -04:00
conf = parser . yy . getConfig ( ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should handle a simple bound call' , function ( ) {
renderer . bounds . insert ( 100 , 100 , 200 , 200 ) ;
2020-06-26 09:26:56 -04:00
const { bounds } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 100 ) ;
expect ( bounds . starty ) . toBe ( 100 ) ;
expect ( bounds . stopx ) . toBe ( 200 ) ;
expect ( bounds . stopy ) . toBe ( 200 ) ;
} ) ;
it ( 'it should handle an expanding bound' , function ( ) {
renderer . bounds . insert ( 100 , 100 , 200 , 200 ) ;
renderer . bounds . insert ( 25 , 50 , 300 , 400 ) ;
2020-06-26 09:26:56 -04:00
const { bounds } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 25 ) ;
expect ( bounds . starty ) . toBe ( 50 ) ;
expect ( bounds . stopx ) . toBe ( 300 ) ;
expect ( bounds . stopy ) . toBe ( 400 ) ;
} ) ;
it ( 'it should handle inserts within the bound without changing the outer bounds' , function ( ) {
renderer . bounds . insert ( 100 , 100 , 200 , 200 ) ;
renderer . bounds . insert ( 25 , 50 , 300 , 400 ) ;
renderer . bounds . insert ( 125 , 150 , 150 , 200 ) ;
2020-06-26 09:26:56 -04:00
const { bounds } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 25 ) ;
expect ( bounds . starty ) . toBe ( 50 ) ;
expect ( bounds . stopx ) . toBe ( 300 ) ;
expect ( bounds . stopy ) . toBe ( 400 ) ;
} ) ;
it ( 'it should handle a loop without expanding the area' , function ( ) {
renderer . bounds . insert ( 25 , 50 , 300 , 400 ) ;
renderer . bounds . verticalPos = 150 ;
renderer . bounds . newLoop ( ) ;
renderer . bounds . insert ( 125 , 150 , 150 , 200 ) ;
const loop = renderer . bounds . endLoop ( ) ;
expect ( loop . startx ) . toBe ( 125 - conf . boxMargin ) ;
expect ( loop . starty ) . toBe ( 150 - conf . boxMargin ) ;
expect ( loop . stopx ) . toBe ( 150 + conf . boxMargin ) ;
expect ( loop . stopy ) . toBe ( 200 + conf . boxMargin ) ;
2014-12-20 08:40:48 +01:00
2017-04-16 23:48:36 +08:00
// Check bounds of first loop
2020-06-26 09:26:56 -04:00
const { bounds } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 25 ) ;
expect ( bounds . starty ) . toBe ( 50 ) ;
expect ( bounds . stopx ) . toBe ( 300 ) ;
expect ( bounds . stopy ) . toBe ( 400 ) ;
} ) ;
it ( 'it should handle multiple loops withtout expanding the bounds' , function ( ) {
renderer . bounds . insert ( 100 , 100 , 1000 , 1000 ) ;
renderer . bounds . verticalPos = 200 ;
renderer . bounds . newLoop ( ) ;
renderer . bounds . newLoop ( ) ;
renderer . bounds . insert ( 200 , 200 , 300 , 300 ) ;
2014-12-20 08:40:48 +01:00
2017-04-16 23:48:36 +08:00
// Check bounds of first loop
2019-09-12 12:55:10 -07:00
let loop = renderer . bounds . endLoop ( ) ;
2014-12-20 08:40:48 +01:00
2019-09-12 12:55:10 -07:00
expect ( loop . startx ) . toBe ( 200 - conf . boxMargin ) ;
expect ( loop . starty ) . toBe ( 200 - conf . boxMargin ) ;
expect ( loop . stopx ) . toBe ( 300 + conf . boxMargin ) ;
expect ( loop . stopy ) . toBe ( 300 + conf . boxMargin ) ;
2014-12-20 08:40:48 +01:00
2017-04-16 23:48:36 +08:00
// Check bounds of second loop
2019-09-12 12:55:10 -07:00
loop = renderer . bounds . endLoop ( ) ;
2014-12-20 08:40:48 +01:00
2019-09-12 12:55:10 -07:00
expect ( loop . startx ) . toBe ( 200 - 2 * conf . boxMargin ) ;
expect ( loop . starty ) . toBe ( 200 - 2 * conf . boxMargin ) ;
expect ( loop . stopx ) . toBe ( 300 + 2 * conf . boxMargin ) ;
expect ( loop . stopy ) . toBe ( 300 + 2 * conf . boxMargin ) ;
2014-12-20 08:40:48 +01:00
2017-04-16 23:48:36 +08:00
// Check bounds of first loop
2020-06-26 09:26:56 -04:00
const { bounds } = renderer . bounds . getBounds ( ) ;
2014-12-20 08:40:48 +01:00
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 100 ) ;
expect ( bounds . starty ) . toBe ( 100 ) ;
expect ( bounds . stopx ) . toBe ( 1000 ) ;
expect ( bounds . stopy ) . toBe ( 1000 ) ;
} ) ;
it ( 'it should handle a loop that expands the area' , function ( ) {
2014-12-20 08:40:48 +01:00
2019-09-12 12:55:10 -07:00
renderer . bounds . insert ( 100 , 100 , 200 , 200 ) ;
renderer . bounds . verticalPos = 200 ;
renderer . bounds . newLoop ( ) ;
renderer . bounds . insert ( 50 , 50 , 300 , 300 ) ;
2014-12-20 08:40:48 +01:00
2019-09-12 12:55:10 -07:00
const loop = renderer . bounds . endLoop ( ) ;
2014-12-20 08:40:48 +01:00
2019-09-12 12:55:10 -07:00
expect ( loop . startx ) . toBe ( 50 - conf . boxMargin ) ;
expect ( loop . starty ) . toBe ( 50 - conf . boxMargin ) ;
expect ( loop . stopx ) . toBe ( 300 + conf . boxMargin ) ;
expect ( loop . stopy ) . toBe ( 300 + conf . boxMargin ) ;
2014-12-20 08:40:48 +01:00
2017-04-16 23:48:36 +08:00
// Check bounds after the loop
2020-06-26 09:26:56 -04:00
const { bounds } = renderer . bounds . getBounds ( ) ;
2014-12-20 08:40:48 +01:00
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( loop . startx ) ;
expect ( bounds . starty ) . toBe ( loop . starty ) ;
expect ( bounds . stopx ) . toBe ( loop . stopx ) ;
expect ( bounds . stopy ) . toBe ( loop . stopy ) ;
} ) ;
} ) ;
2015-01-25 14:24:58 +01:00
2020-07-29 18:38:59 +02:00
describe ( 'when rendering a sequenceDiagram APA' , function ( ) {
2020-06-26 09:26:56 -04:00
beforeAll ( ( ) => {
let conf = {
2017-04-11 22:14:25 +08:00
diagramMarginX : 50 ,
diagramMarginY : 10 ,
actorMargin : 50 ,
width : 150 ,
2017-04-16 23:48:36 +08:00
// Height of actor boxes
2017-04-11 22:14:25 +08:00
height : 65 ,
boxMargin : 10 ,
messageMargin : 40 ,
boxTextMargin : 15 ,
2020-06-17 18:12:01 -04:00
noteMargin : 25 ,
2020-06-26 09:26:56 -04:00
wrap : false ,
2020-06-17 18:12:01 -04:00
mirrorActors : false
2019-09-12 12:55:10 -07:00
} ;
2020-07-29 18:38:59 +02:00
configApi . setSiteConfig ( { logLevel : 5 , sequence : conf } ) ;
2020-06-26 09:26:56 -04:00
} ) ;
let conf ;
beforeEach ( function ( ) {
mermaidAPI . reset ( ) ;
2020-07-29 18:38:59 +02:00
conf = {
diagramMarginX : 50 ,
diagramMarginY : 10 ,
actorMargin : 50 ,
width : 150 ,
// Height of actor boxes
height : 65 ,
boxMargin : 10 ,
messageMargin : 40 ,
boxTextMargin : 15 ,
noteMargin : 25 ,
wrap : false ,
mirrorActors : false
} ;
configApi . setSiteConfig ( { logLevel : 5 , sequence : conf } ) ;
2020-06-26 09:26:56 -04:00
parser . yy = sequenceDb ;
parser . yy . clear ( ) ;
2020-07-29 18:38:59 +02:00
// conf = parser.yy.getConfig();
2019-09-12 12:55:10 -07:00
} ) ;
[ 'tspan' , 'fo' , 'old' , undefined ] . forEach ( function ( textPlacement ) {
2020-06-11 15:31:59 -04:00
it ( `
it should handle one actor , when textPlacement is $ { textPlacement } ` , function() {
const str = `
sequenceDiagram
participant Alice ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . reinitialize ( { sequence : { textPlacement : textPlacement } } ) ;
mermaidAPI . parse ( str ) ;
// renderer.setConf(mermaidAPI.getConfig().sequence);
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width ) ;
expect ( bounds . stopy ) . toBe ( conf . height ) ;
} ) ;
2017-04-11 22:14:25 +08:00
} ) ;
2019-09-12 12:55:10 -07:00
it ( 'it should handle same actor with different whitespace properly' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant Alice
participant Alice
participant Alice
` ;
2019-07-14 11:51:20 -04:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-07-14 11:51:20 -04:00
2019-09-12 12:55:10 -07:00
const actors = parser . yy . getActors ( ) ;
expect ( Object . keys ( actors ) ) . toEqual ( [ 'Alice' ] ) ;
} ) ;
it ( 'it should handle one actor and a centered note' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant Alice
Note over Alice : Alice thinks
` ;
2015-11-06 02:42:03 -05:00
2020-06-26 09:26:56 -04:00
expect ( mermaidAPI . getConfig ( ) . sequence . mirrorActors ) . toBeFalsy ( ) ;
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2015-11-06 02:42:03 -05:00
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width ) ;
2017-04-16 23:48:36 +08:00
// 10 comes from mock of text height
2020-06-26 09:26:56 -04:00
expect ( bounds . stopy ) . toBe ( models . lastNote ( ) . stopy ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should handle one actor and a note to the left' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant Alice
Note left of Alice : Alice thinks ` ;
2014-12-20 08:40:48 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2014-12-20 08:40:48 +01:00
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( - ( conf . width / 2 ) - conf . actorMargin / 2 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width ) ;
2017-04-16 23:48:36 +08:00
// 10 comes from mock of text height
2020-06-26 09:26:56 -04:00
expect ( bounds . stopy ) . toBe ( models . lastNote ( ) . stopy ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should handle one actor and a note to the right' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant Alice
Note right of Alice : Alice thinks ` ;
2014-12-20 08:40:48 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2014-12-20 08:40:48 +01:00
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width / 2 + conf . actorMargin / 2 + conf . width ) ;
2017-04-16 23:48:36 +08:00
// 10 comes from mock of text height
2020-06-26 09:26:56 -04:00
expect ( bounds . stopy ) . toBe ( models . lastNote ( ) . stopy ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should handle two actors' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
2020-06-14 11:34:39 -04:00
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ? ` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-14 11:34:39 -04:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-14 11:34:39 -04:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2020-06-14 11:34:39 -04:00
} ) ;
it ( 'it should handle two actors with init directive' , function ( ) {
const str = `
2020-06-11 15:31:59 -04:00
% % { init : { 'logLevel' : 0 } } % %
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ? ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-14 11:34:39 -04:00
const mermaid = mermaidAPI . getConfig ( ) ;
expect ( mermaid . logLevel ) . toBe ( 0 ) ;
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2020-06-14 11:34:39 -04:00
} ) ;
it ( 'it should handle two actors with init directive with multiline directive' , function ( ) {
const str = `
% % { init : { 'logLevel' : 0 } } % %
sequenceDiagram
% % {
wrap
} % %
Alice - > Bob : Hello Bob , how are you ? ` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-14 11:34:39 -04:00
renderer . draw ( str , 'tst' ) ;
2020-06-17 18:14:10 -04:00
const msgs = parser . yy . getMessages ( ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-14 11:34:39 -04:00
const mermaid = mermaidAPI . getConfig ( ) ;
expect ( mermaid . logLevel ) . toBe ( 0 ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2020-06-17 18:14:10 -04:00
expect ( msgs . every ( v => v . wrap ) ) . toBe ( true ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should handle two actors and two centered shared notes' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Note over Alice , Bob : Looks
Note over Bob , Alice : Looks back
` ;
2020-07-29 18:38:59 +02:00
// mermaidAPI.initialize({logLevel:0})
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-06-26 09:26:56 -04:00
expect ( bounds . stopy ) . toBe ( models . lastNote ( ) . stopy ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should draw two actors and two messages' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Bob - > Alice : Fine ! ` ;
2019-09-12 12:55:10 -07:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
2020-06-26 09:26:56 -04:00
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should draw two actors notes to the right' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Note right of Bob : Bob thinks
Bob - > Alice : Fine ! ` ;
2014-12-18 23:17:32 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2014-12-18 23:17:32 +01:00
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
2014-12-18 23:17:32 +01:00
2019-09-12 12:55:10 -07:00
const expStopX = conf . actorMargin + conf . width + conf . width / 2 + conf . noteMargin + conf . width ;
2014-12-18 23:17:32 +01:00
2019-09-12 12:55:10 -07:00
expect ( bounds . stopx ) . toBe ( expStopX ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should draw two actors notes to the left' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
Note left of Alice : Bob thinks
Bob - > Alice : Fine ! ` ;
2014-12-18 23:17:32 +01:00
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2014-12-18 23:17:32 +01:00
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( - ( conf . width / 2 ) - conf . actorMargin / 2 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
2014-12-18 23:17:32 +01:00
2019-09-12 12:55:10 -07:00
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2019-09-12 12:55:10 -07:00
} ) ;
2020-06-11 15:31:59 -04:00
it ( 'it should draw two actors notes to the left with text wrapped (inline)' , function ( ) {
const str = `
sequenceDiagram
Alice - >> Bob : wrap : Hello Bob , how are you ? If you are not available right now , I can leave you a message . Please get back to me as soon as you can !
Note left of Alice : Bob thinks
Bob - >> Alice : Fine ! ` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-11 15:31:59 -04:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-11 15:31:59 -04:00
const msgs = parser . yy . getMessages ( ) ;
expect ( bounds . startx ) . toBe ( - ( conf . width / 2 ) - conf . actorMargin / 2 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( msgs [ 0 ] . wrap ) . toBe ( true ) ;
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2020-06-11 15:31:59 -04:00
} ) ;
it ( 'it should draw two actors notes to the left with text wrapped (directive)' , function ( ) {
const str = `
% % { init : { 'theme' : 'dark' } } % %
sequenceDiagram
% % { wrap } % %
Alice - >> Bob : Hello Bob , how are you ? If you are not available right now , I can leave you a message . Please get back to me as soon as you can !
Note left of Alice : Bob thinks
Bob - >> Alice : Fine ! ` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-11 15:31:59 -04:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-11 15:31:59 -04:00
const msgs = parser . yy . getMessages ( ) ;
const mermaid = mermaidAPI . getConfig ( ) ;
expect ( bounds . startx ) . toBe ( - ( conf . width / 2 ) - conf . actorMargin / 2 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( mermaid . theme ) . toBe ( 'dark' ) ;
expect ( msgs . every ( v => v . wrap ) ) . toBe ( true ) ;
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2020-06-11 15:31:59 -04:00
} ) ;
it ( 'it should draw two actors notes to the left with text wrapped and the init directive sets the theme to dark' , function ( ) {
const str = `
% % { init : { 'theme' : 'dark' } } % %
sequenceDiagram
% % { wrap } % %
Alice - >> Bob : Hello Bob , how are you ? If you are not available right now , I can leave you a message . Please get back to me as soon as you can !
Note left of Alice : Bob thinks
Bob - >> Alice : Fine ! ` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-11 15:31:59 -04:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-11 15:31:59 -04:00
const msgs = parser . yy . getMessages ( ) ;
const mermaid = mermaidAPI . getConfig ( ) ;
expect ( bounds . startx ) . toBe ( - ( conf . width / 2 ) - conf . actorMargin / 2 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( mermaid . theme ) . toBe ( 'dark' ) ;
expect ( msgs . every ( v => v . wrap ) ) . toBe ( true ) ;
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2020-06-11 15:31:59 -04:00
} ) ;
2020-06-17 18:14:10 -04:00
it ( 'it should draw two actors, notes to the left with text wrapped and the init directive sets the theme to dark and fontFamily to Menlo, fontSize to 18, and fontWeight to 800' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
2021-08-05 18:58:42 +02:00
% % { init : { "theme" : "dark" , 'config' : { "fontFamily" : "Menlo" , "fontSize" : 18 , "messageFontWeight" : 400 , "wrap" : true } } } % %
2020-06-11 15:31:59 -04:00
sequenceDiagram
Alice - >> Bob : Hello Bob , how are you ? If you are not available right now , I can leave you a message . Please get back to me as soon as you can !
Note left of Alice : Bob thinks
Bob - >> Alice : Fine ! ` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-11 15:31:59 -04:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-11 15:31:59 -04:00
const msgs = parser . yy . getMessages ( ) ;
const mermaid = mermaidAPI . getConfig ( ) ;
expect ( bounds . startx ) . toBe ( - ( conf . width / 2 ) - conf . actorMargin / 2 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( mermaid . theme ) . toBe ( 'dark' ) ;
2020-06-17 18:12:01 -04:00
expect ( mermaid . sequence . fontFamily ) . toBe ( 'Menlo' ) ;
expect ( mermaid . sequence . fontSize ) . toBe ( 18 ) ;
2021-08-05 18:58:42 +02:00
expect ( mermaid . sequence . messageFontWeight ) . toBe ( 400 ) ;
2020-06-11 15:31:59 -04:00
expect ( msgs . every ( v => v . wrap ) ) . toBe ( true ) ;
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-07-04 12:35:34 +02:00
expect ( bounds . stopy ) . toBe ( models . lastMessage ( ) . stopy + 10 ) ;
2020-06-11 15:31:59 -04:00
} ) ;
2019-09-12 12:55:10 -07:00
it ( 'it should draw two loops' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , how are you ?
loop Cheers
Bob - > Alice : Fine !
end ` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
2020-06-11 15:31:59 -04:00
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
2020-06-26 09:26:56 -04:00
expect ( bounds . stopy ) . toBe ( models . lastLoop ( ) . stopy ) ;
2019-09-12 12:55:10 -07:00
} ) ;
it ( 'it should draw background rect' , function ( ) {
2019-07-23 21:28:48 -07:00
const str = `
sequenceDiagram
Alice - > Bob : Hello Bob , are you alright ?
rect rgb ( 0 , 0 , 0 )
Bob - > Alice : I feel surrounded by darkness
end
2019-09-12 12:55:10 -07:00
` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
2020-06-26 09:26:56 -04:00
expect ( bounds . stopx ) . toBe ( conf . width * 2 + conf . actorMargin ) ;
expect ( bounds . stopy ) . toBe ( models . lastLoop ( ) . stopy ) ;
2019-09-12 12:55:10 -07:00
} ) ;
} ) ;
2020-06-19 08:19:03 -04:00
2019-09-12 12:55:10 -07:00
describe ( 'when rendering a sequenceDiagram with actor mirror activated' , function ( ) {
2020-06-26 09:26:56 -04:00
beforeAll ( ( ) => {
let conf = {
2017-04-11 22:14:25 +08:00
diagramMarginX : 50 ,
diagramMarginY : 10 ,
actorMargin : 50 ,
width : 150 ,
2017-04-16 23:48:36 +08:00
// Height of actor boxes
2017-04-11 22:14:25 +08:00
height : 65 ,
boxMargin : 10 ,
messageMargin : 40 ,
boxTextMargin : 15 ,
noteMargin : 25 ,
mirrorActors : true ,
2017-04-16 23:48:36 +08:00
// Depending on css styling this might need adjustment
// Prolongs the edge of the diagram downwards
2017-04-11 22:14:25 +08:00
bottomMarginAdj : 1
2019-09-12 12:55:10 -07:00
} ;
2020-06-26 09:26:56 -04:00
2020-06-17 18:14:10 -04:00
mermaidAPI . initialize ( { sequence : conf } ) ;
2020-06-26 09:26:56 -04:00
} ) ;
let conf ;
beforeEach ( function ( ) {
mermaidAPI . reset ( ) ;
parser . yy = sequenceDb ;
parser . yy . clear ( ) ;
conf = parser . yy . getConfig ( ) ;
2020-06-17 18:14:10 -04:00
renderer . bounds . init ( ) ;
2019-09-12 12:55:10 -07:00
} ) ;
[ 'tspan' , 'fo' , 'old' , undefined ] . forEach ( function ( textPlacement ) {
it ( 'it should handle one actor, when textPlacement is' + textPlacement , function ( ) {
2020-06-17 18:14:10 -04:00
mermaidAPI . initialize ( addConf ( conf , 'textPlacement' , textPlacement ) ) ;
2019-09-12 12:55:10 -07:00
renderer . bounds . init ( ) ;
2020-06-11 15:31:59 -04:00
const str = `
sequenceDiagram
participant Alice ` ;
2020-06-26 09:26:56 -04:00
renderer . bounds . init ( ) ;
mermaidAPI . parse ( str ) ;
2019-09-12 12:55:10 -07:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2019-09-12 12:55:10 -07:00
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
expect ( bounds . stopx ) . toBe ( conf . width ) ;
2021-09-18 10:05:53 +02:00
expect ( bounds . stopy ) . toBe ( models . lastActor ( ) . y + models . lastActor ( ) . height + conf . boxMargin ) ;
2019-09-12 12:55:10 -07:00
} ) ;
2017-04-11 22:14:25 +08:00
} ) ;
2019-09-12 12:55:10 -07:00
} ) ;
2020-06-11 15:31:59 -04:00
describe ( 'when rendering a sequenceDiagram with directives' , function ( ) {
2020-06-26 09:26:56 -04:00
beforeAll ( function ( ) {
let conf = {
2020-06-11 15:31:59 -04:00
diagramMarginX : 50 ,
diagramMarginY : 10 ,
actorMargin : 50 ,
width : 150 ,
height : 65 ,
boxMargin : 10 ,
messageMargin : 40 ,
boxTextMargin : 15 ,
noteMargin : 25
} ;
2020-06-17 18:14:10 -04:00
mermaidAPI . initialize ( { sequence : conf } ) ;
2020-06-26 09:26:56 -04:00
} ) ;
let conf ;
beforeEach ( function ( ) {
mermaidAPI . reset ( ) ;
parser . yy = sequenceDb ;
parser . yy . clear ( ) ;
conf = parser . yy . getConfig ( ) ;
2020-06-17 18:14:10 -04:00
renderer . bounds . init ( ) ;
2020-06-11 15:31:59 -04:00
} ) ;
2020-06-15 01:11:56 +02:00
it ( 'it should handle one actor, when theme is dark and logLevel is 1 DX1' , function ( ) {
2020-06-11 15:31:59 -04:00
const str = `
% % { init : { "theme" : "dark" , "logLevel" : 1 } } % %
sequenceDiagram
% % { wrap } % %
participant Alice
` ;
2020-06-26 09:26:56 -04:00
renderer . bounds . init ( ) ;
mermaidAPI . parse ( str ) ;
2020-06-11 15:31:59 -04:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-11 15:31:59 -04:00
const mermaid = mermaidAPI . getConfig ( ) ;
expect ( mermaid . theme ) . toBe ( 'dark' ) ;
expect ( mermaid . logLevel ) . toBe ( 1 ) ;
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
2021-09-18 10:05:53 +02:00
expect ( bounds . stopy ) . toBe ( models . lastActor ( ) . y + models . lastActor ( ) . height + mermaid . sequence . boxMargin ) ;
2020-06-11 15:31:59 -04:00
} ) ;
it ( 'it should handle one actor, when logLevel is 3' , function ( ) {
const str = `
% % { initialize : { "logLevel" : 3 } } % %
sequenceDiagram
participant Alice
` ;
2020-06-26 09:26:56 -04:00
mermaidAPI . parse ( str ) ;
2020-06-11 15:31:59 -04:00
renderer . draw ( str , 'tst' ) ;
2020-06-26 09:26:56 -04:00
const { bounds , models } = renderer . bounds . getBounds ( ) ;
2020-06-11 15:31:59 -04:00
const mermaid = mermaidAPI . getConfig ( ) ;
expect ( mermaid . logLevel ) . toBe ( 3 ) ;
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . startx ) . toBe ( 0 ) ;
expect ( bounds . starty ) . toBe ( 0 ) ;
2021-09-18 10:05:53 +02:00
expect ( bounds . stopy ) . toBe ( models . lastActor ( ) . y + models . lastActor ( ) . height + mermaid . sequence . boxMargin ) ;
2020-06-11 15:31:59 -04:00
} ) ;
} ) ;