2017-04-11 22:57:57 +08:00
|
|
|
/* eslint-env jasmine */
|
2017-04-11 22:14:25 +08:00
|
|
|
var proxyquire = require('proxyquire')
|
2014-12-04 18:06:54 +01:00
|
|
|
/**
|
|
|
|
* Created by knut on 14-11-18.
|
|
|
|
*/
|
2015-05-26 20:41:53 +02:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var sq = require('./parser/sequenceDiagram').parser
|
2017-04-13 20:16:38 +08:00
|
|
|
var NewD3
|
2015-05-26 20:41:53 +02:00
|
|
|
|
2015-01-20 16:54:22 +11:00
|
|
|
var d3 = {
|
2017-04-11 22:14:25 +08:00
|
|
|
select: function () {
|
2017-04-13 20:16:38 +08:00
|
|
|
return new NewD3()
|
2017-04-11 22:14:25 +08:00
|
|
|
},
|
|
|
|
selectAll: function () {
|
2017-04-13 20:16:38 +08:00
|
|
|
return new NewD3()
|
2017-04-11 22:14:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var sd = proxyquire('./sequenceRenderer', { '../../d3': d3 })
|
2014-12-04 18:06:54 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
function addConf (conf, key, value) {
|
2016-12-07 21:46:58 -05:00
|
|
|
if (value !== undefined) {
|
2017-04-11 22:14:25 +08:00
|
|
|
conf[key] = value
|
2016-12-07 21:46:58 -05:00
|
|
|
}
|
2017-04-11 22:14:25 +08:00
|
|
|
return conf
|
2016-12-07 21:46:58 -05:00
|
|
|
}
|
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var str
|
|
|
|
describe('when parsing a sequenceDiagram', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
sq.yy = require('./sequenceDb')
|
|
|
|
sq.yy.clear()
|
|
|
|
})
|
|
|
|
it('it should handle a sequenceDiagram defintion', function () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob:Hello Bob, how are you?\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(3)
|
|
|
|
expect(messages[0].from).toBe('Alice')
|
|
|
|
expect(messages[2].from).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should handle a sequenceDiagram definition with a title', function () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'title: Diagram Title\n' +
|
|
|
|
'Alice->Bob:Hello Bob, how are you?\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
var title = sq.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 () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob:Hello Bob, how are - you?\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!'
|
2015-01-04 17:56:58 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
2015-01-04 17:56:58 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2015-01-04 17:56:58 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(messages.length).toBe(2)
|
|
|
|
expect(messages[0].from).toBe('Alice')
|
|
|
|
expect(messages[1].from).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should alias participants', function () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'participant A as Alice\n' +
|
|
|
|
'participant B as Bob\n' +
|
|
|
|
'A->B:Hello Bob, how are you?\n' +
|
|
|
|
'B-->A: I am good thanks!'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(Object.keys(actors)).toEqual(['A', 'B'])
|
|
|
|
expect(actors.A.description).toBe('Alice')
|
|
|
|
expect(actors.B.description).toBe('Bob')
|
|
|
|
|
|
|
|
var messages = sq.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 () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice-xBob:Hello Bob, how are you?'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
expect(actors.Bob.description).toBe('Bob')
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(1)
|
|
|
|
expect(messages[0].type).toBe(sq.yy.LINETYPE.SOLID_CROSS)
|
|
|
|
})
|
|
|
|
it('it should handle in async dotted messages', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice--xBob:Hello Bob, how are you?'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
expect(actors.Bob.description).toBe('Bob')
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(1)
|
|
|
|
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED_CROSS)
|
|
|
|
})
|
|
|
|
it('it should handle in arrow messages', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->>Bob:Hello Bob, how are you?'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
expect(actors.Bob.description).toBe('Bob')
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(1)
|
|
|
|
expect(messages[0].type).toBe(sq.yy.LINETYPE.SOLID)
|
|
|
|
})
|
|
|
|
it('it should handle in arrow messages', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice-->>Bob:Hello Bob, how are you?'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
expect(actors.Bob.description).toBe('Bob')
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(1)
|
|
|
|
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED)
|
|
|
|
})
|
|
|
|
it('it should handle actor activation', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice-->>Bob:Hello Bob, how are you?\n' +
|
|
|
|
'activate Bob\n' +
|
|
|
|
'Bob-->>Alice:Hello Alice, I\'m fine and you?\n' +
|
|
|
|
'deactivate Bob'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
expect(actors.Bob.description).toBe('Bob')
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(4)
|
|
|
|
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED)
|
|
|
|
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START)
|
|
|
|
expect(messages[1].from.actor).toBe('Bob')
|
|
|
|
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED)
|
|
|
|
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_END)
|
|
|
|
expect(messages[3].from.actor).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should handle actor one line notation activation', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice-->>+Bob:Hello Bob, how are you?\n' +
|
|
|
|
'Bob-->>- Alice:Hello Alice, I\'m fine and you?'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
expect(actors.Bob.description).toBe('Bob')
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(4)
|
|
|
|
console.log('msg', messages[0])
|
|
|
|
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED)
|
|
|
|
console.log('msg', messages[1])
|
|
|
|
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START)
|
|
|
|
expect(messages[1].from.actor).toBe('Bob')
|
|
|
|
console.log('msg', messages[2])
|
|
|
|
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED)
|
|
|
|
console.log('msg', messages[3])
|
|
|
|
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_END)
|
|
|
|
expect(messages[3].from.actor).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should handle stacked activations', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice-->>+Bob:Hello Bob, how are you?\n' +
|
|
|
|
'Bob-->>+Carol:Carol, let me introduce Alice?\n' +
|
|
|
|
'Bob-->>- Alice:Hello Alice, please meet Carol?\n' +
|
|
|
|
'Carol->>- Bob:Oh Bob, I\'m so happy to be here!'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
expect(actors.Bob.description).toBe('Bob')
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(8)
|
|
|
|
console.log('msg', messages[0])
|
|
|
|
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED)
|
|
|
|
console.log('msg', messages[1])
|
|
|
|
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START)
|
|
|
|
expect(messages[1].from.actor).toBe('Bob')
|
|
|
|
console.log('msg', messages[2])
|
|
|
|
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED)
|
|
|
|
console.log('msg', messages[3])
|
|
|
|
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_START)
|
|
|
|
expect(messages[3].from.actor).toBe('Carol')
|
|
|
|
console.log('msg', messages[5])
|
|
|
|
expect(messages[5].type).toBe(sq.yy.LINETYPE.ACTIVE_END)
|
|
|
|
expect(messages[5].from.actor).toBe('Bob')
|
|
|
|
console.log('msg', messages[7])
|
|
|
|
expect(messages[7].type).toBe(sq.yy.LINETYPE.ACTIVE_END)
|
|
|
|
expect(messages[7].from.actor).toBe('Carol')
|
|
|
|
})
|
|
|
|
it('it should handle comments in a sequenceDiagram', function () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'%% Comment\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!'
|
2014-12-16 20:51:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
2014-12-16 20:51:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2014-12-16 20:51:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08: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 () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n\n' +
|
|
|
|
'%% Comment\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n'
|
2014-12-16 20:51:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
2015-01-04 17:56:58 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2015-01-04 17:56:58 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(messages.length).toBe(3)
|
|
|
|
expect(messages[0].from).toBe('Alice')
|
|
|
|
expect(messages[2].from).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should handle semicolons', function () {
|
|
|
|
str = 'sequenceDiagram;' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'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
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
2015-11-05 18:30:18 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2015-11-05 18:30:18 -05:00
|
|
|
|
2017-04-11 22:14:25 +08: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 () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
' Alice->Bob: Hello Bob, how are you?\n\n' +
|
|
|
|
'%% Comment\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!'
|
2015-01-04 17:56:58 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
2015-01-04 17:56:58 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2015-01-04 17:56:58 +01:00
|
|
|
|
2017-04-11 22:14:25 +08: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 () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
' Alice->Bob: Hello Bob, how are you?\n\n' +
|
|
|
|
'%% Comment\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'participant Alice\n' +
|
|
|
|
'participant Bob\n' +
|
|
|
|
'Alice->John: Hello John, how are you?\n' +
|
|
|
|
' loop Healthcheck\n' +
|
|
|
|
'John->John: Fight against hypochondria\n' +
|
|
|
|
' end\n' +
|
|
|
|
'Note right of John: Rational thoughts<br/>prevail...\n' +
|
|
|
|
' John-->Alice: Great!\n' +
|
|
|
|
' John->Bob: How about you?\n' +
|
|
|
|
'Bob-->John: Jolly good!'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
|
|
|
|
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
|
|
|
|
expect(messages.length).toBe(8)
|
|
|
|
expect(messages[0].from).toBe('Alice')
|
|
|
|
expect(messages[2].from).toBe('John')
|
|
|
|
})
|
|
|
|
it('it should handle notes over a single actor', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'Note over Bob: Bob thinks\n'
|
2015-11-06 02:42:03 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2015-11-06 02:42:03 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[1].from).toBe('Bob')
|
|
|
|
expect(messages[1].to).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should handle notes over multiple actors', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'Note over Alice,Bob: confusion\n' +
|
|
|
|
'Note over Bob,Alice: resolution\n'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
|
|
|
|
var messages = sq.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 a sequenceDiagram', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n\n' +
|
|
|
|
'%% Comment\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'loop Multiple happy responses\n\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2014-12-16 20:51:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
2014-12-16 20:51:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2014-12-16 20:51:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(messages.length).toBe(5)
|
|
|
|
expect(messages[0].from).toBe('Alice')
|
|
|
|
expect(messages[1].from).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should handle opt statements a sequenceDiagram', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n\n' +
|
|
|
|
'%% Comment\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'opt Perhaps a happy response\n\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2015-01-05 13:25:37 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
2015-01-05 13:25:37 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2015-01-05 13:25:37 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(messages.length).toBe(5)
|
|
|
|
expect(messages[0].from).toBe('Alice')
|
|
|
|
expect(messages[1].from).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should handle alt statements a sequenceDiagram', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n\n' +
|
|
|
|
'%% Comment\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'alt isWell\n\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'else isSick\n' +
|
|
|
|
'Bob-->Alice: Feel sick...\n' +
|
|
|
|
'end'
|
2015-01-05 13:25:37 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
2015-01-05 13:25:37 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
actors.Bob.description = 'Bob'
|
2015-01-05 13:25:37 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2015-01-05 13:25:37 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(messages.length).toBe(7)
|
|
|
|
expect(messages[0].from).toBe('Alice')
|
|
|
|
expect(messages[1].from).toBe('Bob')
|
|
|
|
})
|
|
|
|
it('it should handle par statements a sequenceDiagram', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'par Parallel one\n' +
|
|
|
|
'Alice->>Bob: Hello Bob, how are you?\n' +
|
|
|
|
'Bob-->>Alice: I am good thanks!\n' +
|
|
|
|
'and Parallel two\n' +
|
|
|
|
'Alice->>Bob: Are you OK?\n' +
|
|
|
|
'Bob-->>Alice: Fine!\n' +
|
|
|
|
'and Parallel three\n' +
|
|
|
|
'Alice->>Bob: What do you think about it?\n' +
|
|
|
|
'Bob-->>Alice: It\'s good!\n' +
|
|
|
|
'end'
|
2017-02-02 17:16:26 +09:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
var actors = sq.yy.getActors()
|
2017-02-02 17:16:26 +09:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(actors.Alice.description).toBe('Alice')
|
|
|
|
expect(actors.Bob.description).toBe('Bob')
|
2017-02-02 17:16:26 +09:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
2017-02-02 17:16:26 +09:00
|
|
|
|
2017-04-11 22:14:25 +08: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 () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: -:<>,;# comment'
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[0].message).toBe('-:<>,')
|
|
|
|
})
|
|
|
|
it('it should handle special characters in notes', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'Note right of Bob: -:<>,;# comment'
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[1].message).toBe('-:<>,')
|
|
|
|
})
|
|
|
|
it('it should handle special characters in loop', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'loop -:<>,;# comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[1].message).toBe('-:<>,')
|
|
|
|
})
|
|
|
|
it('it should handle special characters in opt', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'opt -:<>,;# comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[1].message).toBe('-:<>,')
|
|
|
|
})
|
|
|
|
it('it should handle special characters in alt', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'alt -:<>,;# comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'else ,<>:-#; comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2015-11-05 21:54:45 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[1].message).toBe('-:<>,')
|
|
|
|
expect(messages[3].message).toBe(',<>:-')
|
|
|
|
})
|
|
|
|
it('it should handle special characters in par', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'par -:<>,;# comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'and ,<>:-#; comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2017-02-02 17:16:26 +09:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2017-02-02 17:16:26 +09:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[1].message).toBe('-:<>,')
|
|
|
|
expect(messages[3].message).toBe(',<>:-')
|
|
|
|
})
|
|
|
|
it('it should handle no-label loop', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'loop\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2015-11-05 23:03:02 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2015-11-05 23:03:02 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[1].message).toBe('')
|
|
|
|
expect(messages[2].message).toBe('I am good thanks!')
|
|
|
|
})
|
|
|
|
it('it should handle no-label opt', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'opt # comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2015-11-05 23:03:02 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
2015-11-05 23:03:02 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var messages = sq.yy.getMessages()
|
|
|
|
expect(messages[1].message).toBe('')
|
|
|
|
expect(messages[2].message).toBe('I am good thanks!')
|
|
|
|
})
|
|
|
|
it('it should handle no-label alt', function () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'alt;' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'else # comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
|
|
|
|
var messages = sq.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 () {
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'par;' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'and # comment\n' +
|
|
|
|
'Bob-->Alice: I am good thanks!\n' +
|
|
|
|
'end'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
|
|
|
|
var messages = sq.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!')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when checking the bounds in a sequenceDiagram', function () {
|
|
|
|
var conf
|
|
|
|
beforeEach(function () {
|
|
|
|
sq.yy = require('./sequenceDb')
|
|
|
|
sq.yy.clear()
|
|
|
|
conf = {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
sd.setConf(conf)
|
|
|
|
})
|
|
|
|
it('it should handle a simple bound call', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
|
|
|
|
sd.bounds.insert(100, 100, 200, 200)
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
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 () {
|
|
|
|
sd.bounds.init()
|
|
|
|
|
|
|
|
sd.bounds.insert(100, 100, 200, 200)
|
|
|
|
sd.bounds.insert(25, 50, 300, 400)
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
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 () {
|
|
|
|
sd.bounds.init()
|
|
|
|
|
|
|
|
sd.bounds.insert(100, 100, 200, 200)
|
|
|
|
sd.bounds.insert(25, 50, 300, 400)
|
|
|
|
sd.bounds.insert(125, 150, 150, 200)
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
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 () {
|
|
|
|
sd.bounds.init()
|
|
|
|
|
|
|
|
sd.bounds.insert(25, 50, 300, 400)
|
|
|
|
sd.bounds.verticalPos = 150
|
|
|
|
sd.bounds.newLoop()
|
|
|
|
sd.bounds.insert(125, 150, 150, 200)
|
|
|
|
|
|
|
|
var loop = sd.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
|
2017-04-11 22:14:25 +08:00
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
sd.bounds.init()
|
|
|
|
|
|
|
|
sd.bounds.insert(100, 100, 1000, 1000)
|
|
|
|
sd.bounds.verticalPos = 200
|
|
|
|
sd.bounds.newLoop()
|
|
|
|
sd.bounds.newLoop()
|
|
|
|
sd.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
|
2017-04-11 22:14:25 +08:00
|
|
|
var loop = sd.bounds.endLoop()
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08: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
|
2017-04-11 22:14:25 +08:00
|
|
|
loop = sd.bounds.endLoop()
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08: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
|
2017-04-11 22:14:25 +08:00
|
|
|
var bounds = sd.bounds.getBounds()
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08: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 () {
|
|
|
|
sd.bounds.init()
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sd.bounds.insert(100, 100, 200, 200)
|
|
|
|
sd.bounds.verticalPos = 200
|
|
|
|
sd.bounds.newLoop()
|
|
|
|
sd.bounds.insert(50, 50, 300, 300)
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var loop = sd.bounds.endLoop()
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08: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
|
2017-04-11 22:14:25 +08:00
|
|
|
var bounds = sd.bounds.getBounds()
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08: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
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
describe('when rendering a sequenceDiagram', function () {
|
|
|
|
var conf
|
|
|
|
beforeEach(function () {
|
|
|
|
sq.yy = require('./sequenceDb')
|
|
|
|
sq.yy.clear()
|
2015-10-12 07:37:02 +02:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
delete global.mermaid_config
|
2015-10-17 12:46:36 +02:00
|
|
|
|
2017-04-13 20:16:38 +08:00
|
|
|
NewD3 = function () {
|
2017-04-11 22:14:25 +08:00
|
|
|
var o = {
|
|
|
|
append: function () {
|
2017-04-13 20:16:38 +08:00
|
|
|
return NewD3()
|
2017-04-11 22:14:25 +08:00
|
|
|
},
|
|
|
|
attr: function () {
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
style: function () {
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
text: function () {
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
0: {
|
|
|
|
0: {
|
|
|
|
getBBox: function () {
|
|
|
|
return {
|
|
|
|
height: 10,
|
|
|
|
width: 20
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return o
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
sd.setConf(conf)
|
|
|
|
});
|
|
|
|
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
|
|
|
|
it('it should handle one actor, when textPlacement is ' + textPlacement, function () {
|
|
|
|
sd.setConf(addConf(conf, 'textPlacement', textPlacement))
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'participant Alice'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
expect(bounds.startx).toBe(0)
|
|
|
|
expect(bounds.starty).toBe(0)
|
|
|
|
expect(bounds.stopx).toBe(conf.width)
|
|
|
|
expect(bounds.stopy).toBe(conf.height)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('it should handle one actor and a centered note', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'participant Alice\n' +
|
|
|
|
'Note over Alice: Alice thinks\n'
|
2015-11-06 02:42:03 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
2015-11-06 02:42:03 -05:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
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
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
|
|
|
|
})
|
|
|
|
it('it should handle one actor and a note to the left', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'participant Alice\n' +
|
|
|
|
'Note left of Alice: Alice thinks'
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
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
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
|
|
|
|
})
|
|
|
|
it('it should handle one actor and a note to the right', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'participant Alice\n' +
|
|
|
|
'Note right of Alice: Alice thinks'
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
2014-12-20 08:40:48 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
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
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
|
|
|
|
})
|
|
|
|
it('it should handle two actors', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
expect(bounds.startx).toBe(0)
|
|
|
|
expect(bounds.starty).toBe(0)
|
|
|
|
expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
|
|
|
|
expect(bounds.stopy).toBe(0 + conf.messageMargin + conf.height)
|
|
|
|
})
|
|
|
|
it('it should handle two actors and two centered shared notes', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'Note over Alice,Bob: Looks\n' +
|
|
|
|
'Note over Bob,Alice: Looks back\n'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
expect(bounds.startx).toBe(0)
|
|
|
|
expect(bounds.starty).toBe(0)
|
|
|
|
expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
|
|
|
|
expect(bounds.stopy).toBe(conf.height + conf.messageMargin + 2 * (conf.boxMargin + 2 * conf.noteMargin + 10))
|
|
|
|
})
|
|
|
|
it('it should draw two actors and two messages', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'Bob->Alice: Fine!'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
expect(bounds.startx).toBe(0)
|
|
|
|
expect(bounds.starty).toBe(0)
|
|
|
|
expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin)
|
|
|
|
expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height)
|
|
|
|
})
|
|
|
|
it('it should draw two actors notes to the right', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'Note right of Bob: Bob thinks\n' +
|
|
|
|
'Bob->Alice: Fine!'
|
2014-12-18 23:17:32 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
2014-12-18 23:17:32 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
expect(bounds.startx).toBe(0)
|
|
|
|
expect(bounds.starty).toBe(0)
|
2014-12-18 23:17:32 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var expStopX = conf.actorMargin + conf.width + (conf.width / 2) + conf.noteMargin + conf.width
|
2014-12-18 23:17:32 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(bounds.stopx).toBe(expStopX)
|
|
|
|
expect(bounds.stopy).toBe(2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin)
|
|
|
|
})
|
|
|
|
it('it should draw two actors notes to the left', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'Note left of Alice: Bob thinks\n' +
|
|
|
|
'Bob->Alice: Fine!'
|
2014-12-18 23:17:32 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
2014-12-18 23:17:32 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
expect(bounds.startx).toBe(-(conf.width / 2) - (conf.actorMargin / 2))
|
|
|
|
expect(bounds.starty).toBe(0)
|
2014-12-18 23:17:32 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
|
|
|
|
expect(bounds.stopy).toBe(2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin)
|
|
|
|
})
|
|
|
|
it('it should draw two loops', function () {
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'Alice->Bob: Hello Bob, how are you?\n' +
|
|
|
|
'loop Cheers\n' +
|
|
|
|
'Bob->Alice: Fine!\n' +
|
|
|
|
'end'
|
2017-04-11 22:14:25 +08:00
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
expect(bounds.startx).toBe(0)
|
|
|
|
expect(bounds.starty).toBe(0)
|
|
|
|
|
|
|
|
expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin)
|
|
|
|
expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height + 3 * conf.boxMargin + conf.boxTextMargin)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when rendering a sequenceDiagram with actor mirror activated', function () {
|
|
|
|
var conf
|
|
|
|
beforeEach(function () {
|
|
|
|
sq.yy = require('./sequenceDb')
|
|
|
|
sq.yy.clear()
|
|
|
|
|
2017-04-13 20:16:38 +08:00
|
|
|
NewD3 = function () {
|
2017-04-11 22:14:25 +08:00
|
|
|
var o = {
|
|
|
|
append: function () {
|
2017-04-13 20:16:38 +08:00
|
|
|
return NewD3()
|
2017-04-11 22:14:25 +08:00
|
|
|
},
|
|
|
|
attr: function () {
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
style: function () {
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
text: function () {
|
|
|
|
return this
|
|
|
|
},
|
|
|
|
0: {
|
|
|
|
0: {
|
|
|
|
getBBox: function () {
|
|
|
|
return {
|
|
|
|
height: 10,
|
|
|
|
width: 20
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return o
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
sd.setConf(conf)
|
|
|
|
});
|
|
|
|
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
|
|
|
|
it('it should handle one actor, when textPlacement is' + textPlacement, function () {
|
|
|
|
sd.setConf(addConf(conf, 'textPlacement', textPlacement))
|
|
|
|
sd.bounds.init()
|
|
|
|
var str = 'sequenceDiagram\n' +
|
2017-04-16 23:48:36 +08:00
|
|
|
'participant Alice'
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
sq.parse(str)
|
|
|
|
sd.draw(str, 'tst')
|
|
|
|
|
|
|
|
var bounds = sd.bounds.getBounds()
|
|
|
|
expect(bounds.startx).toBe(0)
|
|
|
|
expect(bounds.starty).toBe(0)
|
|
|
|
expect(bounds.stopx).toBe(conf.width)
|
|
|
|
expect(bounds.stopy).toBe(2 * conf.height + 2 * conf.boxMargin)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|