import React from 'react';
import sinon from 'sinon';
import { shallow } from 'enzyme';

import Configuration from '../components/views/configuration';

describe('Configuration', () => {
  it('The handleModifyOutliers function should be called every time the "Show outliers" checkbox is changed', () => {
    const numChanges = 10;
    const handleModifyOutliers = sinon.spy();
    const c = shallow(
      <Configuration
        configureOutliers={true}
        whitelistedPopulations={['All']}
        handleModifyOutliers={handleModifyOutliers}
      />
    );
    const showOutliersCheckbox = c.find('.configure-outliers input[type="checkbox"]');

    for (let i = 0; i < numChanges; i++) {
      showOutliersCheckbox.simulate('change');
    }

    expect(handleModifyOutliers.callCount).toBe(numChanges);
  });

  it('The handleModifyScale function should be called every time a scale radio button is selected', () => {
    const numChanges = 10;
    const handleModifyScale = sinon.spy();
    const c = shallow(
      <Configuration
        configureScale={true}
        whitelistedPopulations={['All']}
        handleModifyScale={handleModifyScale}
      />
    );

    const linearRadioButton = c.find('.configure-scale .linear');
    const logRadioButton = c.find('.configure-scale .log');

    for (let i = 0; i < numChanges; i++) {
      const even = i % 2 === 0;

      if (even) {
        linearRadioButton.simulate('change');
      } else {
        logRadioButton.simulate('change');
      }
    }

    expect(handleModifyScale.callCount).toBe(numChanges);
  });
});

@@ -150,217 +150,153 @@
 ';%0A%0A
-describe('Configuration', () =%3E %7B%0A  it('The handleModifyOutliers function should be called every time the %22Show outliers%22 checkbox is changed', () =%3E %7B%0A    const numChanges = 10;%0A    const handleModifyOutliers
+%0Alet outliersSpy, scaleSpy, configurationMock;%0A%0Adescribe('Configuration', () =%3E %7B%0A  beforeAll(() =%3E %7B%0A    outliersSpy = sinon.spy();%0A    scaleSpy
  = s
@@ -303,35 +303,46 @@
 inon.spy();%0A
+%0A
     con
-st c
+figurationMock
  = shallow(%0A
@@ -374,140 +374,352 @@
     
-configureOutliers=%7Btrue%7D%0A        whitelistedPopulations=%7B%5B'All'%5D%7D%0A        handleModifyOutliers=%7BhandleModifyOutliers%7D%0A      /%3E%0A    )
+whitelistedPopulations=%7B%5B'All'%5D%7D%0A%0A        configureOutliers=%7Btrue%7D%0A        configureScale=%7Btrue%7D%0A%0A        handleModifyOutliers=%7BoutliersSpy%7D%0A        handleModifyScale=%7BscaleSpy%7D%0A      /%3E%0A    );%0A  %7D);%0A%0A  it('The handleModifyOutliers function should be called every time the %22Show outliers%22 checkbox is changed', () =%3E %7B%0A    const numChanges = 10
 ;%0A  
@@ -746,24 +746,40 @@
 Checkbox = c
+onfigurationMock
 .find('.conf
@@ -928,36 +928,27 @@
  expect(
-handleModifyO
+o
 utliers
+Spy
 .callCou
@@ -1103,32 +1103,33 @@
 umChanges = 10;%0A
+%0A
     const handle
@@ -1126,229 +1126,8 @@
 nst 
-handleModifyScale = sinon.spy();%0A    const c = shallow(%0A      %3CConfiguration%0A        configureScale=%7Btrue%7D%0A        whitelistedPopulations=%7B%5B'All'%5D%7D%0A        handleModifyScale=%7BhandleModifyScale%7D%0A      /%3E%0A    );%0A%0A    const 
 line
@@ -1135,32 +1135,48 @@
 rRadioButton = c
+onfigurationMock
 .find('.configur
@@ -1222,16 +1222,32 @@
 tton = c
+onfigurationMock
 .find('.
@@ -1495,33 +1495,24 @@
  expect(
-handleModifyScale
+scaleSpy
 .callCou

Clean up Configuration tests