import { waitFor } from '@testing-library/react';
import { renderComponent } from 'lib/test-helpers/render-helper';
import InvalidProductCheck from '../invalid-product-check';
import { DIGITAL_AUDIO, PHYSICAL_AUDIO, IN_CONTENT, OTHER } from '../../../constants';
import { product as productFixture } from '../../../__fixtures__/product';

describe('<InvalidProductCheck>', () => {
    describe('when it renders for an in_content digital audio product', () => {
        const props = {
            product: {
                ...productFixture,
                productConfiguration: DIGITAL_AUDIO,
                status: IN_CONTENT
            }
        };
        test('it returns null', async () => {
            const component = renderComponent({
                Component: InvalidProductCheck, props
            });
            await waitFor(() => {
                expect(component).toMatchSnapshot();
            });
        });
    });

    describe('when it renders for an in_content physical audio product', () => {
        const props = {
            product: {
                ...productFixture,
                productConfiguration: PHYSICAL_AUDIO,
                status: IN_CONTENT
            }
        };
        test('it returns null', async () => {
            const component = renderComponent({
                Component: InvalidProductCheck, props
            });
            await waitFor(() => {
                expect(component).toMatchSnapshot();
            });
        });
    });

    describe('when the product is a music video product', () => {
        const props = {
            product: {
                ...productFixture,
                productConfiguration: 'Music Video'
            }
        };
        test('returns null', async () => {
            const component = renderComponent({
                Component: InvalidProductCheck, props
            });
            await waitFor(() => {
                expect(component).toMatchSnapshot();
            });
        });
    });

    describe('when it renders for an in_content "other" product', () => {
        const props = {
            product: {
                ...productFixture,
                productConfiguration: OTHER,
                status: IN_CONTENT
            }
        };
        test('it returns null', () => {
            const component = renderComponent({
                Component: InvalidProductCheck, props
            });

            expect(component.container).toBeEmptyDOMElement();
        });
    });

    describe('when the product is not in_content', () => {
        const props = {
            product: {
                ...productFixture,
                productConfiguration: DIGITAL_AUDIO,
                status: 'label_processing'
            }
        };
        test('it redirects to the error page', async () => {
            const component = renderComponent({
                Component: InvalidProductCheck, props
            });
            await waitFor(() => {
                expect(component).toMatchSnapshot();
            });
        });
    });
});

