Skip to content
Merged
Changes from all commits
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
65 changes: 57 additions & 8 deletions packages/core/__tests__/view/Graph.test.ts
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