Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
900 changes: 900 additions & 0 deletions __tests__/basic.test.ts

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion __tests__/compact-box.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import { compactBox } from '../src/index';
import { expectSVGToMatchSnapshot, collectNodes } from './utils/svg-generator';
import { expectSVGToMatchSnapshot, expectStyledSVGToMatchSnapshot, collectNodes } from './utils/svg-generator';
import complexTree from './fixtures/complex-tree.json';
import basicTree from './fixtures/basic-tree.json';

describe('CompactBox Layout', () => {
Expand Down Expand Up @@ -126,4 +127,44 @@ describe('CompactBox Layout', () => {
expect(result.data.customProp).toBe('custom value');
expect(result.children![0].data.anotherProp).toBe(123);
});

it('complex styled snapshots (nodeType × colorScheme)', () => {
const nodeTypes = ['rect', 'square', 'circle'] as const;
const colorSchemes = ['depth', 'branch', 'single'] as const;

const getNodeWidth = (nodeType: string) => {
switch (nodeType) {
case 'circle':
case 'square':
return 20; // nodeSize*2
case 'rect':
default:
return 100; // nodeSize*10
}
};
const getNodeHeight = () => 20; // nodeSize*2

nodeTypes.forEach((nodeType) => {
colorSchemes.forEach((colorScheme) => {
const result = compactBox(complexTree as any, {
direction: 'TB',
getHGap: () => 50,
getVGap: () => 50,
getWidth: () => getNodeWidth(nodeType),
getHeight: () => getNodeHeight(),
} as any);

expect(result).toBeDefined();
const filename = `compactBox-${nodeType}-${colorScheme}.svg`;
expectStyledSVGToMatchSnapshot(result, filename, {
nodeType: nodeType as any,
colorScheme: colorScheme as any,
nodeSize: 10,
showLabels: true,
width: 900,
height: 700,
});
});
});
});
});
44 changes: 43 additions & 1 deletion __tests__/dendrogram.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import { dendrogram } from '../src/index';
import { expectSVGToMatchSnapshot, collectNodes } from './utils/svg-generator';
import { expectSVGToMatchSnapshot, expectStyledSVGToMatchSnapshot, collectNodes } from './utils/svg-generator';
import complexTree from './fixtures/complex-tree.json';
import basicTree from './fixtures/basic-tree.json';

describe('Dendrogram Layout', () => {
Expand Down Expand Up @@ -91,4 +92,45 @@ describe('Dendrogram Layout', () => {

expectSVGToMatchSnapshot(result, 'dendrogram-wide.svg');
});

it('complex styled snapshots (nodeType × colorScheme)', () => {
const nodeTypes = ['rect', 'square', 'circle'] as const;
const colorSchemes = ['depth', 'branch', 'single'] as const;

const nodeSize = 10;
const getNodeWidth = (nodeType: string) => {
switch (nodeType) {
case 'circle':
case 'square':
return nodeSize * 2;
case 'rect':
default:
return nodeSize * 10;
}
};
const getNodeHeight = () => nodeSize * 2;

nodeTypes.forEach((nodeType) => {
colorSchemes.forEach((colorScheme) => {
const result = dendrogram(complexTree as any, {
direction: 'TB',
getHGap: () => 50,
getVGap: () => 50,
getWidth: () => getNodeWidth(nodeType),
getHeight: () => getNodeHeight(),
} as any);

expect(result).toBeDefined();
const filename = `dendrogram-${nodeType}-${colorScheme}.svg`;
expectStyledSVGToMatchSnapshot(result, filename, {
nodeType: nodeType as any,
colorScheme: colorScheme as any,
nodeSize,
showLabels: true,
width: 900,
height: 700,
});
});
});
});
});
40 changes: 40 additions & 0 deletions __tests__/fixtures/complex-tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "root",
"children": [
{
"id": "branch-1",
"children": [
{
"id": "leaf-1-1",
"children": [
{ "id": "leaf-1-1-1" },
{ "id": "leaf-1-1-2" },
{ "id": "leaf-1-1-3" }
]
},
{ "id": "leaf-1-2" }
]
},
{
"id": "branch-2",
"children": [
{ "id": "leaf-2-1" },
{ "id": "leaf-2-2" },
{ "id": "leaf-2-3" },
{ "id": "leaf-2-4" }
]
},
{
"id": "branch-3",
"children": [
{
"id": "leaf-3-1",
"children": [
{ "id": "leaf-3-1-1" },
{ "id": "leaf-3-1-2" }
]
}
]
}
]
}
45 changes: 44 additions & 1 deletion __tests__/indented.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import { indented } from '../src/index';
import { expectSVGToMatchSnapshot, collectNodes } from './utils/svg-generator';
import { expectSVGToMatchSnapshot, expectStyledSVGToMatchSnapshot, collectNodes } from './utils/svg-generator';
import complexTree from './fixtures/complex-tree.json';
import basicTree from './fixtures/basic-tree.json';

