2014-11-27 18:21:15 +01:00
|
|
|
/**
|
|
|
|
* Created by knut on 14-11-26.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Created by knut on 14-11-23.
|
|
|
|
*/
|
|
|
|
var rewire = require("rewire");
|
|
|
|
var utils = require("./utils");
|
|
|
|
|
2014-11-28 18:08:36 +01:00
|
|
|
describe('when using main and ',function() {
|
|
|
|
describe('when detecting chart type ',function() {
|
|
|
|
var main;
|
|
|
|
beforeEach(function () {
|
|
|
|
var MockBrowser = require('mock-browser').mocks.MockBrowser;
|
|
|
|
var mock = new MockBrowser();
|
2014-11-27 18:21:15 +01:00
|
|
|
|
2014-11-28 18:08:36 +01:00
|
|
|
// and in the run-code inside some object
|
|
|
|
document = mock.getDocument();
|
2014-11-27 18:21:15 +01:00
|
|
|
|
|
|
|
|
2014-11-28 18:08:36 +01:00
|
|
|
});
|
2014-12-02 18:36:16 +01:00
|
|
|
xit('should have a version', function () {
|
2014-11-28 18:08:36 +01:00
|
|
|
div = document.createElement('div');
|
|
|
|
mermaid_config ={startOnLoad : false};
|
|
|
|
main = rewire('./main');
|
2014-12-01 21:12:14 +01:00
|
|
|
expect(main.version()).toBe('0.2.10');
|
2014-11-28 18:08:36 +01:00
|
|
|
});
|
|
|
|
it('should not call start anything with an empty document', function () {
|
|
|
|
|
|
|
|
mermaid_config ={startOnLoad : false};
|
|
|
|
main = rewire('./main');
|
2014-11-27 18:21:15 +01:00
|
|
|
|
2014-11-28 18:08:36 +01:00
|
|
|
spyOn(utils,'detectType');
|
|
|
|
expect(utils.detectType).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
it('should start something with a mermaid document', function () {
|
|
|
|
mermaid_config ={startOnLoad : false};
|
|
|
|
main = rewire('./main');
|
2014-12-04 17:58:05 +01:00
|
|
|
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>';
|
2014-11-28 18:08:36 +01:00
|
|
|
spyOn(utils,'detectType');
|
|
|
|
mermaid.init();
|
|
|
|
expect(utils.detectType).toHaveBeenCalled();
|
|
|
|
});
|
2014-11-27 18:21:15 +01:00
|
|
|
|
|
|
|
});
|
2014-11-28 18:08:36 +01:00
|
|
|
|
2014-12-01 20:41:08 +01:00
|
|
|
describe('when calling addEdges ',function() {
|
2014-11-28 18:08:36 +01:00
|
|
|
var main;
|
2014-12-01 20:41:08 +01:00
|
|
|
var graph = require('./graphDb');
|
|
|
|
var flow = require('./parser/flow');
|
|
|
|
|
2014-11-28 18:08:36 +01:00
|
|
|
beforeEach(function () {
|
2014-12-01 20:41:08 +01:00
|
|
|
mermaid_config ={startOnLoad : false};
|
|
|
|
var MockBrowser = require('mock-browser').mocks.MockBrowser;
|
|
|
|
var mock = new MockBrowser();
|
|
|
|
flow.parser.yy =graph;
|
|
|
|
graph.clear();
|
|
|
|
document = mock.getDocument();
|
2014-11-28 18:08:36 +01:00
|
|
|
main = rewire('./main');
|
|
|
|
});
|
2014-12-01 20:41:08 +01:00
|
|
|
it('it should handle edges with text', function () {
|
|
|
|
var res = flow.parser.parse('graph TD;A-->|text ex|B;');
|
|
|
|
var vert = flow.parser.yy.getVertices();
|
|
|
|
var edges = flow.parser.yy.getEdges();
|
|
|
|
|
|
|
|
var mockG = {
|
|
|
|
setEdge:function(start, end,options,name){
|
|
|
|
expect(start).toBe('A');
|
|
|
|
expect(end).toBe('B');
|
2014-12-09 20:42:31 +01:00
|
|
|
expect(options.arrowhead).toBe('normal');
|
2014-12-01 20:41:08 +01:00
|
|
|
expect(options.label.match('text ex')).toBeTruthy();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
main.addEdges(edges,mockG);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle edges without text', function () {
|
|
|
|
var res = flow.parser.parse('graph TD;A-->B;');
|
|
|
|
var vert = flow.parser.yy.getVertices();
|
|
|
|
var edges = flow.parser.yy.getEdges();
|
|
|
|
|
2014-11-28 18:08:36 +01:00
|
|
|
var mockG = {
|
2014-12-01 20:41:08 +01:00
|
|
|
setEdge:function(start, end,options,name){
|
|
|
|
expect(start).toBe('A');
|
|
|
|
expect(end).toBe('B');
|
2014-12-09 20:42:31 +01:00
|
|
|
expect(options.arrowhead).toBe('normal');
|
2014-12-01 20:41:08 +01:00
|
|
|
}
|
2014-11-28 18:08:36 +01:00
|
|
|
};
|
2014-12-01 20:41:08 +01:00
|
|
|
|
|
|
|
main.addEdges(edges,mockG);
|
2014-11-28 18:08:36 +01:00
|
|
|
});
|
|
|
|
|
2014-12-01 20:41:08 +01:00
|
|
|
|
|
|
|
it('should handle open-ended edges', function () {
|
|
|
|
var res = flow.parser.parse('graph TD;A---B;');
|
|
|
|
var vert = flow.parser.yy.getVertices();
|
|
|
|
var edges = flow.parser.yy.getEdges();
|
|
|
|
|
|
|
|
var mockG = {
|
|
|
|
setEdge:function(start, end,options,name){
|
|
|
|
expect(start).toBe('A');
|
|
|
|
expect(end).toBe('B');
|
|
|
|
expect(options.arrowhead).toBe('none');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
main.addEdges(edges,mockG);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle edges with styles defined', function () {
|
|
|
|
var res = flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;');
|
|
|
|
var vert = flow.parser.yy.getVertices();
|
|
|
|
var edges = flow.parser.yy.getEdges();
|
|
|
|
|
|
|
|
var mockG = {
|
|
|
|
setEdge:function(start, end,options,name){
|
|
|
|
expect(start).toBe('A');
|
|
|
|
expect(end).toBe('B');
|
|
|
|
expect(options.arrowhead).toBe('none');
|
|
|
|
expect(options.style).toBe('stroke:val1;stroke-width:val2;');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
main.addEdges(edges,mockG);
|
|
|
|
});
|
|
|
|
it('should handle edges with text and styles defined', function () {
|
|
|
|
var res = flow.parser.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;');
|
|
|
|
var vert = flow.parser.yy.getVertices();
|
|
|
|
var edges = flow.parser.yy.getEdges();
|
|
|
|
|
|
|
|
var mockG = {
|
|
|
|
setEdge:function(start, end,options,name){
|
|
|
|
expect(start).toBe('A');
|
|
|
|
expect(end).toBe('B');
|
|
|
|
expect(options.arrowhead).toBe('none');
|
|
|
|
expect(options.label.match('the text')).toBeTruthy();
|
|
|
|
expect(options.style).toBe('stroke:val1;stroke-width:val2;');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
main.addEdges(edges,mockG);
|
|
|
|
});
|
2014-11-27 18:21:15 +01:00
|
|
|
});
|
|
|
|
});
|