<commit_before>'use strict';

jest.unmock('../js/components/game-over');
jest.unmock('material-ui/lib/raised-button');

import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import GameOver from '../js/components/game-over';

navigator.__defineGetter__('userAgent', function() {
  return 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2454.85 Safari/537.36'
});

describe('In the game, after the user submits a word...', () => {
  it('if this is the last word available to be submitted we display the component', () => {
    const onStartNewGameMockFunc = jest.fn();
    const onStartSameGameMockFunc = jest.fn();
    // Render a gameover component in the document
    const gameOver = TestUtils.renderIntoDocument(
      <GameOver status='Game Finished' numberCorrect="5" onStartNewGame={onStartNewGameMockFunc} onStartSameGame={onStartSameGameMockFunc}/>
    );

    const gameOverNode = ReactDOM.findDOMNode(gameOver);
    expect(gameOverNode.style.display).toEqual('flex');
    const titleNode = gameOverNode.children[0].children[0];
    expect(titleNode.textContent).toEqual('You got 5 correct!');

  });

  it('if this is not the last word available to spell, then keep the component hidden', () => {
    const onStartNewGameMockFunc = jest.fn();
    const onStartSameGameMockFunc = jest.fn();
    // Render a gameover component in the document
    const gameOver = TestUtils.renderIntoDocument(
      <GameOver status='Playing'  onStartNewGame={onStartNewGameMockFunc} onStartSameGame={onStartSameGameMockFunc}/>
    );

    const gameOverNode = ReactDOM.findDOMNode(gameOver);
    expect(gameOverNode.style.display).toEqual('none');
  });

  it('clicking same game button calls the correct function', () => {
    const onStartNewGameMockFunc = jest.fn();
    const onStartSameGameMockFunc = jest.fn();
    // Render a gameover component in the document
    const gameOver = TestUtils.renderIntoDocument(
      <GameOver status='Playing'  onStartNewGame={onStartNewGameMockFunc} onStartSameGame={onStartSameGameMockFunc}/>
    );

    const gameOverNode = ReactDOM.findDOMNode(gameOver);
    expect(gameOverNode.style.display).toEqual('none');
    let startSameButton = gameOverNode.children[0].children[1].children[0];
    expect(startSameButton.textContent).toEqual('Start Again?');
    TestUtils.Simulate.click(startSameButton);
    expect(onStartSameGameMockFunc).not.toBeCalled();
  });

  it('clicking new game button calls the correct function', () => {
    const onStartNewGameMockFunc = jest.fn();
    const onStartSameGameMockFunc = jest.fn();
    // Render a gameover component in the document
    const gameOver = TestUtils.renderIntoDocument(
      <GameOver status='Playing'  onStartNewGame={onStartNewGameMockFunc} onStartSameGame={onStartSameGameMockFunc}/>
    );

    const gameOverNode = ReactDOM.findDOMNode(gameOver);
    expect(gameOverNode.style.display).toEqual('none');
    let startNewButton = gameOverNode.children[0].children[1].children[1];
    expect(startNewButton.textContent).toEqual('Move to harder words?');
    TestUtils.Simulate.click(startNewButton);
    expect(onStartNewGameMockFunc).not.toBeCalled();
  });

});<commit_msg>function clicking tests for the game over screen<commit_after>'use strict';

jest.unmock('../js/components/game-over');
jest.unmock('material-ui/lib/raised-button');

import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import GameOver from '../js/components/game-over';

navigator.__defineGetter__('userAgent', function() {
  return 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2454.85 Safari/537.36'
});

describe('In the game, after the user submits a word...', () => {
  it('if this is the last word available to be submitted we display the component', () => {
    const onStartNewGameMockFunc = jest.fn();
    const onStartSameGameMockFunc = jest.fn();
    // Render a gameover component in the document
    const gameOver = TestUtils.renderIntoDocument(
      <GameOver status='Game Finished' numberCorrect="5" onStartNewGame={onStartNewGameMockFunc} onStartSameGame={onStartSameGameMockFunc}/>
    );

    const gameOverNode = ReactDOM.findDOMNode(gameOver);
    expect(gameOverNode.style.display).toEqual('flex');
    const titleNode = gameOverNode.children[0].children[0];
    expect(titleNode.textContent).toEqual('You got 5 correct!');

  });

  it('if this is not the last word available to spell, then keep the component hidden', () => {
    const onStartNewGameMockFunc = jest.fn();
    const onStartSameGameMockFunc = jest.fn();
    // Render a gameover component in the document
    const gameOver = TestUtils.renderIntoDocument(
      <GameOver status='Playing' onStartNewGame={onStartNewGameMockFunc} onStartSameGame={onStartSameGameMockFunc}/>
    );

    const gameOverNode = ReactDOM.findDOMNode(gameOver);
    expect(gameOverNode.style.display).toEqual('none');
  });

  it('should call the appropriate function when clicking same game button', () => {
    const onStartNewGameMockFunc = jest.fn();
    const onStartSameGameMockFunc = jest.fn();
    // Render a gameover component in the document
    const gameOver = TestUtils.renderIntoDocument(
      <GameOver status='Game Finished' onStartNewGame={onStartNewGameMockFunc} onStartSameGame={onStartSameGameMockFunc}/>
    );

    const gameOverNode = ReactDOM.findDOMNode(gameOver);
    expect(gameOverNode.style.display).toEqual('flex');
    let startSameButton = gameOverNode.children[0].children[1].children[0].children[0];
    expect(startSameButton.tagName).toEqual('BUTTON');
    expect(startSameButton.textContent).toEqual('Start Again?');
    TestUtils.Simulate.click(startSameButton);
    expect(onStartSameGameMockFunc).toBeCalled();
  });

  it('should call the appropriate function when clicking new game button', () => {
    const onStartNewGameMockFunc = jest.fn();
    const onStartSameGameMockFunc = jest.fn();
    // Render a gameover component in the document
    const gameOver = TestUtils.renderIntoDocument(
      <GameOver status='Game Finished' onStartNewGame={onStartNewGameMockFunc} onStartSameGame={onStartSameGameMockFunc}/>
    );

    const gameOverNode = ReactDOM.findDOMNode(gameOver);
    expect(gameOverNode.style.display).toEqual('flex');
    let startNewButton = gameOverNode.children[0].children[1].children[1].children[0];
    expect(startNewButton.tagName).toEqual('BUTTON');
    expect(startNewButton.textContent).toEqual('Move to harder words?');
    TestUtils.Simulate.click(startNewButton);
    expect(onStartNewGameMockFunc).toBeCalled();
  });

});
{'fraction_non_alphanumeric': 0.12442464736451374, 'fraction_numerical': 0.010690423162583519, 'mean_word_length': 4.821953327571305, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '1432939', 'n_tokens_mistral': 2009, 'n_tokens_neox': 1978, 'n_words': 433}