<commit_before>import React                   from "react";
import ReactDOM                from "react-dom";
import TestUtils               from "react/lib/ReactTestUtils";
import Helper                  from "../../../specs_support/helper";

import appHistory              from "../../history";
import { Assessment }          from "./assessment";
import * as AssessmentActions  from "../../actions/assessment";


var props;
var allQuestions,
  assessment,
  assessmentViewed,
  checkedResponses,
  currentItem,
  outcomes,
  previousQuestions,
  progress,
  questionCount,
  questionsPerPage,
  responses,
  result,
  settings,
  subject,
  submitAssessment;

var result;
var subject;

var reset = () => {
  allQuestions = () => [{
    timeSpent:0,
    outcomes:{shortOutcome:"", longOutcome:""},
    material: "Test Material",
    correct:[{
      id:"testCorrect",
      value:"100"
    }],
    points_possible:"1",
    question_type:"multiple_choice_question",
    answers:[
      {
        id:"testCorrect",
        material:"test question material"
      },
      {
        id:"testIncorrect",
        material:"test question material"
      }
    ],
    title:"Test Question Title",
    id:"TestQuestionID"
  }];

  assessment = {
    title: "Test Title"
  };

  checkedResponses = [];

  currentItem = 5;

  questionsPerPage = 1;

  outcomes = () => {};

  progress = {
    currentItemIndex:0
  };

  questionCount = 10;

  responses = [];
  settings = {
    user_id      : 0,
    max_attempts : 1,
    eid          : "external_identifier",
    src_url      : "http://www.openassessments.com/api/assessments/55.xml",
    questions_per_page:1,
    assessment_kind: "SUMMATIVE"
  };

  props = {
    allQuestions:allQuestions(),
    assessment,
    assessmentViewed: () => {},
    checkedResponses,
    currentItem,
    hideLMSNavigation: () => {},
    nextQuestions: () => {},
    outcomes:outcomes(),
    previousQuestions: () => {},
    progress,
    questionCount,
    questionsPerPage,
    responses,
    scrollParentToTop: () => {},
    sendSize: () => {},
    settings,
    submitAssessment: () => {}
  };


  result = TestUtils.renderIntoDocument(<Assessment {...props} />);
  subject = ReactDOM.findDOMNode(result);
};


