import React from 'react';
import ReactTestRenderer from 'react-test-renderer';
import { MemoryRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import { ConsoleMock } from 'app/testUtils/consoleMock';
import Enzyme from 'enzyme/build/index';
import Adapter from 'enzyme-adapter-react-16/build/index';
import { AUTH } from 'app/common/store/auth/auth.constants';
import permissions from 'app/common/config/permissions';
import { earningsRoute } from 'app/common/routes';
import { SideMenu } from './sideMenu';

describe('Side menu tests', () => {
  Enzyme.configure({ adapter: new Adapter() });

  jest.mock('app/modules/navigation/components/sideNav', () => ({
    SideNav: () => 'SideNav',
  }));

  process.env = { ADMIN_PANEL_URL:'url' };

  const initialState = {
    app: {
      homeRoute: earningsRoute,
    },
    user: { role: AUTH.ROLE.USER, permissions: permissions[AUTH.ROLE.USER] },
  };
  const mockStore = configureStore();
  let store;
  let consoleMock;

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

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

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

});
