{"size": 2522, "ext": "js", "max_stars_repo_path": "test/client/components/gm/game-controls.test.js", "max_stars_repo_name": "azeemba/everyoneisjohn", "max_stars_repo_stars_event_min_datetime": "2020-11-16T01:42:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-16T01:42:52.000Z", "max_issues_repo_path": "test/client/components/gm/game-controls.test.js", "max_issues_repo_name": "azeemba/everyoneisjohn", "max_issues_repo_issues_event_min_datetime": "2019-04-23T02:40:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T09:02:17.000Z", "max_forks_repo_path": "test/client/components/gm/game-controls.test.js", "max_forks_repo_name": "azeemba/everyoneisjohn", "max_forks_repo_forks_event_min_datetime": "2020-11-22T05:10:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-22T05:10:13.000Z"}
{"max_stars_count": 1, "max_issues_count": 19, "max_forks_count": 1, "avg_line_length": 26.2708333333, "max_line_length": 83, "alphanum_fraction": 0.6566217288}
import test from 'ava';
import React from 'react';
import proxyquire from 'proxyquire';
import {shallow} from 'enzyme';
import {stub} from 'sinon';
import {MockSocket} from '../../../server/mocks/socket';

const socket = new MockSocket();

const GameControls = proxyquire('../../../../client/components/gm/game-controls', {
  'react-redux': {connect: stub().returns(stub().returnsArg(0))},
  '../../socket': {default: socket}
}).default;

const render = (props = {mode: 'SETUP'}) => shallow(<GameControls {...props}/>);

test('it initially renders a Start Game button, in SETUP mode', t => {
  const wrapper = render();
  const buttons = wrapper.find('button');

  t.is(buttons.length, 1);

  t.is(buttons.at(0).text(), 'Start Game');
});

test('the Start Game button dispatches a startGame event', t => {
  const wrapper = render();
  const button = wrapper.find('button');

  button.simulate('click');

  t.true(socket.emit.calledWith('startGame'));
});

test('it renders voting buttons if in VOTING mode', t => {
  const wrapper = render({mode: 'VOTING'});
  const buttons = wrapper.find('button');

  t.is(buttons.length, 1);

  t.is(buttons.at(0).text(), 'Skip Bidding');
});

test('the Skip Bidding button dispatches a startPlaying event', t => {
  const wrapper = render({mode: 'VOTING'});
  const button = wrapper.find('button');

  button.simulate('click');

  t.true(socket.emit.calledWith('startPlaying'));
});

test('it renders playing buttons if in PLAYING mode', t => {
  const wrapper = render({mode: 'PLAYING'});
  const buttons = wrapper.find('button');

  t.is(buttons.length, 1);

  t.is(buttons.at(0).text(), 'Next Round');
});

test('the Next Round button dispatches a startBidding event', t => {
  const wrapper = render({mode: 'PLAYING'});
  const button = wrapper.find('button');

  button.simulate('click');

  t.true(socket.emit.calledWith('startBidding'));
});

test('it renders a Ticker', t => {
  const wrapper = render({mode: 'PLAYING'});
  const ticker = wrapper.find('Ticker');

  t.is(ticker.length, 1);
});

test('it does not render a Ticker if in the SETUP mode', t => {
  const wrapper = render({mode: 'SETUP'});
  const ticker = wrapper.find('Ticker');

  t.is(ticker.length, 0);
});

test('when changed, the Ticker emits a giveWillpower event', t => {
  const wrapper = render({mode: 'PLAYING'});
  const ticker = wrapper.find('Ticker');

  const {onChange} = ticker.props();

  const amount = -1;
  onChange(amount);

  t.true(socket.emit.calledWith('giveWillpower', {amount}));
});
