content: import React from 'react';
  import ReactDOM from 'react-dom';
  import {
    renderIntoDocument,
    scryRenderedDOMComponentsWithTag,
    Simulate
  } from 'react-addons-test-utils';
  
  import {List} from 'immutable';
  import {expect} from 'chai';
  
  import Voting from '../../src/components/Voting';
  
  describe('Voting', () => {
  
    it('Renders a pair of buttons', () => {
      const component = renderIntoDocument(
        <Voting pair={['Trainspotting', '28 days later']} />
      );
      const buttons = scryRenderedDOMComponentsWithTag(component, 'button');
  
      expect(buttons.length).to.equal(2);
      expect(buttons[0].textContent).to.equal('Trainspotting');
      expect(buttons[1].textContent).to.equal('28 days later');
    });
  
    it('invokes callback when a button is clicked', () => {
      let votedWith;
      const vote = (entry) => votedWith = entry;
      const component = renderIntoDocument(
        <Voting pair={['Trainspotting', '28 days later']}
                vote={vote}/>
      );
      const buttons = scryRenderedDOMComponentsWithTag(component, 'button');
      Simulate.click(buttons[0]);
  
      expect(votedWith).to.equal('Trainspotting');
    });
  
    it('disables buttons when user has voted', () => {
      const component = renderIntoDocument(
        <Voting pair={['Trainspotting', '28 days later']}
                hasVoted="Trainspotting"/>
      );
      const buttons = scryRenderedDOMComponentsWithTag(component, 'button');
  
      expect(buttons.length).to.equal(2);
      expect(buttons[0].hasAttribute('disabled')).to.equal(true);
      expect(buttons[1].hasAttribute('disabled')).to.equal(true);
    });
  
    it('labels a voted entry', () => {
      const component = renderIntoDocument(
        <Voting pair={['Trainspotting', '28 days later']}
                hasVoted="Trainspotting" />
      );
      const buttons = scryRenderedDOMComponentsWithTag(component, 'button');
  
      expect(buttons.length).to.equal(2);
      expect(buttons[0].textContent).to.contain('Voted');
    });
  
    it('renders just the winner when there is one', () => {
      const component = renderIntoDocument(
        <Voting winner="Trainspotting"/>
      );
      const buttons = scryRenderedDOMComponentsWithTag(component, 'button');
  
      const winner = ReactDOM.findDOMNode(component.refs.winner);
      expect(winner).to.be.ok;
      expect(winner.textContent).to.contain('Trainspotting');
    });
  
    it('renders as a pure component', () => {
      const pair = ['Trainspotting', '28 days later'];
      const container = document.createElement('div');
      let component = ReactDOM.render(
        <Voting pair={pair} />,
        container
      );
      let firstButton = scryRenderedDOMComponentsWithTag(component, 'button')[0];
      expect(firstButton.textContent).to.equal('Trainspotting');
  
      pair[0] = 'Sunshine';
      component = ReactDOM.render(
        <Voting pair={pair} />,
        container
      );
      firstButton = scryRenderedDOMComponentsWithTag(component, 'button')[0];
      expect(firstButton.textContent).to.equal('Trainspotting');
    });
  
    it('does update dom when props change', () => {
      const pair = List.of('Trainspotting', '28 days later');
      const container = document.createElement('div');
      let component = ReactDOM.render(
        <Voting pair={pair} />,
        container
      );
      let firstButton = scryRenderedDOMComponentsWithTag(component, 'button')[0];
      expect(firstButton.textContent).to.equal('Trainspotting');
  
      const newPair = pair.set(0, 'Sunshine');
      component = ReactDOM.render(
        <Voting pair={newPair} />,
        container
      );
      firstButton = scryRenderedDOMComponentsWithTag(component, 'button')[0];
      expect(firstButton.textContent).to.equal('Sunshine');
    });
  
  });
  