// @flow
import React from 'react';
import { act } from 'react-dom/test-utils';
import { Datepicker } from '.';
import {
  mountWrappedComponent,
  renderSnapshot,
  itIsAccessible,
} from '../../../utils/tests';

describe('Datepicker', () => {
  const DEFAULT_PROPS = {
    onChange: jest.fn(),
    label: 'Choose a date',
    value: new Date('2019-01-01 12:30:00'),
  };

  it('has the correct onChange functionality', () => {
    let component = mountWrappedComponent(<Datepicker {...DEFAULT_PROPS} />);

    act(() => {
      component.find('input').simulate('click');
    });

    component = component.update();

    act(() => {
      component
        .find('.DayPicker-Day')
        .at(19)
        .simulate('click');
    });

    component = component.update();

    // we do a toContain just so we dont deal with timezones in testing environments
    expect(DEFAULT_PROPS.onChange.mock.calls[0][0].toISOString()).toContain(
      '2019-01-18T',
    );
  });

  it('matches previous snapshot', () => {
    const component = renderSnapshot(<Datepicker {...DEFAULT_PROPS} />);

    expect(component).toMatchSnapshot();
  });

  describe.skip('accessibility', () => {
    itIsAccessible(<Datepicker {...DEFAULT_PROPS} />);
  });
});
