import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import {expect} from 'chai';

import Voting from '../../src/components/Voting';

describe('Voting', () => {
  it('renders a pair of buttons', () => {
    const component = ReactTestUtils.renderIntoDocument(
      <Voting pair={['first', 'second']} />
    );
    const buttons = ReactTestUtils.scryRenderedDOMComponentsWithTag(component, 'button');

    expect(buttons.length).to.equal(2);
    expect(buttons[0].textContent).to.equal('first');
    expect(buttons[1].textContent).to.equal('second');
  });

  it('invokes callback when a button is clicked', () => {
    let votedWith;
    const voteHanlder = entry => votedWith = entry;

    const component = ReactTestUtils.renderIntoDocument(
      <Voting pair={['first', 'second']} vote={voteHanlder} />
    );
    const buttons = ReactTestUtils.scryRenderedDOMComponentsWithTag(component, 'button');
    ReactTestUtils.Simulate.click(buttons[0]);

    expect(votedWith).to.equal('first');
  })
});

@@ -1020,13 +1020,443 @@
 ');%0A  %7D)
+%0A%0A  it('disables buttons when user has voted', () =%3E %7B%0A    const component = ReactTestUtils.renderIntoDocument(%0A      %3CVoting pair=%7B%5B'f', 's'%5D%7D hasVoted=%22f%22 /%3E%0A    );%0A    const buttons = ReactTestUtils.scryRenderedDOMComponentsWithTag(component, 'button');%0A%0A    expect(buttons.length).to.equal(2);%0A    expect(buttons%5B0%5D.hasAttribute('disabled')).to.equal(true);%0A    expect(buttons%5B1%5D.hasAttribute('disabled')).to.equal(true);%0A  %7D)
 %0A%7D);%0A

test for 'hasVoted' property