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

test: verify AbstractGraph.createHandler factory method delegation by tbouffard · Pull Request #819 · 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
65 changes: 57 additions & 8 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 @@ -24,6 +24,7 @@ import {
EdgeSegmentHandler,
EdgeStyle,
type EdgeStyleFunction,
EdgeStyleRegistry,
ElbowEdgeHandler,
Point,
Rectangle,
Expand All @@ -37,6 +38,13 @@ const customEdgeStyle: EdgeStyleFunction = () => {
// do nothing, we just need a custom implementation that is not registered by default
};

beforeEach(() => {
unregisterAllEdgeStyles();
});
afterAll(() => {
unregisterAllEdgeStyles();
});

describe('isOrthogonal', () => {
test('Style of the CellState, orthogonal: true', () => {
const graph = new BaseGraph();
Expand All @@ -57,12 +65,8 @@ describe('isOrthogonal', () => {

describe('Default builtin styles registered', () => {
beforeEach(() => {
unregisterAllEdgeStyles();
registerDefaultEdgeStyles();
});
afterAll(() => {
unregisterAllEdgeStyles();
});

test.each([
['EntityRelation', EdgeStyle.EntityRelation],
Expand Down Expand Up @@ -128,12 +132,8 @@ const createCellStateOfEdge = (graph: AbstractGraph): CellState =>
describe('createEdgeHandler', () => {
describe('Default builtin styles registered', () => {
beforeEach(() => {
unregisterAllEdgeStyles();
registerDefaultEdgeStyles();
});
afterAll(() => {
unregisterAllEdgeStyles();
});

test.each([
['ElbowConnector', EdgeStyle.ElbowConnector],
Expand Down Expand Up @@ -190,6 +190,55 @@ describe('createEdgeHandler', () => {
expectExactInstanceOfEdgeHandler(graph.createEdgeHandler(cellState, edgeStyle));
}
);

describe('Custom edge handler', () => {
test('default', () => {
class CustomEdgeHandler extends EdgeHandler {}
const edgeStyle = customEdgeStyle;

const graph = new BaseGraph();
graph.createEdgeHandlerInstance = (state) => {
return new CustomEdgeHandler(state);
};

const cellState = createCellStateOfEdge(graph);
expect(graph.createEdgeHandler(cellState, edgeStyle)).toBeInstanceOf(
CustomEdgeHandler
);
});

test('elbow', () => {
class CustomEdgeHandler extends ElbowEdgeHandler {}
const edgeStyle = customEdgeStyle;
EdgeStyleRegistry.add('custom', edgeStyle, { handlerKind: 'elbow' });

const graph = new BaseGraph();
graph.createElbowEdgeHandler = (state) => {
return new CustomEdgeHandler(state);
};

const cellState = createCellStateOfEdge(graph);
expect(graph.createEdgeHandler(cellState, edgeStyle)).toBeInstanceOf(
CustomEdgeHandler
);
});

test('segment', () => {
class CustomEdgeHandler extends EdgeSegmentHandler {}
const edgeStyle = customEdgeStyle;
EdgeStyleRegistry.add('custom', edgeStyle, { handlerKind: 'segment' });

const graph = new BaseGraph();
graph.createEdgeSegmentHandler = (state) => {
return new CustomEdgeHandler(state);
};

const cellState = createCellStateOfEdge(graph);
expect(graph.createEdgeHandler(cellState, edgeStyle)).toBeInstanceOf(
CustomEdgeHandler
);
});
});
});

describe('createHandler', () => {
Expand Down

Back | FazBrowse Home | New Git URL