mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-15 05:19:58 +02:00
fix: tidy tree layout tests
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||||
|
import { executeTidyTreeLayout, validateLayoutData } from './layout.js';
|
||||||
|
import type { LayoutResult } from './types.js';
|
||||||
|
import type { LayoutData, MermaidConfig } from 'mermaid';
|
||||||
|
|
||||||
// Mock non-layered-tidy-tree-layout
|
// Mock non-layered-tidy-tree-layout
|
||||||
vi.mock('non-layered-tidy-tree-layout', () => ({
|
vi.mock('non-layered-tidy-tree-layout', () => ({
|
||||||
@@ -42,10 +45,6 @@ vi.mock('non-layered-tidy-tree-layout', () => ({
|
|||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { executeTidyTreeLayout, validateLayoutData } from './layout.js';
|
|
||||||
import type { LayoutResult } from './types.js';
|
|
||||||
import type { LayoutData, MermaidConfig } from 'mermaid';
|
|
||||||
|
|
||||||
describe('Tidy-Tree Layout Algorithm', () => {
|
describe('Tidy-Tree Layout Algorithm', () => {
|
||||||
let mockConfig: MermaidConfig;
|
let mockConfig: MermaidConfig;
|
||||||
let mockLayoutData: LayoutData;
|
let mockLayoutData: LayoutData;
|
||||||
@@ -209,7 +208,7 @@ describe('Tidy-Tree Layout Algorithm', () => {
|
|||||||
|
|
||||||
describe('executeTidyTreeLayout function', () => {
|
describe('executeTidyTreeLayout function', () => {
|
||||||
it('should execute layout algorithm successfully', async () => {
|
it('should execute layout algorithm successfully', async () => {
|
||||||
const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData, mockConfig);
|
const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData);
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
expect(result.nodes).toBeDefined();
|
expect(result.nodes).toBeDefined();
|
||||||
@@ -219,7 +218,7 @@ describe('Tidy-Tree Layout Algorithm', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return positioned nodes with coordinates', async () => {
|
it('should return positioned nodes with coordinates', async () => {
|
||||||
const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData, mockConfig);
|
const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData);
|
||||||
|
|
||||||
expect(result.nodes.length).toBeGreaterThan(0);
|
expect(result.nodes.length).toBeGreaterThan(0);
|
||||||
result.nodes.forEach((node) => {
|
result.nodes.forEach((node) => {
|
||||||
@@ -231,7 +230,7 @@ describe('Tidy-Tree Layout Algorithm', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return positioned edges with coordinates', async () => {
|
it('should return positioned edges with coordinates', async () => {
|
||||||
const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData, mockConfig);
|
const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData);
|
||||||
|
|
||||||
expect(result.edges.length).toBeGreaterThan(0);
|
expect(result.edges.length).toBeGreaterThan(0);
|
||||||
result.edges.forEach((edge) => {
|
result.edges.forEach((edge) => {
|
||||||
@@ -251,7 +250,7 @@ describe('Tidy-Tree Layout Algorithm', () => {
|
|||||||
edges: [],
|
edges: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(executeTidyTreeLayout(emptyData, mockConfig)).rejects.toThrow(
|
await expect(executeTidyTreeLayout(emptyData)).rejects.toThrow(
|
||||||
'No nodes found in layout data'
|
'No nodes found in layout data'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -259,7 +258,7 @@ describe('Tidy-Tree Layout Algorithm', () => {
|
|||||||
it('should throw error for missing nodes', async () => {
|
it('should throw error for missing nodes', async () => {
|
||||||
const invalidData = { ...mockLayoutData, nodes: [] };
|
const invalidData = { ...mockLayoutData, nodes: [] };
|
||||||
|
|
||||||
await expect(executeTidyTreeLayout(invalidData, mockConfig)).rejects.toThrow(
|
await expect(executeTidyTreeLayout(invalidData)).rejects.toThrow(
|
||||||
'No nodes found in layout data'
|
'No nodes found in layout data'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -271,14 +270,14 @@ describe('Tidy-Tree Layout Algorithm', () => {
|
|||||||
nodes: [mockLayoutData.nodes[0]],
|
nodes: [mockLayoutData.nodes[0]],
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await executeTidyTreeLayout(singleNodeData, mockConfig);
|
const result = await executeTidyTreeLayout(singleNodeData);
|
||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
expect(result.nodes).toHaveLength(1);
|
expect(result.nodes).toHaveLength(1);
|
||||||
expect(result.edges).toHaveLength(0);
|
expect(result.edges).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create bidirectional dual-tree layout with alternating left/right children', async () => {
|
it('should create bidirectional dual-tree layout with alternating left/right children', async () => {
|
||||||
const result = await executeTidyTreeLayout(mockLayoutData, mockConfig);
|
const result = await executeTidyTreeLayout(mockLayoutData);
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
expect(result.nodes).toHaveLength(5);
|
expect(result.nodes).toHaveLength(5);
|
||||||
@@ -383,7 +382,7 @@ describe('Tidy-Tree Layout Algorithm', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await executeTidyTreeLayout(testData, mockConfig);
|
const result = await executeTidyTreeLayout(testData);
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
expect(result.nodes).toHaveLength(3);
|
expect(result.nodes).toHaveLength(3);
|
||||||
|
Reference in New Issue
Block a user