2019-12-10 03:48:12 +01:00
|
|
|
import { addVertices } from './flowRenderer';
|
2019-10-04 22:03:20 -04:00
|
|
|
import { setConfig } from '../../config';
|
|
|
|
|
|
|
|
setConfig({
|
|
|
|
flowchart: {
|
|
|
|
htmlLabels: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('the flowchart renderer', function() {
|
|
|
|
describe('when adding vertices to a graph', function() {
|
|
|
|
[
|
|
|
|
['round', 'rect', 5],
|
|
|
|
['square', 'rect'],
|
|
|
|
['diamond', 'question'],
|
|
|
|
['hexagon', 'hexagon'],
|
|
|
|
['odd', 'rect_left_inv_arrow'],
|
|
|
|
['lean_right', 'lean_right'],
|
|
|
|
['lean_left', 'lean_left'],
|
|
|
|
['trapezoid', 'trapezoid'],
|
|
|
|
['inv_trapezoid', 'inv_trapezoid'],
|
|
|
|
['odd_right', 'rect_left_inv_arrow'],
|
|
|
|
['circle', 'circle'],
|
|
|
|
['ellipse', 'ellipse'],
|
2019-12-08 16:51:47 +01:00
|
|
|
['stadium', 'stadium'],
|
2019-10-04 22:03:20 -04:00
|
|
|
['group', 'rect']
|
|
|
|
].forEach(function([type, expectedShape, expectedRadios = 0]) {
|
|
|
|
it(`should add the correct shaped node to the graph for vertex type ${type}`, function() {
|
|
|
|
const addedNodes = [];
|
|
|
|
const mockG = {
|
|
|
|
setNode: function(id, object) {
|
|
|
|
addedNodes.push([id, object]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
addVertices(
|
|
|
|
{
|
|
|
|
v1: {
|
|
|
|
type,
|
|
|
|
id: 'my-node-id',
|
|
|
|
classes: [],
|
|
|
|
styles: [],
|
|
|
|
text: 'my vertex text'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mockG,
|
|
|
|
'svg-id'
|
|
|
|
);
|
|
|
|
expect(addedNodes).toHaveLength(1);
|
|
|
|
expect(addedNodes[0][0]).toEqual('my-node-id');
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('id', 'my-node-id');
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('labelType', 'svg');
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('shape', expectedShape);
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('rx', expectedRadios);
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('ry', expectedRadios);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-10-14 22:10:58 +02:00
|
|
|
|
|
|
|
[
|
|
|
|
[['fill:#fff'], 'fill:#fff;', ''],
|
|
|
|
[['color:#ccc'], 'color:#ccc;', 'color:#ccc;'],
|
|
|
|
[['fill:#fff', 'color:#ccc'], 'fill:#fff;color:#ccc;', 'color:#ccc;'],
|
|
|
|
[
|
|
|
|
['fill:#fff', 'color:#ccc', 'text-align:center'],
|
|
|
|
'fill:#fff;color:#ccc;text-align:center;',
|
|
|
|
'color:#ccc;text-align:center;'
|
|
|
|
]
|
|
|
|
].forEach(function([style, expectedStyle, expectedLabelStyle]) {
|
2019-10-14 22:36:55 +02:00
|
|
|
it(`should add the styles to style and/or labelStyle for style ${style}`, function() {
|
2019-10-14 22:10:58 +02:00
|
|
|
const addedNodes = [];
|
|
|
|
const mockG = {
|
|
|
|
setNode: function(id, object) {
|
|
|
|
addedNodes.push([id, object]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
addVertices(
|
|
|
|
{
|
|
|
|
v1: {
|
|
|
|
type: 'rect',
|
|
|
|
id: 'my-node-id',
|
|
|
|
classes: [],
|
|
|
|
styles: style,
|
|
|
|
text: 'my vertex text'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mockG,
|
|
|
|
'svg-id'
|
|
|
|
);
|
|
|
|
expect(addedNodes).toHaveLength(1);
|
|
|
|
expect(addedNodes[0][0]).toEqual('my-node-id');
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('id', 'my-node-id');
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('labelType', 'svg');
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('style', expectedStyle);
|
|
|
|
expect(addedNodes[0][1]).toHaveProperty('labelStyle', expectedLabelStyle);
|
|
|
|
});
|
|
|
|
});
|
2019-10-04 22:03:20 -04:00
|
|
|
});
|