import { renderHook, act } from '@testing-library/react';
import { useSigma } from '@react-sigma/core';
import { useSigmaCustomRenderers } from '../../hooks/useSigmaCustomRenderers';
import { useSelectedNodeRenderer } from './useSelectedNodeRenderer';
import { createDefaultGraph } from './defaultGraph.test-data';
import { drawTwoArcs } from '../../rendering/canvas/nodeArc';
jest.mock('@react-sigma/core');
jest.mock('../../hooks/useSigmaCustomRenderers', function () { return ({
    useSigmaCustomRenderers: jest.fn()
}); });
jest.mock('../../rendering/canvas/nodeArc', function () { return ({
    drawTwoArcs: jest.fn().mockImplementation(jest.requireActual('../../rendering/canvas/nodeArc').drawTwoArcs)
}); });
describe('useSelectedNodeRenderer tests', function () {
    var graph;
    var setUp = function (graphArg) {
        graph = graphArg || createDefaultGraph();
        return renderHook(useSelectedNodeRenderer, {
            initialProps: graph
        });
    };
    var getNodeDisplayData = jest.fn().mockImplementation(function (nodeId) { return graph.getNodeAttributes(nodeId); });
    var renderers = {};
    var addRenderers = function (rendererObject) { return Object.assign(renderers, rendererObject); };
    beforeEach(function () {
        useSigmaCustomRenderers.mockReturnValue({
            addRenderers: addRenderers
        });
        useSigma.mockReturnValue({
            getNodeDisplayData: getNodeDisplayData,
            framedGraphToViewport: function (x) { return x; },
            scaleSize: function (x) { return x; }
        });
    });
    afterEach(function () {
        jest.clearAllMocks();
    });
    var getRenderer = function () { return renderers.selectedNodeBorder; };
    it('should not draw 2 arcs for regular node', function () {
        setUp();
        var renderer = getRenderer().renderer;
        var canvas = document.createElement('canvas');
        var canvasContext = canvas.getContext('2d');
        act(function () {
            renderer(canvasContext);
        });
        expect(drawTwoArcs).not.toHaveBeenCalled();
    });
    it('should draw 2 arcs for selected node', function () {
        var graph = createDefaultGraph();
        graph.setNodeAttribute('hcp', 'selected', true);
        setUp(graph);
        var renderer = getRenderer().renderer;
        var canvas = document.createElement('canvas');
        var canvasContext = canvas.getContext('2d');
        act(function () {
            renderer(canvasContext);
        });
        expect(drawTwoArcs).toHaveBeenCalledTimes(1);
    });
});