describe("assessment", function() {


  // Props are reset to these default values between each test. To use
  // a modified prop in your test case, modify props.myProp in your test case and
  // re-render dom element with  result = TestUtils.renderIntoDocument. Then
  // proceed to test your result.
  beforeEach(() => {
    reset();
  });

  afterEach(() => {
    jasmine.clock().uninstall();
    jasmine.Ajax.uninstall();
  });

  it("Calls nextQuestions when the next button is clicked", () => {
    spyOn(props, "nextQuestions");
    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    let button = TestUtils.findRenderedDOMComponentWithClass(result, "c-btn--next");
    TestUtils.Simulate.click(button);

    expect(props.nextQuestions).toHaveBeenCalled();
  });

  it("Calls previousQuestions when the previous button is clicked", () => {
    spyOn(props, "previousQuestions");
    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    let button = TestUtils.findRenderedDOMComponentWithClass(result, "c-btn--previous");
    TestUtils.Simulate.click(button);

    expect(props.previousQuestions).toHaveBeenCalled();
  });

  it("renders the assessment", () => {
    expect(subject).toBeDefined();
  });

  it("renders a question", () => {
    expect(subject.innerHTML).toContain("Test Question Title");
  });

  it("redirects to assessment result when assessment has been submitted", () => {
    spyOn(appHistory, "push");
    props.progress.assessmentResult = "done";
    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    subject = ReactDOM.findDOMNode(result);

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

  it('isLastPage should return true on last question', () => {
    props.currentItem = 9;

    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    expect(result.isLastPage()).toEqual(true);
  });

  it('isLastPage should not return true otherwise', () =>{
    props.currentItem = 8;

    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    expect(result.isLastPage()).toEqual(false);
  });

  it('isFirstPage should return true on first question', () => {
    props.currentItem = 0;

    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    expect(result.isFirstPage()).toEqual(true);
  });

  it('isFirstPage should not return true otherwise', () =>{
    props.currentItem = 1;

    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    expect(result.isFirstPage()).toEqual(false);
  });


  describe('getNextUnlocked', () => {
    beforeEach(() => { reset(); });

    describe('when unlockNext is ON_CORRECT', () => {
      var checkedResponse = () => ({correct:true, feedback:"Correct Answer"});
      var unlockNext = "ON_CORRECT";
      var currentItem = 9;
      var questionsPerPage = 10;
      var checkedResponses = [];
      for(var i = 0; i < 10; i++){checkedResponses.push(checkedResponse());}

      it('should return true when all answers in current page are correct', () => {
        var subject = result.getNextUnlocked;

        expect(
          subject(unlockNext, currentItem, questionsPerPage, checkedResponses)
        ).toEqual(true);
      });

      it('should return false when there is an incorrect answer in current page', () => {
        var subject = result.getNextUnlocked;
        var responses = [];
        for(var i = 0; i < 10; i++){responses.push(checkedResponse());}
        responses[9].correct = false;

        expect(
          subject(unlockNext, currentItem, questionsPerPage, responses)
        ).toEqual(false);
      });

      it('should return false when there is an unanswered question in current page', () => {
        var subject = result.getNextUnlocked;
        var responses = [];
        for(var i = 0; i < 10; i++){
          if(i === 5){continue;}
          responses.push(checkedResponse());
        }

        expect(
          subject(unlockNext, currentItem, questionsPerPage, responses)
        ).toEqual(false);
      });
    });

    describe('when unlockNext is ON_ANSWER_CHECK', () => {
      var checkedResponse = () => ({correct:false, feedback:"Correct Answer"});
      var unlockNext = "ON_ANSWER_CHECK";
      var currentItem = 9;
      var questionsPerPage = 10;
      var checkedResponses = [];
      for(var i = 0; i < 10; i++){checkedResponses.push(checkedResponse());}

      it('should return true when all questions have been checked in current page', () => {
        var subject = result.getNextUnlocked;

        expect(
          subject(unlockNext, currentItem, questionsPerPage, checkedResponses)
        ).toEqual(true);
      });

      it('should return false when all questions have not been answered in current page', () => {
        var subject = result.getNextUnlocked;
        var responses = [];
        for(var i = 0; i < 10; i++){
          if(i % 3 == 0){continue;}
          responses.push(checkedResponse());
        }

        expect(
          subject(unlockNext, currentItem, questionsPerPage, responses)
        ).toEqual(false);
      });
    });

    describe(' when unlockNext is on ALWAYS', () => {
      var checkedResponse = () => ({correct:false, feedback:"Correct Answer"});
      var unlockNext = "ALWAYS";
      var currentItem = 9;
      var questionsPerPage = 10;
      var checkedResponses = [];

      it('should return true if no questions are answered', () => {
        var subject = result.getNextUnlocked;

        expect(
          subject(unlockNext, currentItem, questionsPerPage, responses)
        ).toEqual(true);
      });
    });
  });

});
<commit_msg>refactored arrow functions out of tests<commit_after>import React                   from "react";
import ReactDOM                from "react-dom";
import TestUtils               from "react/lib/ReactTestUtils";
import Helper                  from "../../../specs_support/helper";

import appHistory              from "../../history";
import { Assessment }          from "./assessment";
import * as AssessmentActions  from "../../actions/assessment";


var props;
var allQuestions,
  assessment,
  assessmentViewed,
  checkedResponses,
  currentItem,
  outcomes,
  previousQuestions,
  progress,
  questionCount,
  questionsPerPage,
  responses,
  result,
  settings,
  subject,
  submitAssessment;

var result;
var subject;

function reset(){
  allQuestions = [{
    timeSpent:0,
    outcomes:{shortOutcome:"", longOutcome:""},
    material: "Test Material",
    correct:[{
      id:"testCorrect",
      value:"100"
    }],
    points_possible:"1",
    question_type:"multiple_choice_question",
    answers:[
      {
        id:"testCorrect",
        material:"test question material"
      },
      {
        id:"testIncorrect",
        material:"test question material"
      }
    ],
    title:"Test Question Title",
    id:"TestQuestionID"
  }];

  assessment = {
    title: "Test Title"
  };

  checkedResponses = [];

  currentItem = 5;

  questionsPerPage = 1;

  progress = {
    currentItemIndex:0
  };

  questionCount = 10;

  responses = [];
  settings = {
    user_id            : 0,
    max_attempts       : 1,
    eid                : "external_identifier",
    src_url            : "http://www.openassessments.com/api/assessments/55.xml",
    questions_per_page : 1,
    assessment_kind    : "SUMMATIVE"
  };

  props = {
    allQuestions,
    assessment,
    assessmentViewed: () => {},
    checkedResponses,
    currentItem,
    hideLMSNavigation: () => {},
    nextQuestions: () => {},
    previousQuestions: () => {},
    progress,
    questionCount,
    questionsPerPage,
    responses,
    scrollParentToTop: () => {},
    sendSize: () => {},
    settings,
    submitAssessment: () => {}
  };


  result = TestUtils.renderIntoDocument(<Assessment {...props} />);
  subject = ReactDOM.findDOMNode(result);
};


describe("assessment", function() {


  // Props are reset to these default values between each test. To use
  // a modified prop in your test case, modify props.myProp in your test case and
  // re-render dom element with  result = TestUtils.renderIntoDocument. Then
  // proceed to test your result.
  beforeEach(() => {
    reset();
  });

  afterEach(() => {
    jasmine.clock().uninstall();
    jasmine.Ajax.uninstall();
  });

  it("Calls nextQuestions when the next button is clicked", () => {
    spyOn(props, "nextQuestions");
    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    let button = TestUtils.findRenderedDOMComponentWithClass(result, "c-btn--next");
    TestUtils.Simulate.click(button);

    expect(props.nextQuestions).toHaveBeenCalled();
  });

  it("Calls previousQuestions when the previous button is clicked", () => {
    spyOn(props, "previousQuestions");
    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    let button = TestUtils.findRenderedDOMComponentWithClass(result, "c-btn--previous");
    TestUtils.Simulate.click(button);

    expect(props.previousQuestions).toHaveBeenCalled();
  });

  it("renders the assessment", () => {
    expect(subject).toBeDefined();
  });

  it("renders a question", () => {
    expect(subject.innerHTML).toContain("Test Question Title");
  });

  it("redirects to assessment result when assessment has been submitted", () => {
    spyOn(appHistory, "push");
    props.progress.assessmentResult = "done";
    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    subject = ReactDOM.findDOMNode(result);

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

  it('isLastPage should return true on last question', () => {
    props.currentItem = 9;

    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    expect(result.isLastPage()).toEqual(true);
  });

  it('isLastPage should not return true otherwise', () =>{
    props.currentItem = 8;

    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    expect(result.isLastPage()).toEqual(false);
  });

  it('isFirstPage should return true on first question', () => {
    props.currentItem = 0;

    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    expect(result.isFirstPage()).toEqual(true);
  });

  it('isFirstPage should not return true otherwise', () =>{
    props.currentItem = 1;

    result = TestUtils.renderIntoDocument(<Assessment {...props} />);
    expect(result.isFirstPage()).toEqual(false);
  });


  describe('getNextUnlocked', () => {
    beforeEach(() => { reset(); });

    describe('when unlockNext is ON_CORRECT', () => {
      var checkedResponse = () => ({correct:true, feedback:"Correct Answer"});
      var unlockNext = "ON_CORRECT";
      var currentItem = 9;
      var questionsPerPage = 10;
      var checkedResponses = [];
      for(var i = 0; i < 10; i++){checkedResponses.push(checkedResponse());}

      it('should return true when all answers in current page are correct', () => {
        var subject = result.getNextUnlocked;

        expect(
          subject(unlockNext, currentItem, questionsPerPage, checkedResponses)
        ).toEqual(true);
      });

      it('should return false when there is an incorrect answer in current page', () => {
        var subject = result.getNextUnlocked;
        var responses = [];
        for(var i = 0; i < 10; i++){responses.push(checkedResponse());}
        responses[9].correct = false;

        expect(
          subject(unlockNext, currentItem, questionsPerPage, responses)
        ).toEqual(false);
      });

      it('should return false when there is an unanswered question in current page', () => {
        var subject = result.getNextUnlocked;
        var responses = [];
        for(var i = 0; i < 10; i++){
          if(i === 5){continue;}
          responses.push(checkedResponse());
        }

        expect(
          subject(unlockNext, currentItem, questionsPerPage, responses)
        ).toEqual(false);
      });
    });

    describe('when unlockNext is ON_ANSWER_CHECK', () => {
      var checkedResponse = () => ({correct:false, feedback:"Correct Answer"});
      var unlockNext = "ON_ANSWER_CHECK";
      var currentItem = 9;
      var questionsPerPage = 10;
      var checkedResponses = [];
      for(var i = 0; i < 10; i++){checkedResponses.push(checkedResponse());}

      it('should return true when all questions have been checked in current page', () => {
        var subject = result.getNextUnlocked;

        expect(
          subject(unlockNext, currentItem, questionsPerPage, checkedResponses)
        ).toEqual(true);
      });

      it('should return false when all questions have not been answered in current page', () => {
        var subject = result.getNextUnlocked;
        var responses = [];
        for(var i = 0; i < 10; i++){
          if(i % 3 == 0){continue;}
          responses.push(checkedResponse());
        }

        expect(
          subject(unlockNext, currentItem, questionsPerPage, responses)
        ).toEqual(false);
      });
    });

    describe(' when unlockNext is on ALWAYS', () => {
      var checkedResponse = () => ({correct:false, feedback:"Correct Answer"});
      var unlockNext = "ALWAYS";
      var currentItem = 9;
      var questionsPerPage = 10;
      var checkedResponses = [];

      it('should return true if no questions are answered', () => {
        var subject = result.getNextUnlocked;

        expect(
          subject(unlockNext, currentItem, questionsPerPage, responses)
        ).toEqual(true);
      });
    });
  });

});

{'fraction_non_alphanumeric': 0.14222278609489977, 'fraction_numerical': 0.005962953565085004, 'mean_word_length': 2.836699926989535, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '5991139', 'n_tokens_mistral': 4644, 'n_tokens_neox': 4441, 'n_words': 1048}