<commit_before>import React from 'react';
import { expect } from 'chai';
import { shallow, mount } from 'enzyme';
import sinon from 'sinon';
import { scaleLinear } from 'd3';

import Slider from '../src/slider';
import SliderHandle from '../src/slider-handle';

describe('ChoroplethLegend <Slider />', () => {
  const domain = [0, 100];
  const width = 1000;
  const xScale = scaleLinear()
    .domain(domain)
    .range([0, width])
    .clamp(true);
  const onSliderMove = sinon.spy((extent) => {
    return extent;
  });
  const minExtent = 25;
  const maxExtent = 75;

  describe('responds to range extent', () => {
    const wrapper = shallow(
      <Slider
        domain={domain}
        xScale={xScale}
        rangeExtent={[minExtent, maxExtent]}
        width={width}
        onSliderMove={onSliderMove}
      />
    );

    it('places brush handles on the left and ridge edges of the range extent', () => {
      expect(wrapper.find(SliderHandle).first()).to.have.prop('position', xScale(minExtent));
      expect(wrapper.find(SliderHandle).last()).to.have.prop('position', xScale(maxExtent));
    });

    it('produces gray rects of appropriate width based on range extent', () => {
      expect(wrapper.find('rect').first()).to.have.attr('width', `${xScale(minExtent)}`);
      expect(wrapper.find('rect').last()).to.have.attr('width', `${width - xScale(maxExtent)}`);
    });
  });

  describe('publishes updated range extent', () => {
    let wrapper;

    beforeEach(() => {
      wrapper = mount(
        <Slider
          domain={domain}
          xScale={xScale}
          rangeExtent={[minExtent, maxExtent]}
          width={width}
          onSliderMove={onSliderMove}
        />
      );
      onSliderMove.reset();
    });

    afterEach(() => {
      wrapper.unmount();
    });

    it('supplied sliderMove evt is triggered by dragmove event on brush handles ', () => {
      expect(onSliderMove.callCount).to.equal(0);

      // trigger dragmove handler
      wrapper.find(SliderHandle).get(0).onHandleMove({ dx: 10 });

      expect(onSliderMove.callCount).to.equal(1);
    });

    it('does not trigger supplied sliderMove evt when handle is moved off slider', () => {
      expect(onSliderMove.callCount).to.equal(0);
      wrapper.find(SliderHandle).get(1).onHandleMove({ dx: 300 });
      expect(onSliderMove.callCount).to.equal(0);
    });

    it('snaps to bounds of slider within tolerance', () => {
      wrapper.find(SliderHandle).get(0).onHandleMove({ dx: -248 });
      expect(onSliderMove.lastCall.args[0]).to.deep.equal([0, 0.75]);

      wrapper.find(SliderHandle).get(1).onHandleMove({ dx: 248 });
      expect(onSliderMove.lastCall.args[0]).to.deep.equal([0.25, 1]);
    });
  });
});<commit_msg>With enzyme update to 3.x.x need to update slider tests to call method on slider handle component<commit_after>import React from 'react';
import { expect } from 'chai';
import { shallow, mount } from 'enzyme';
import sinon from 'sinon';
import { scaleLinear } from 'd3';

import Slider from '../src/slider';
import SliderHandle from '../src/slider-handle';

describe('ChoroplethLegend <Slider />', () => {
  const domain = [0, 100];
  const width = 1000;
  const xScale = scaleLinear()
    .domain(domain)
    .range([0, width])
    .clamp(true);
  const onSliderMove = sinon.spy((extent) => {
    return extent;
  });
  const minExtent = 25;
  const maxExtent = 75;

  describe('responds to range extent', () => {
    const wrapper = shallow(
      <Slider
        domain={domain}
        xScale={xScale}
        rangeExtent={[minExtent, maxExtent]}
        width={width}
        onSliderMove={onSliderMove}
      />
    );

    it('places brush handles on the left and ridge edges of the range extent', () => {
      expect(wrapper.find(SliderHandle).first()).to.have.prop('position', xScale(minExtent));
      expect(wrapper.find(SliderHandle).last()).to.have.prop('position', xScale(maxExtent));
    });

    it('produces gray rects of appropriate width based on range extent', () => {
      expect(wrapper.find('rect').first()).to.have.attr('width', `${xScale(minExtent)}`);
      expect(wrapper.find('rect').last()).to.have.attr('width', `${width - xScale(maxExtent)}`);
    });
  });

  describe('publishes updated range extent', () => {
    let wrapper;

    beforeEach(() => {
      wrapper = mount(
        <Slider
          domain={domain}
          xScale={xScale}
          rangeExtent={[minExtent, maxExtent]}
          width={width}
          onSliderMove={onSliderMove}
        />
      );
      onSliderMove.reset();
    });

    afterEach(() => {
      wrapper.unmount();
    });

    it('supplied sliderMove evt is triggered by dragmove event on brush handles ', () => {
      expect(onSliderMove.callCount).to.equal(0);

      wrapper.find(SliderHandle).first().instance().onHandleMove({ dx: 10 });

      expect(onSliderMove.callCount).to.equal(1);
    });

    it('does not trigger supplied sliderMove evt when handle is moved off slider', () => {
      expect(onSliderMove.callCount).to.equal(0);
      wrapper.find(SliderHandle).last().instance().onHandleMove({ dx: 300 });
      expect(onSliderMove.callCount).to.equal(0);
    });

    it('snaps to bounds of slider within tolerance', () => {
      wrapper.find(SliderHandle).first().instance().onHandleMove({ dx: -248 });
      expect(onSliderMove.lastCall.args[0]).to.deep.equal([0, 0.75]);

      wrapper.find(SliderHandle).last().instance().onHandleMove({ dx: 248 });
      expect(onSliderMove.lastCall.args[0]).to.deep.equal([0.25, 1]);
    });
  });
});
{'fraction_non_alphanumeric': 0.16905958363244794, 'fraction_numerical': 0.014895908111988513, 'mean_word_length': 3.125092524056255, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, 'https://': 0, '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': '7657378', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1731, 'n_words': 361}