import React from 'react';
import { shallow, mount } from 'enzyme';
import { FormattedMessage, defineMessages } from 'react-intl';
import { Provider } from 'react-redux';
import ConnectedLanguageProvider, { LanguageProvider } from '../index';
import { configureStore }  from '@capillarytech/vulcan-react-sdk/utils';
import history from '../../../utils/history';
import { initialReducer } from '../../../initialReducer';

import { translationMessages } from '../../../i18n';

const messages = defineMessages({
  someMessage: {
    id: 'some.id',
    defaultMessage: 'This is some default message',
    en: 'This is some en message',
  },
});

jest.mock('antd/es/locale/en_US', () => 'enUS');
jest.mock('antd/es/locale/zh_CN', () => 'zhCN');
jest.mock('antd/es/locale/ja_JP', () => 'jaJP');

describe('<LanguageProvider />', () => {
  it('should render its children', () => {
    const mockActions = {
      getLocizMessage: jest.fn(),
    };

    const language = {
      locale : 'en',
    }

    const props = {
      messages : messages,
      language: language,
      actions: mockActions,
    };

    const children = <h1>Test</h1>

    const renderedComponent = shallow(
      <LanguageProvider {...props}>
        {children}
      </LanguageProvider>
    );
    expect(renderedComponent.contains(children)).toBe(true);
  });
});

describe('<ConnectedLanguageProvider />', () => {
  let store;

  beforeAll(() => {
    store = configureStore({}, initialReducer, history);
  });

  it('should render the default language messages', () => {
    const renderedComponent = mount(
      <Provider store={store}>
        <ConnectedLanguageProvider messages={translationMessages}>
          <FormattedMessage {...messages.someMessage} />
        </ConnectedLanguageProvider>
      </Provider>
    );
    expect(renderedComponent.contains(<FormattedMessage {...messages.someMessage} />)).toBe(true);
  });
});
