Timo Hocker cef87ba4a5
All checks were successful
continuous-integration/drone/push Build is passing
lint
2023-03-25 14:17:58 +01:00

88 lines
2.1 KiB
TypeScript

/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of graphviz-builder which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { Node, Color } from '../../lib';
const serialized_simple
= 'bar_foo [label="baz", style="dashed",'
+ ' shape="tripleoctagon", color="#00ff00"]';
const serialized_table = `bar_foo [label=<<table>
<tr><td>foo</td><td>bar</td><td>baz</td></tr>
<tr><td>bar</td><td>baz</td><td>foo</td></tr>
<tr><td>baz</td><td>foo</td><td>bar</td></tr>
</table>>, style="invis", color="#00ff00"]`;
// eslint-disable-next-line max-lines-per-function
describe ('node', () => {
it ('should serialize simple', () => {
const g = new Node ('foo', 'bar', 'baz');
g.color = Color.green;
g.style = 'dashed';
g.shape = 'tripleoctagon';
const serialized = g.toString ();
expect (g.full_name)
.toEqual ('bar_foo');
expect (serialized)
.toEqual (serialized_simple);
});
it ('should serialize table', () => {
const g = new Node ('foo', 'bar', 'baz');
g.color = Color.green;
g.style = 'invis';
g.table_contents = [
[
'foo',
'bar',
'baz'
],
[
'bar',
'baz',
'foo'
],
[
'baz',
'foo',
'bar'
]
];
g.is_table = true;
const serialized = g.toString ();
expect (g.full_name)
.toEqual ('bar_foo');
expect (serialized)
.toEqual (serialized_table);
});
it ('should adhere to naming convention', () => {
const n = new Node ('invalid.name', 'parent');
expect (n.name)
.toEqual ('invalidname');
});
it ('should throw on invalid name', () => {
expect (() => {
const n = new Node ('564#+-.,/@', 'parent');
return n.toString ();
})
.toThrowError ('invalid node name 564#+-.,/@');
});
it ('should leave numbers after the first letter', () => {
const n = new Node ('i123nvalid.name', 'parent');
expect (n.name)
.toEqual ('i123nvalidname');
});
});