FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: improve the Graph tests by tbouffard · Pull Request #797 · maxGraph/maxGraph · GitHub

forked from jgraph/mxgraph
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
43 changes: 29 additions & 14 deletions packages/core/__tests__/view/Graph.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,63 @@ limitations under the License.
import { describe, expect, test } from '@jest/globals';
import {
AbstractGraph,
BaseGraph,
Cell,
CellState,
EdgeHandler,
EdgeSegmentHandler,
EdgeStyle,
type EdgeStyleFunction,
ElbowEdgeHandler,
Point,
Rectangle,
RectangleShape,
VertexHandler,
} from '../../src';
import { createGraphWithoutPlugins } from '../utils';

const customEdgeStyle: EdgeStyleFunction = () => {
// do nothing, we just need a custom implementation that is not registered by default
};

describe('isOrthogonal', () => {
test('Style of the CellState, orthogonal: true', () => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
const cellState = new CellState(graph.view, null, { orthogonal: true });
expect(graph.isOrthogonal(cellState)).toBeTruthy();
});

test('No style in the CellState', () => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
expect(graph.isOrthogonal(new CellState())).toBeFalsy();
});

test.each([undefined, null])('Style of the CellState, orthogonal: %s', (orthogonal) => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
const cellState = new CellState(graph.view, null, { orthogonal });
expect(graph.isOrthogonal(cellState)).toBeFalsy();
});

test.each([
['EntityRelation', EdgeStyle.EntityRelation],
['ElbowConnector', EdgeStyle.ElbowConnector],
['ManhattanConnector', EdgeStyle.ManhattanConnector],
['OrthogonalConnector', EdgeStyle.OrthConnector],
['SegmentConnector', EdgeStyle.SegmentConnector],
['SideToSide', EdgeStyle.SideToSide],
['TopToBottom', EdgeStyle.TopToBottom],
])('Style of the CellState, edgeStyle: %s', (_name, edgeStyle) => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
const cellState = new CellState(graph.view, null, { edgeStyle });
expect(graph.isOrthogonal(cellState)).toBeTruthy();
});

test('Style of the CellState, edgeStyle: Loop', () => {
const graph = createGraphWithoutPlugins();
test.each([
['custom', customEdgeStyle],
['Loop', EdgeStyle.Loop],
])('Style of the CellState, edgeStyle: %s', (_name, edgeStyle) => {
const graph = new BaseGraph();
const cellState = new CellState(graph.view, null, {
edgeStyle: EdgeStyle.Loop,
edgeStyle: edgeStyle,
});
expect(graph.isOrthogonal(cellState)).toBeFalsy();
});
Expand All @@ -85,7 +96,7 @@ describe('createEdgeHandler', () => {
['SideToSide', EdgeStyle.SideToSide],
['TopToBottom', EdgeStyle.TopToBottom],
])('Expect ElbowEdgeHandler for edgeStyle: %s', (_name, edgeStyle) => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
const cellState = createCellState(graph, true);
expect(graph.createEdgeHandler(cellState, edgeStyle)).toBeInstanceOf(
ElbowEdgeHandler
Expand All @@ -97,32 +108,36 @@ describe('createEdgeHandler', () => {
['OrthogonalConnector', EdgeStyle.OrthConnector],
['SegmentConnector', EdgeStyle.SegmentConnector],
])('Expect EdgeSegmentHandler for edgeStyle: %s', (_name, edgeStyle) => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
const cellState = createCellState(graph, true);
expect(graph.createEdgeHandler(cellState, edgeStyle)).toBeInstanceOf(
EdgeSegmentHandler
);
});

test.each([
['custom', customEdgeStyle],
['EntityRelation', EdgeStyle.EntityRelation],
['null', null],
])('Expect EdgeHandler for edgeStyle: %s', (_name, edgeStyle) => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
const cellState = createCellState(graph, true);
expect(graph.createEdgeHandler(cellState, edgeStyle)).toBeInstanceOf(EdgeHandler);
const edgeHandler = graph.createEdgeHandler(cellState, edgeStyle);
expect(edgeHandler).toBeInstanceOf(EdgeHandler);
expect(edgeHandler).not.toBeInstanceOf(EdgeSegmentHandler);
expect(edgeHandler).not.toBeInstanceOf(ElbowEdgeHandler);
});
});

describe('createHandler', () => {
test('Expect VertexHandler', () => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
const cellState = createCellState(graph, false);
expect(graph.createHandler(cellState)).toBeInstanceOf(VertexHandler);
});

test('Expect EdgeHandler', () => {
const graph = createGraphWithoutPlugins();
const graph = new BaseGraph();
const cellState = createCellState(graph, true);
expect(graph.createHandler(cellState)).toBeInstanceOf(EdgeHandler);
});
Expand Down

Back | FazBrowse Home | New Git URL