describe('Indented Layout', () => {
Expand Down Expand Up @@ -125,4 +126,46 @@ describe('Indented Layout', () => {
expect(result).toBeDefined();
expectSVGToMatchSnapshot(result, 'indented-custom-sizes.svg');
});

it('complex styled snapshots (nodeType × colorScheme)', () => {
const nodeTypes = ['rect', 'square', 'circle'] as const;
const colorSchemes = ['depth', 'branch', 'single'] as const;

const nodeSize = 10;
const getNodeWidth = (nodeType: string) => {
switch (nodeType) {
case 'circle':
case 'square':
return nodeSize * 2;
case 'rect':
default:
return nodeSize * 10;
}
};
const getNodeHeight = () => nodeSize * 2;

nodeTypes.forEach((nodeType) => {
colorSchemes.forEach((colorScheme) => {
const result = indented(complexTree as any, {
direction: 'LR',
indent: 50,
getHGap: () => 50,
getVGap: () => 50,
getWidth: () => getNodeWidth(nodeType),
getHeight: () => getNodeHeight(),
} as any);

expect(result).toBeDefined();
const filename = `indented-${nodeType}-${colorScheme}.svg`;
expectStyledSVGToMatchSnapshot(result, filename, {
nodeType: nodeType as any,
colorScheme: colorScheme as any,
nodeSize,
showLabels: true,
width: 900,
height: 700,
});
});
});
});
});
44 changes: 43 additions & 1 deletion __tests__/mindmap.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import { mindmap } from '../src/index';
import { expectSVGToMatchSnapshot, collectNodes } from './utils/svg-generator';
import { expectSVGToMatchSnapshot, expectStyledSVGToMatchSnapshot, collectNodes } from './utils/svg-generator';
import complexTree from './fixtures/complex-tree.json';
import mindmapTree from './fixtures/mindmap-tree.json';
import basicTree from './fixtures/basic-tree.json';

Expand Down Expand Up @@ -138,4 +139,45 @@ describe('Mindmap Layout', () => {

expectSVGToMatchSnapshot(result, 'mindmap-auto-sides.svg');
});

it('complex styled snapshots (nodeType × colorScheme)', () => {
const nodeTypes = ['rect', 'square', 'circle'] as const;
const colorSchemes = ['depth', 'branch', 'single'] as const;

const nodeSize = 10;
const getNodeWidth = (nodeType: string) => {
switch (nodeType) {
case 'circle':
case 'square':
return nodeSize * 2;
case 'rect':
default:
return nodeSize * 10;
}
};
const getNodeHeight = () => nodeSize * 2;

nodeTypes.forEach((nodeType) => {
colorSchemes.forEach((colorScheme) => {
const result = mindmap(complexTree as any, {
direction: 'H',
getHGap: () => 50,
getVGap: () => 50,
getWidth: () => getNodeWidth(nodeType),
getHeight: () => getNodeHeight(),
} as any);

expect(result).toBeDefined();
const filename = `mindmap-${nodeType}-${colorScheme}.svg`;
expectStyledSVGToMatchSnapshot(result, filename, {
nodeType: nodeType as any,
colorScheme: colorScheme as any,
nodeSize,
showLabels: true,
width: 900,
height: 700,
});
});
});
});
});
55 changes: 55 additions & 0 deletions __tests__/snapshots/compactBox-circle-branch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions __tests__/snapshots/compactBox-circle-depth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading