import React from 'react';
import { injectIntl } from 'react-intl';

import * as actions from '../actions';
import {Cap} from '../index';
import mockData from '../../mockdata';
import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
const { match, location, capGlobal, language } = mockData;

jest.mock('@capillarytech/cap-ui-utils', () => ({
  GA: {
    initialize: jest.fn(),
    timeTracker: {
      stopTimer: jest.fn(),
      startTimer: jest.fn(),
    },
    setCustomDimension: jest.fn(),
  },
  Auth: {
    hasAccess: () => jest.fn(() => true),
    hasFeatureAccess: () => jest.fn(() => true),
    authHoc: jest.fn(),
    initialize: jest.fn(),
  },
  multipleOrgSwitch: {
    logNewTab: jest.fn(),
    utilsGetOrgNameFromId: () => 'org2',
    tabBeforeUnloadEventHandler: jest.fn(),
    utilsHandleStorageChange: () => jest.fn(() => true),
    isMultipleTabsOpen: () => jest.fn(() => true),
  },
  utilsSessionStorageApi: {
    loadSessionItem: () => true,
    saveSessionItem: jest.fn(),
  },
}));

describe('<Cap />', () => {
  const push = jest.fn();
  const componentProps = {
    actions,
    history: {
      push,
    },
    orgTimezone: 'Asia/Kolkata',
    match,
    location,
    Global: capGlobal,
    language,
  };
  let renderedComponent;
  const renderFunc = () => {
    const Component = injectIntl(Cap);
    renderedComponent = shallowWithIntl(<Component {...componentProps} />);
  };

  it('should render correct component', () => {
    renderFunc();
    expect(renderedComponent).toMatchSnapshot();
  });
});

