var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import { drawSelfRelationLoop } from './selfRelationLoop';
describe('Graph selfRelationLoop behavior', function () {
    var context = {
        beginPath: jest.fn(),
        moveTo: jest.fn(),
        lineTo: jest.fn(),
        bezierCurveTo: jest.fn(),
        stroke: jest.fn(),
        closePath: jest.fn(),
        fill: jest.fn()
    };
    var pathInstance = {
        moveTo: jest.fn(),
        bezierCurveTo: jest.fn()
    };
    var edgeData = {
        key: 'id_47',
        size: 1,
        color: 'rgba(0, 0, 0, 0.2)',
        forceLabel: true,
        loop: true,
        hidden: false,
        label: '',
        type: 'line',
        zIndex: 1
    };
    var sourceData = {
        x: 20,
        y: 30,
        size: 1
    };
    beforeEach(function () {
        jest.spyOn(window, 'Path2D').mockImplementation(function () {
            return pathInstance;
        });
    });
    afterEach(function () {
        jest.clearAllMocks();
    });
    it('should call context methods for not arrow edge', function () {
        drawSelfRelationLoop(context, edgeData, sourceData);
        expect(Path2D).toHaveBeenCalled();
        expect(pathInstance.moveTo).toHaveBeenCalledWith(sourceData.x, sourceData.y);
        expect(pathInstance.bezierCurveTo).toHaveBeenCalledWith(15.8, 30, 20, 34.2, sourceData.x, sourceData.y);
        expect(context.stroke).toHaveBeenCalledWith(pathInstance);
    });
    it('should call context methods for arrow edge correctly', function () {
        drawSelfRelationLoop(context, __assign(__assign({}, edgeData), { type: 'arrow' }), sourceData);
        expect(Path2D).toHaveBeenCalled();
        expect(pathInstance.moveTo).toHaveBeenCalledWith(sourceData.x, sourceData.y);
        expect(pathInstance.bezierCurveTo).toHaveBeenCalledWith(sourceData.x, 34.2, 15.8, 30, 16.8, sourceData.y);
        expect(context.stroke).toHaveBeenCalledWith(pathInstance);
        expect(context.beginPath).toHaveBeenCalled();
        expect(context.moveTo).toHaveBeenCalledWith(19, 30);
        expect(context.lineTo).toHaveBeenNthCalledWith(1, 16.8, 29.12);
        expect(context.lineTo).toHaveBeenNthCalledWith(2, 16.8, 30.88);
        expect(context.lineTo).toHaveBeenNthCalledWith(3, 19, 30);
        expect(context.closePath).toHaveBeenCalled();
        expect(context.fill).toHaveBeenCalled();
    });
    it('should call context methods for doubleArrow edge correctly', function () {
        drawSelfRelationLoop(context, __assign(__assign({}, edgeData), { type: 'doubleArrow' }), sourceData);
        expect(Path2D).toHaveBeenCalled();
        expect(context.beginPath).toHaveBeenCalledTimes(2);
        expect(context.fill).toHaveBeenCalledTimes(2);
        expect(context.closePath).toHaveBeenCalledTimes(2);
        expect(context.moveTo).toHaveBeenNthCalledWith(1, sourceData.x, 31);
        expect(context.lineTo).toHaveBeenNthCalledWith(1, 19.119999999999997, 33.2);
        expect(context.lineTo).toHaveBeenNthCalledWith(2, 20.880000000000003, 33.2);
        expect(context.lineTo).toHaveBeenNthCalledWith(3, sourceData.x, 31);
        expect(pathInstance.moveTo).toHaveBeenCalledWith(sourceData.x, 33.2);
        expect(pathInstance.bezierCurveTo).toHaveBeenCalledWith(sourceData.x, 34.2, 15.8, 30, 16.8, sourceData.y);
        expect(context.stroke).toHaveBeenCalledWith(pathInstance);
        expect(context.moveTo).toHaveBeenNthCalledWith(2, 19, sourceData.y);
        expect(context.lineTo).toHaveBeenNthCalledWith(4, 16.8, 29.12);
        expect(context.lineTo).toHaveBeenNthCalledWith(5, 16.8, 30.88);
        expect(context.lineTo).toHaveBeenNthCalledWith(6, 19, sourceData.y);
    });
});
