// @flow
import React from 'react';
import { act } from 'react-test-renderer';
import { mountWrappedComponent } from '../../../utils/tests';
import type { DateRangePickerProps } from './date-range-picker.proptypes';
import { DateRangePicker } from './index';

const DEFAULT_PROPS: DateRangePickerProps = {
  onRangeChange: jest.fn(),
  placeholder: 'placeholder',
  range: { from: undefined, to: undefined },
};

describe('DateRangePicker', () => {
  it('sets the from to the very start of the day', () => {
    const mockOnDateSelect = jest.fn();

    const props = {
      ...DEFAULT_PROPS,
      onRangeChange: mockOnDateSelect,
    };
    let component = mountWrappedComponent(<DateRangePicker {...props} />);

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

    const allAvailableDates = component.findWhere(
      (n) =>
        n.prop('className') === 'DayPicker-Day' &&
        n.prop('aria-disabled') === false,
    );

    act(() => {
      allAvailableDates.at(0).simulate('click');
    });

    const { from = new Date() } = mockOnDateSelect.mock.calls[0][0];

    expect(from.getHours()).toEqual(0);
    expect(from.getMinutes()).toEqual(0);
    expect(from.getSeconds()).toEqual(0);
  });
});
