{"size": 1679, "ext": "js", "max_stars_repo_path": "client/js/_player/components/index.spec.js", "max_stars_repo_name": "dhavalocked/openassessment", "max_stars_repo_stars_event_min_datetime": "2017-03-09T14:26:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-05T17:46:21.000Z", "max_issues_repo_path": "client/js/_player/components/index.spec.js", "max_issues_repo_name": "dhavalocked/openassessment", "max_issues_repo_issues_event_min_datetime": "2017-01-30T22:04:09.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-21T20:47:02.000Z", "max_forks_repo_path": "client/js/_player/components/index.spec.js", "max_forks_repo_name": "dhavalocked/openassessment", "max_forks_repo_forks_event_min_datetime": "2017-02-07T18:41:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-13T16:22:52.000Z"}
{"max_stars_count": 2, "max_issues_count": 80, "max_forks_count": 6, "avg_line_length": 27.9833333333, "max_line_length": 77, "alphanum_fraction": 0.6313281715}
"use strict";

import React                from 'react';
import ReactDOM             from 'react-dom';
import TestUtils            from 'react-addons-test-utils';
import { Index }            from './index';
import appHistory           from "../history";

describe('index', function() {
  var result, props, scrollParentToTopCalled, sendSizeCalled;


  beforeEach(()=>{
    scrollParentToTopCalled = false;
    sendSizeCalled = false;

    props = {
      loadAssessment: () => {},
      scrollParentToTop: () => { scrollParentToTopCalled = true; },
      sendSize: () => { sendSizeCalled = true; },
      availableLocales: () => {}
    };

    result = TestUtils.renderIntoDocument(<Index {...props} />);
    spyOn(appHistory, 'push');
  });

  it('renders the index', function() {
    expect(ReactDOM.findDOMNode(result)).toBeDefined();
  });

  it('redirects to assessment when start is disabled', () => {
    props.enableStart = false;
    result = TestUtils.renderIntoDocument(<Index {...props} />);

    expect(appHistory.push).toHaveBeenCalledWith("assessment");
  });

  it('redirects to retries exceeded when tries >= allowed tries', () => {
    props.maxAttempts = 1;
    props.userAttempts = 1;
    result = TestUtils.renderIntoDocument(<Index {...props} />);

    expect(appHistory.push).toHaveBeenCalledWith("retries-exceeded");
  });

  it('calls the send size comm handler action', () => {
    expect(sendSizeCalled).toBe(true);
  });

  it('calls the scroll parent to top comm handler action', () => {
    expect(scrollParentToTopCalled).toBe(true);
  });

  afterEach(()=>{
    ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(result).parentNode);
  });

});
