import React from 'react';
import { render } from '@testing-library/react';
import Spinner from '../Spinner';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';

const spinnerTrueProps = {
    common: {
        showSpinner: true,
    },
};

const spinnerFalseProps = {
    common: {
        showSpinner: false,
    },
};

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

describe('Spinner', () => {
    it('render spinner', () => {
        const store = mockStore(spinnerTrueProps);
        const { getByTestId } = render(
            <Provider store={store}>
                <Spinner />
            </Provider>,
        );
        expect(getByTestId('spinner')).toBeInTheDocument();
    });

    it('when showSpinner is false', () => {
        const store = mockStore(spinnerFalseProps);
        const { container } = render(
            <Provider store={store}>
                <Spinner />
            </Provider>,
        );
        expect(container.firstChild).toMatchSnapshot();
    });
});
