import configureStore from 'redux-mock-store';
import React from 'react';
import ReactTestRenderer from 'react-test-renderer';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import ReportsPage from './reports.page';
import * as selectors from '../../reports/store/bi.selectors';

jest.mock('powerbi-report-component', () => ({
  Report: jest.fn(() => 'Report'),
}));

jest.mock('../store/bi.selectors');

describe('Reports page tests', () => {
  const mockedSelectors = selectors as jest.Mocked<typeof selectors>;
  const initialState = {
    pools: [],
    user: {
      data: {
        company: [ 'maersk' ],
        pools: [ 'first', 'second' ],
      },
    },
    bi: {
      reports: {
        collection: [
          { id: 2, year: 2020 },
          { id: 1, year: 2019 },
        ],
        filters: {
          years: [
            2020,
            2019,
          ],
        },
        year: 2019,
      },
    },
  };
  const mockStore = configureStore();
  let store;

  beforeEach(() => {
    store = mockStore(initialState);
  });


  it('renders Reports page correctly', () => {
    mockedSelectors.selectEmbeddedBiReportData.mockImplementation(() => ({
      token: null, reportId: null, reportUrl: null, filters: [],
    }));
    const tree = ReactTestRenderer.create(<MemoryRouter>
      <Provider store={store}>
        <ReportsPage />
      </Provider>
    </MemoryRouter>).toJSON();

    expect(tree).toMatchSnapshot();
  });
});
