import React from 'react';
import {
    shallow,
    mount
} from 'enzyme';
import sinon from 'sinon';
import { TsdevPieChart } from '../../../index';

describe('Ensure Component TsdevPieChart', () => {

    const component = (<TsdevPieChart />);
    const numberOfProps = 40;

    const dataSet = [
        {
            label: 'one',
            value: 0
        },
        {
            label: 'two',
            value: 40
        },
        {
            label: 'three',
            value: 20
        },
        {
            label: 'four',
            value: 20
        },
        {
            label: 'five',
            value: 10
        }
    ];

    let wrapper;

    it('Ensure component class name', () => {
        wrapper = shallow(component);
        expect(wrapper.getElement(0).props.className).toBe('tsdev-pie-chart');
        wrapper = shallow(<TsdevPieChart subClass="abc def" />);
        expect(wrapper.getElement(0).props.className).toBe('tsdev-pie-chart abc def');
    });

    it('Ensure number of prop-types', () => {
        expect(Object.keys(TsdevPieChart.propTypes).length).toBe(numberOfProps);
    });

    it('Ensure number of properties', () => {
        expect(Object.keys(component.props).length).toBe(numberOfProps);
    });

    describe('| functionality |', () => {

        it('Ensure function: render', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(component);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

    });

    describe('| coverage perposes |', () => {

        it('Ensure function: render', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showLegend
                showSortedValues
                sortDirection="desc"
                showInnerLabels />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: asc', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showLegend
                showSortedValues
                sortDirection="asc"
                showInnerLabels />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: outer labels', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showLabelLine
                showLabelLineDot
                showOuterLabels />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: innerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showInnerLabels
                dataSet={dataSet}
                innerLabelType="label" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: innerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showInnerLabels
                dataSet={dataSet}
                innerLabelType="labelValue" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: innerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showInnerLabels
                dataSet={dataSet}
                innerLabelType="percent" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: innerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showInnerLabels
                dataSet={dataSet}
                innerLabelType="labelPercent" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: innerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showInnerLabels
                dataSet={dataSet}
                innerLabelType="value" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: outerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showOuterLabels
                dataSet={dataSet}
                outerLabelType="label" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: outerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showOuterLabels
                dataSet={dataSet}
                outerLabelType="labelValue" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: outerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showOuterLabels
                dataSet={dataSet}
                outerLabelType="percent" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: outerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showOuterLabels
                dataSet={dataSet}
                outerLabelType="labelPercent" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

        it('Ensure sortDirection: outerLabelType', () => {
            const spy = sinon.spy(TsdevPieChart.prototype, 'render');

            mount(<TsdevPieChart showOuterLabels
                dataSet={dataSet}
                outerLabelType="value" />);
            expect(spy.calledOnce).toBe(true);
            spy.restore();
        });

    });

});
