Skip to content

Commit 3219da6

Browse files
committed
test(react): cover the Graphviz diagrams plugin
Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f0e818c commit 3219da6

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it } from 'node:test';
3+
4+
import { u } from 'unist-builder';
5+
6+
import transformDiagrams, { renderDiagram } from '../diagrams.mjs';
7+
8+
const transform = transformDiagrams();
9+
10+
describe('transformDiagrams', () => {
11+
it('renders ```dot code blocks as inline SVG', () => {
12+
const tree = u('root', [u('code', { lang: 'dot' }, 'digraph { a -> b }')]);
13+
14+
transform(tree);
15+
16+
const [node] = tree.children;
17+
assert.equal(node.type, 'html');
18+
assert.match(
19+
node.value,
20+
/^<div class="diagram">[\s\S]*<svg[\s\S]*<\/svg><\/div>$/
21+
);
22+
assert.doesNotMatch(node.value, /\n\s*\n/);
23+
});
24+
25+
it('leaves other code blocks alone', () => {
26+
const code = u('code', { lang: 'js' }, 'a -> b');
27+
const tree = u('root', [code]);
28+
29+
transform(tree);
30+
31+
assert.equal(tree.children[0], code);
32+
});
33+
});
34+
35+
describe('renderDiagram', () => {
36+
it('renders a diagram per color scheme for themed colors', () => {
37+
const html = renderDiagram('digraph { a [color="${#000000|#ffffff}"] }');
38+
39+
assert.match(html, /class="diagram diagram-light"/);
40+
assert.match(html, /class="diagram diagram-dark"/);
41+
assert.match(html.split('diagram-dark')[0], /#000000/);
42+
assert.match(html.split('diagram-dark')[1], /#ffffff/);
43+
});
44+
});

0 commit comments

Comments
 (0)