import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import { render } from '@testing-library/react';
import SeriesIcon, { Props } from '../SeriesIcon';

describe('<SeriesIcon>', () => {
    const defaultProps: Props = {
        index: 0
    };

    const renderMocked = (props: Partial<Props>) =>
        render(<SeriesIcon {...{ ...defaultProps, ...props }} />);

    test.each([1, 2, 3, 4])('renders svg icon with "bg-dataviz-%s" class', index => {
        const { container } = renderMocked({ index });
        const icon = container.getElementsByClassName(`bg-dataviz-${index}`).item(0);

        expect(icon).toBeVisible();
    });

    test('size is used as height and width', () => {
        const size = 10;
        const index = 1;
        const { container } = renderMocked({ size, index });
        const icon = container.getElementsByClassName(`bg-dataviz-${index}`).item(0);

        if (!icon) throw new Error('Icon not found');
        if (!icon.parentElement) throw new Error('Parent svg element not found');

        expect(icon.parentElement.getAttribute('height')).toEqual(size.toString());
        expect(icon.parentElement.getAttribute('width')).toEqual(size.toString());
    });
});
