<commit_before>import React from 'react';
import { mount, render } from 'enzyme';
import { expect } from 'chai';
import Immutable from 'immutable';

// see: https://github.com/mochajs/mocha/issues/1847
const { describe, it } = global;

import Visualizer from '../Visualizer';
import { defaultLabels } from '../../defaults';

describe('<Visualizer />', () => {

  const sequence = new Immutable.List('ATTTGCGTCG'.split(''));
  let context;

  before(() => {
    context = {
      controller: {
        on: () => {},
        dispatch: () => {},
      }
    };
  });

  it('renders a SVG element with appropriate dimensions', () => {
    const childContextTypes = { controller: React.PropTypes.object.isRequired };
    const wrapper = mount(
      <Visualizer
        sequence={sequence}
        labels={defaultLabels}
        positionFrom={0}
      />,
      { context, childContextTypes }
    );

    expect(wrapper.find(Visualizer)).to.have.length(1);
    expect(wrapper.ref('wrapper')).to.have.length(1);
    expect(wrapper.find('svg')).to.have.length(1);
    expect(wrapper.instance().state.width).to.equal('100%');
    expect(wrapper.instance().state.height).to.equal('100%');
  });
});<commit_msg>Add a few more tests for the Visualizer<commit_after>import React from 'react';
import { shallow, mount } from 'enzyme';
import { expect } from 'chai';
import Immutable from 'immutable';
import sinon from 'sinon';

// see: https://github.com/mochajs/mocha/issues/1847
const { describe, it } = global;

import Visualizer from '../Visualizer';
import { defaultLabels } from '../../defaults';

describe('<Visualizer />', () => {

  const sequence = new Immutable.List('ATTTGCGTCG'.split(''));

  const childContextTypes = { controller: React.PropTypes.object.isRequired };
  let context;

  before(() => {
    context = {
      controller: {
        on: () => {},
        dispatch: () => {},
      }
    };
  });

  it('renders a SVG element with appropriate dimensions', () => {
    const wrapper = mount(
      <Visualizer
        sequence={sequence}
        labels={defaultLabels}
        positionFrom={0}
      />,
      { context, childContextTypes }
    );

    expect(wrapper.find(Visualizer)).to.have.length(1);
    expect(wrapper.ref('wrapper')).to.have.length(1);
    expect(wrapper.find('svg')).to.have.length(1);
    expect(wrapper.instance().state.width).to.equal('100%');
    expect(wrapper.instance().state.height).to.equal('100%');
  });

  it('renders help panel if sequence is empty', () => {
    const wrapper = shallow(
      <Visualizer
        sequence={new Immutable.List()}
        labels={defaultLabels}
        positionFrom={0}
      />
    );

    expect(wrapper.find('.help')).to.have.length(1);
    expect(wrapper.find('svg')).to.have.length(0);
  });

  it('adds a listener to window resize', () => {
    window.addEventListener = sinon.spy();

    const wrapper = mount(
      <Visualizer
        sequence={sequence}
        labels={defaultLabels}
        positionFrom={0}
      />,
      { context, childContextTypes }
    );

    expect(window.addEventListener.calledWith('resize')).to.be.true;
  });

  it('updates dimensions when receiving new props', () => {
    const wrapper = mount(
      <Visualizer
        sequence={sequence}
        labels={defaultLabels}
        positionFrom={0}
      />,
      { context, childContextTypes }
    );

    expect(wrapper.state('nucleotidesPerRow')).to.equal(80);

    // test starts here
    wrapper.setProps({
      labels: defaultLabels,
      sequence: new Immutable.List(),
    });

    // Well... it works but we cannot assert something else since
    // it is not possible to get a valid value for `clientWidth` in
    // the method `updateVisualizerDimensions` of the component
    expect(wrapper.state('nucleotidesPerRow')).to.not.equal(80);
  });
});
{'fraction_non_alphanumeric': 0.16588419405320814, 'fraction_numerical': 0.009650495565988524, 'mean_word_length': 2.9699792960662528, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '7139366', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1121, 'n_words': 237}