/* eslint-env jest */
import React from 'react';
import { render, mount } from 'enzyme';
import PriceList from './index';
import noop from 'lodash/noop';
import Typography from '@material-ui/core/Typography';

it('renders correctly with default props', () => {
    const tree = render(<PriceList />);
    expect(tree).toMatchSnapshot();
});

it('renders correctly', () => {
    const priceList = [
        {
            key: 'item',
            selectable: false,
            selected: false,
            label: 'Demo Kaputzenpullover',
            price: '7.000,00 €',
        },
        {
            key: 'global_professional_filecheck',
            selectable: true,
            selected: false,
            label: 'Proficheck',
            price: '49,00 €',
        },
    ];
    const tree = render(
        <PriceList
            amount={200}
            list={priceList}
            totalPrice={'7010 €'}
            taxNote={'inklMwSt.'}
            onSelectableChanged={noop}
        />
    );
    expect(tree).toMatchSnapshot();
});

it('does not show price for optional cost unchecked', async () => {
    const priceList = [
        {
            key: 'item',
            selectable: false,
            selected: false,
            label: 'Demo Kaputzenpullover',
            price: '7.000,00 €',
        },
        {
            key: 'global_professional_filecheck',
            selectable: true,
            selected: false,
            label: 'Proficheck',
            price: '49,00 €',
        },
    ];
    const tree = mount(
        <PriceList
            amount={200}
            list={priceList}
            totalPrice={'7010 €'}
            taxNote={'inklMwSt.'}
            onSelectableChanged={noop}
        />
    );
    const TypoWrapper = tree.find(Typography).last();
    expect(TypoWrapper).toHaveText('');
});

it('shows the price for optional cost selected', () => {
    const priceList = [
        {
            key: 'item',
            selectable: false,
            selected: false,
            label: 'Demo Kaputzenpullover',
            price: '7.000,00 €',
        },
        {
            key: 'global_professional_filecheck',
            selectable: true,
            selected: true,
            label: 'Proficheck',
            price: '49,00 €',
        },
    ];
    const tree = mount(
        <PriceList
            amount={200}
            list={priceList}
            totalPrice={'7010 €'}
            taxNote={'inklMwSt.'}
            onSelectableChanged={noop}
        />
    );
    const TypoWrapper = tree.find(Typography).last();
    expect(TypoWrapper).toHaveText('49,00 €');
});
