import React from 'react';
import ReactTestRenderer from 'react-test-renderer';
import Adapter from 'enzyme-adapter-react-16/build/index';
import Enzyme from 'enzyme/build/index';
import { ConsoleMock } from 'app/testUtils/consoleMock';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import { TceDevelopmentModal } from './tceDevelopmentModal';

jest.mock('app/shared/store/ui/uiSelectors', () => ({
  getScreenWidth: jest.fn(() => 1300), 
}));

jest.mock('../store/tceDevelopment.selectors', () => ({
  createTceDevelopmentIsLoadingSelector: jest.fn(() => () => false),
  selectTceDevelopmentModalData: jest.fn(() => [
    {
      period: '13-12-2020',
      scrubber: true,
      poolPoints: 1,
      bunkerAdjustmentFactor: 2,
      poolPointsEarnings: 3,
      bunkerAdjustment: 4,
      scrubberBonus: 5,
      waf: 6,
      specialCompensation: 7,
      tce: 8,
    },
    {
      period: '13-11-2020',
      scrubber: false,
      poolPoints: 12,
      bunkerAdjustmentFactor: 14,
      poolPointsEarnings: 15,
      bunkerAdjustment: 16,
      scrubberBonus: 17,
      waf: 18,
      specialCompensation: 19,
      tce: 20,
    },
  ],
  ),
  selectTceDevelopmentCommonData: jest.fn(() => ({
    date: 'Period',
    poolPoints: 13,
    bunkerAdjustmentFactor: 7,
    hasScrubber: false,
  })),
  selectVesselName: jest.fn(() => (
    'Sichem Beijing')),
  selectTceDevelopmentModalState: jest.fn(() => true),
}));

jest.mock('app/modules/vesselDetails/root/store/vesselDetails.selectors', () => ({
  selectVesselName: jest.fn(() => 'Vessel Name'),
}));

describe('Tce development modal', () => {
  Enzyme.configure({ adapter: new Adapter() });

  const mockStore = configureStore();
  let store;

  let consoleMock;

  beforeEach(() => {
    consoleMock = new ConsoleMock();
    store = mockStore({});
  });

  afterEach(() => {
    consoleMock.destroy();
  });


  it('renders correctly', () => {
    const tree = ReactTestRenderer
      .create(
        <Provider store={store}>
          <TceDevelopmentModal />
        </Provider>
      )
      .toJSON();
    expect(tree).toMatchSnapshot();
    expect(console.error).not.toBeCalled();
  });
});
