import React from 'react';
import { shallow } from 'enzyme';
import MarketTable from '../MarketTable';

describe('MarketTable', () => {
  const currentTime = new Date('2016-12-05T00:00:00+0000');
  const timezone = 'Asia/Singapore';
  const markets = [
    {
      name: 'Tokyo',
      open: '0800',
      close: '1700',
      timezone: 'Asia/Tokyo',
    },
    {
      name: 'London',
      open: '0800',
      close: '1700',
      timezone: 'Europe/London',
    },
  ];

  it('renders table without market', () => {
    const emptyMarkets = [];

    const wrapper = shallow(
      <MarketTable
        currentTime={currentTime}
        timezone={timezone}
        markets={emptyMarkets}
        format="HH:mm"
      />,
    );

    expect(wrapper).toMatchSnapshot();
  });

  it('renders table with market', () => {
    const wrapper = shallow(
      <MarketTable
        currentTime={currentTime}
        timezone={timezone}
        markets={markets}
        format="HH:mm"
      />,
    );

    expect(wrapper).toMatchSnapshot();
  });

  it('renders MarketRow with next day hours it it is after market close now', () => {
    const afterTokyoClosed = new Date('2016-12-05T08:01:00+0000');

    const wrapper = shallow(
      <MarketTable
        currentTime={afterTokyoClosed}
        timezone={timezone}
        markets={markets}
        format="HH:mm"
      />,
    );

    expect(wrapper).toMatchSnapshot();
  });
});
