nodes and links rendering (+debug)

This commit is contained in:
Klemek
2019-07-12 16:40:41 +02:00
parent ce5c1e7e11
commit 6830d40385
3 changed files with 265 additions and 24 deletions
+28 -10
View File
@@ -1,10 +1,10 @@
/* jshint -W117 */
const rendering = require('../src/rendering');
describe('getIcon', () => {
const solidCirclePath = 'M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z';
const regularCirclePath = 'M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z';
const solidCirclePath = 'M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z';
const regularCirclePath = 'M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200z';
describe('getIcon', () => {
test('no name', () => {
const res = rendering().getIcon(undefined);
expect(res).toBeNull();
@@ -81,14 +81,32 @@ describe('getIcon', () => {
});
});
describe('getBounds', () => {
test('no nodes', () => {
const res = rendering({beautify: false}).getBounds({});
expect(res).toEqual({w: 0, h: 0});
});
test('1 node', () => {
const res = rendering({beautify: false}).getBounds({
'1': {x: 0, y: 0}
});
expect(res).toEqual({w: 1, h: 1});
});
test('3 nodes', () => {
const res = rendering({beautify: false}).getBounds({
'1': {x: 0, y: 0}, '2': {x: 5, y: 2}, '3': {x: 3, y: 8},
});
expect(res).toEqual({w: 6, h: 9});
});
});
describe('toXML', () => {
test('no data', () => {
const res = rendering({beautify: false}).toXML({}, 0, 0);
expect(res).toEqual('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0"/>');
const res = rendering({beautify: false, scale: 20, 'h-spacing': 1}).toXML({}, {w: 0, h: 0});
expect(res).toEqual('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0" width="0" height="0"/>');
});
test('sample svg data', () => {
const res = rendering({beautify: false}).toXML({
const res = rendering({beautify: false, scale: 2, 'h-spacing': 1}).toXML({
'circle': {
'_attributes': {
'cx': 50,
@@ -96,14 +114,14 @@ describe('toXML', () => {
'r': 50
}
}
}, 100, 100);
expect(res).toEqual('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="50"/></svg>');
}, {w: 100, h: 100});
expect(res).toEqual('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="200" height="200"><circle cx="50" cy="50" r="50"/></svg>');
});
});
describe('compute', () => {
test('no nodes no links', () => {
const res = rendering({beautify: true}).compute({}, []);
expect(res).toEqual('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0">\n</svg>');
const res = rendering({beautify: true, 'h-spacing': 1.2, scale: 20}).compute({}, []);
expect(res).toEqual('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0" width="0" height="0">\n</svg>');
});
});