{"size": 1713, "ext": "js", "max_stars_repo_path": "app/containers/CalendarPage/tests/reducer.test.js", "max_stars_repo_name": "ngkhoawork/study-web", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/containers/CalendarPage/tests/reducer.test.js", "max_issues_repo_name": "ngkhoawork/study-web", "max_issues_repo_issues_event_min_datetime": "2020-07-19T13:41:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-19T13:41:05.000Z", "max_forks_repo_path": "app/containers/CalendarPage/tests/reducer.test.js", "max_forks_repo_name": "starsoftdev/study-web", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 27.1904761905, "max_line_length": 125, "alphanum_fraction": 0.5913601868}
import expect from 'expect';

import calendarPageReducer from '../reducer';
import { fetchSchedulesSucceeded, submitSchedule } from '../actions';

describe('CalendarPage/reducer', () => {
  let state;
  beforeEach(() => {
    state = {
      patientsByStudy: {
        isFetching: false,
        data: [],
        error: null,
      },
      schedules: {
        isFetching: false,
        isSubmitting: false,
        isDeleting: false,
        data: [],
        error: null,
      },
    };
  });

  it('should return the initial state', () => {
    const expectedResult = state;
    expect(calendarPageReducer(undefined, {})).toEqual(expectedResult);
  });

  it('should handle the fetchSchedulesSucceeded action correctly', () => {
    const response = [
      { id: 1, user_id: 4, patient_id: 3, siteLocation: 'Palmer Tech', indication: 'Birth Control', protocolNumber: 'AC-1' },
      { id: 2, user_id: 4, patient_id: 3, siteLocation: 'Palmer Tech', indication: 'Acne', protocolNumber: 'AC-2' },
    ];
    const expectedResult = {
      ...state,
      schedules: {
        isFetching: false,
        data: response,
        isSubmitting: false,
        isDeleting: false,
        error: null,
      },
    };
    expect(calendarPageReducer(state, fetchSchedulesSucceeded(response))).toEqual(expectedResult);
  });

  it('should handle the submitSchedule action correctly', () => {
    const payload = {};
    const expectedResult = {
      ...state,
      schedules: {
        isSubmitting: true,
        isFetching: false,
        isDeleting: false,
        data: [],
        error: null,
      },
    };
    expect(calendarPageReducer(state, submitSchedule(payload))).toEqual(expectedResult);
  });
});
