<commit_before>import React from 'react';
import renderer from 'react-test-renderer';
import { mount } from 'enzyme';
import BpkCalendarContainer from './BpkCalendarContainer';
import { weekDays, formatDateFull, formatMonth } from '../test-utils';
import { addDays } from './date-utils';

const createNodeMock = () => ({
  focus: () => null,
});

describe('BpkCalendarContainer', () => {
  it('should render correctly', () => {
    const tree = renderer.create(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={new Date(2010, 1, 15)}
    />, { createNodeMock }).toJSON();
    expect(tree).toMatchSnapshot();
  });

  it('should change the month', () => {
    const calendar = mount(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={new Date(2010, 1, 15)}
    />);

    const grid = calendar.find('BpkCalendarGridTransition');
    const nav = calendar.find('BpkCalendarNav');

    expect(grid.prop('month')).toEqual(new Date(2010, 1, 1));

    nav.prop('onMonthChange')(new Date(2010, 2, 1));
    expect(grid.prop('month')).toEqual(new Date(2010, 2, 1));
  });

  it('should call the onDateSelect callback', () => {
    const onDateSelect = jest.fn();

    const calendar = mount(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={new Date(2010, 1, 15)}
      onDateSelect={onDateSelect}
    />);

    const grid = calendar.find('BpkCalendarGridTransition');

    expect(onDateSelect.mock.calls.length).toBe(0);
    expect(grid.prop('month')).toEqual(new Date(2010, 1, 1));

    grid.prop('onDateClick')(new Date(2010, 1, 20));
    expect(onDateSelect.mock.calls.length).toBe(1);
    expect(onDateSelect.mock.calls[0][0]).toEqual(new Date(2010, 1, 20));
  });

  it('should set state only once on date selection', () => {
    const setStateSpy = jest.fn();
    const oldSetState = BpkCalendarContainer.prototype.setState;
    BpkCalendarContainer.prototype.setState = setStateSpy;

    const calendar = mount(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={new Date(2010, 1, 15)}
      onDateSelect={() => null}
    />);

    const grid = calendar.find('BpkCalendarGridTransition');

    expect(setStateSpy.mock.calls.length).toBe(0);

    grid.prop('onDateClick')(new Date(2010, 1, 20));
    expect(setStateSpy.mock.calls.length).toBe(1);

    BpkCalendarContainer.prototype.setState = oldSetState;
  });

  it('should move focus on keyboard input', () => {
    const preventDefault = jest.fn();
    const origin = new Date(2010, 2, 1);

    const calendar = mount(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={origin}
    />);

    expect(calendar.state('focusedDate')).toEqual(origin);

    // calendar.instance().handleDateKeyDown({ key: 'S', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(origin);
    // expect(preventDefault.mock.calls.length).toEqual(0);
    //
    // calendar.instance().handleDateKeyDown({ key: 'ArrowRight', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(addDays(origin, 1));
    // expect(preventDefault.mock.calls.length).toEqual(1);
    //
    // calendar.instance().handleDateKeyDown({ key: 'ArrowDown', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(addDays(origin, 8));
    // expect(preventDefault.mock.calls.length).toEqual(2);
    //
    // calendar.instance().handleDateKeyDown({ key: 'ArrowLeft', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(addDays(origin, 7));
    // expect(preventDefault.mock.calls.length).toEqual(3);
    //
    // calendar.instance().handleDateKeyDown({ key: 'ArrowUp', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(origin);
    // expect(preventDefault.mock.calls.length).toEqual(4);
    //
    // calendar.instance().handleDateKeyDown({ key: 'End', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(addDays(origin, 14));
    // expect(preventDefault.mock.calls.length).toEqual(5);
    // 
    // calendar.instance().handleDateKeyDown({ key: 'Home', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(origin);
    // expect(preventDefault.mock.calls.length).toEqual(6);
    //
    // calendar.instance().handleDateKeyDown({ key: 'PageDown', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(addDays(origin, 14));
    // expect(preventDefault.mock.calls.length).toEqual(7);
    //
    // calendar.instance().handleDateKeyDown({ key: 'PageUp', preventDefault });
    // expect(calendar.state('focusedDate')).toEqual(addDays(origin, -14));
    // expect(preventDefault.mock.calls.length).toEqual(8);
  });
});
<commit_msg>Uncomment test that was mistakenly commented out<commit_after>import React from 'react';
import renderer from 'react-test-renderer';
import { mount } from 'enzyme';
import BpkCalendarContainer from './BpkCalendarContainer';
import { weekDays, formatDateFull, formatMonth } from '../test-utils';
import { addDays } from './date-utils';

