/
basic.spec.js
59 lines (56 loc) · 1.67 KB
/
basic.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-env jest */
import fs from 'fs'
import path from 'path'
import onml from 'onml'
import xmlFormat from 'xml-formatter'
import { graph2svg } from '../../src/index'
describe('node basic', () => {
test('one node', async () => {
const graph = {
id: 'root',
children: [
{
id: 'n1',
width: 100,
height: 100
}
]
}
const svg = await graph2svg(graph)
fs.writeFileSync(path.join(__dirname, 'output', 'one-node.svg'), xmlFormat(svg))
expect(onml.parse(svg)).toEqual(
['svg', { xmlns: 'http://www.w3.org/2000/svg', width: '150', height: '150' },
['svg', { x: '25', y: '25', width: '100', height: '100' },
['rect', { x: '1', y: '1', width: '98', height: '98', stroke: 'black', fill: 'none' }]
]
])
})
test('two nodes', async () => {
const graph = {
id: 'root',
children: [
{
id: 'n1',
width: 100,
height: 100
},
{
id: 'n2',
width: 100,
height: 100
}
]
}
const svg = await graph2svg(graph)
fs.writeFileSync(path.join(__dirname, 'output', 'two-nodes.svg'), xmlFormat(svg))
expect(onml.parse(svg)).toEqual(
['svg', { xmlns: 'http://www.w3.org/2000/svg', width: '275', height: '150' },
['svg', { x: '25', y: '25', width: '100', height: '100' },
['rect', { x: '1', y: '1', width: '98', height: '98', stroke: 'black', fill: 'none' }]
],
['svg', { x: '150', y: '25', width: '100', height: '100' },
['rect', { x: '1', y: '1', width: '98', height: '98', stroke: 'black', fill: 'none' }]
]
])
})
})