const createNodeMock = () => ({
  focus: () => null,
});

describe('BpkCalendarContainer', () => {
  it('should render correctly', () => {
    const tree = renderer.create(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={new Date(2010, 1, 15)}
    />, { createNodeMock }).toJSON();
    expect(tree).toMatchSnapshot();
  });

  it('should change the month', () => {
    const calendar = mount(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={new Date(2010, 1, 15)}
    />);

    const grid = calendar.find('BpkCalendarGridTransition');
    const nav = calendar.find('BpkCalendarNav');

    expect(grid.prop('month')).toEqual(new Date(2010, 1, 1));

    nav.prop('onMonthChange')(new Date(2010, 2, 1));
    expect(grid.prop('month')).toEqual(new Date(2010, 2, 1));
  });

  it('should call the onDateSelect callback', () => {
    const onDateSelect = jest.fn();

    const calendar = mount(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={new Date(2010, 1, 15)}
      onDateSelect={onDateSelect}
    />);

    const grid = calendar.find('BpkCalendarGridTransition');

    expect(onDateSelect.mock.calls.length).toBe(0);
    expect(grid.prop('month')).toEqual(new Date(2010, 1, 1));

    grid.prop('onDateClick')(new Date(2010, 1, 20));
    expect(onDateSelect.mock.calls.length).toBe(1);
    expect(onDateSelect.mock.calls[0][0]).toEqual(new Date(2010, 1, 20));
  });

  it('should set state only once on date selection', () => {
    const setStateSpy = jest.fn();
    const oldSetState = BpkCalendarContainer.prototype.setState;
    BpkCalendarContainer.prototype.setState = setStateSpy;

    const calendar = mount(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={new Date(2010, 1, 15)}
      onDateSelect={() => null}
    />);

    const grid = calendar.find('BpkCalendarGridTransition');

    expect(setStateSpy.mock.calls.length).toBe(0);

    grid.prop('onDateClick')(new Date(2010, 1, 20));
    expect(setStateSpy.mock.calls.length).toBe(1);

    BpkCalendarContainer.prototype.setState = oldSetState;
  });

  it('should move focus on keyboard input', () => {
    const preventDefault = jest.fn();
    const origin = new Date(2010, 2, 1);

    const calendar = mount(<BpkCalendarContainer
      formatMonth={formatMonth}
      formatDateFull={formatDateFull}
      daysOfWeek={weekDays}
      changeMonthLabel="Change month"
      id="myCalendar"
      minDate={new Date(2010, 1, 15)}
      maxDate={new Date(2010, 2, 15)}
      selectedDate={origin}
    />);

    expect(calendar.state('focusedDate')).toEqual(origin);

    calendar.instance().handleDateKeyDown({ key: 'S', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(origin);
    expect(preventDefault.mock.calls.length).toEqual(0);

    calendar.instance().handleDateKeyDown({ key: 'ArrowRight', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(addDays(origin, 1));
    expect(preventDefault.mock.calls.length).toEqual(1);

    calendar.instance().handleDateKeyDown({ key: 'ArrowDown', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(addDays(origin, 8));
    expect(preventDefault.mock.calls.length).toEqual(2);

    calendar.instance().handleDateKeyDown({ key: 'ArrowLeft', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(addDays(origin, 7));
    expect(preventDefault.mock.calls.length).toEqual(3);

    calendar.instance().handleDateKeyDown({ key: 'ArrowUp', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(origin);
    expect(preventDefault.mock.calls.length).toEqual(4);

    calendar.instance().handleDateKeyDown({ key: 'End', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(addDays(origin, 14));
    expect(preventDefault.mock.calls.length).toEqual(5);

    calendar.instance().handleDateKeyDown({ key: 'Home', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(origin);
    expect(preventDefault.mock.calls.length).toEqual(6);

    calendar.instance().handleDateKeyDown({ key: 'PageDown', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(addDays(origin, 14));
    expect(preventDefault.mock.calls.length).toEqual(7);

    calendar.instance().handleDateKeyDown({ key: 'PageUp', preventDefault });
    expect(calendar.state('focusedDate')).toEqual(addDays(origin, -14));
    expect(preventDefault.mock.calls.length).toEqual(8);
  });
});

{'fraction_non_alphanumeric': 0.1621478406782655, 'fraction_numerical': 0.030557272807559835, 'mean_word_length': 4.094017094017094, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1693265', 'n_tokens_mistral': 3651, 'n_tokens_neox': 3412, 'n_words': 590}