<commit_before>describe('Range input', function() {

  'use strict';

  beforeEach(function(done) {
    var self = this;
    window.Modernizr = {
      inputtypes: {
        range: true
      }
    };
    requirejs(
        ['jquery', 'RangeInput', 'featureDetect', 'eventsWithPromises'],
        function($, RangeInput, featureDetect, eventsWithPromises) {
          self.featureDetect = featureDetect;
          self.$html = $(window.__html__['test/fixtures/RangeInput.html']);
          self.RangeInput = RangeInput;
          self.eventsWithPromises = eventsWithPromises;
          done();
        }, done);
  });

  it('creates a copy of the input and label if the range slider type is supported', function() {
    this.featureDetect.inputtypes.range = true;
    this.rangeInput = new this.RangeInput(this.$html);
    this.rangeInput.init();
    expect(this.$html.find('input').length).to.equal(2);
    expect(this.$html.find('label').length).to.equal(2);
  });

  it('doesn\'t create an extra input if the range slider type isn\'t supported', function() {
    this.featureDetect.inputtypes.range = false;
    this.rangeInput = new this.RangeInput(this.$html);
    this.rangeInput.init();
    expect(this.$html.find('input').length).to.equal(1);
    expect(this.$html.find('label').length).to.equal(1);
  });

  it('keeps both input values in sync', function() {
    var $inputText,
        $inputSlider;

    this.featureDetect.inputtypes.range = true;
    this.rangeInput = new this.RangeInput(this.$html);
    this.rangeInput.init();
    $inputText = this.$html.find('[data-dough-range-input]');
    $inputSlider = this.$html.find('.form__input-range');
    $inputText.val('2000').trigger('change');
    expect($inputSlider.val()).to.equal('2000');
    $inputText.val('50000').trigger('change');
    expect($inputSlider.val()).to.equal('5000');
  });

  it('publishes an event when the value changes', function() {
    var spy = sinon.spy(),
        $input = this.$html.find('[data-dough-range-input]');
    this.featureDetect.inputtypes.range = true;
    this.rangeInput = new this.RangeInput(this.$html);
    this.rangeInput.init();
    this.eventsWithPromises.subscribe('rangeInput:change', spy);
    $input.val('3000').trigger('change');
    sinon.assert.calledWith(spy, {
      emitter: $input,
      value: '3000'
    });
  });

});<commit_msg>RangeInput - refactor / add tests<commit_after>describe('Range input', function () {

  'use strict';

  before(function (done) {
    var self = this;
    window.Modernizr = {
      inputtypes: {
        range: true
      }
    };
    requirejs(
        ['jquery', 'RangeInput', 'featureDetect', 'eventsWithPromises'],
        function ($, RangeInput, featureDetect, eventsWithPromises) {
          self.featureDetect = featureDetect;
          self.RangeInput = RangeInput;
          self.eventsWithPromises = eventsWithPromises;
          done();
        }, done);
  });

  beforeEach(function(){
    this.$html = $(window.__html__['test/fixtures/RangeInput.html']);
  });

  afterEach(function() {
    this.$html.remove();
  });

  describe('Range inputs supported', function () {

    beforeEach(function () {
      this.featureDetect.inputtypes.range = true;
      this.rangeInput = new this.RangeInput(this.$html);
      this.rangeInput.init();
      this.$inputText = this.$html.find('[data-dough-range-input]');
      this.$inputSlider = this.$html.find('.form__input-range');

    });

    it('creates a copy of the input and label if the range slider type is supported', function () {
      expect(this.$html.find('input').length).to.equal(2);
      expect(this.$html.find('label').length).to.equal(2);
    });


    it('keeps the slider in sync if the text input changes', function () {
      this.$inputText.val('2000').trigger('change');
      expect(this.$inputSlider.val()).to.equal('2000');
      this.$inputText.val('50000').trigger('change');
      expect(this.$inputSlider.val()).to.equal('5000'); // because range input has a max of 5000
    });

    it('keeps the text input in sync if the slider changes', function () {
      this.$inputSlider.val('2000').trigger('change');
      expect(this.$inputText.val()).to.equal('2000');
    });

    it('publishes an event when the value changes', function () {
      var spy = sinon.spy();
      this.eventsWithPromises.subscribe('rangeInput:change', spy);
      this.$inputText.val('3000').trigger('change');
      sinon.assert.calledWith(spy, {
        emitter: this.$inputText,
        value: '3000'
      });
    });

  });


  describe('Range inputs supported but don\'t keep inputs in sync', function () {

    beforeEach(function () {
      this.featureDetect.inputtypes.range = true;
      this.rangeInput = new this.RangeInput(this.$html, {
        keepSynced: false
      });
      this.rangeInput.init();
      this.$inputText = this.$html.find('[data-dough-range-input]');
      this.$inputSlider = this.$html.find('.form__input-range');

    });

    it('creates a copy of the input and label if the range slider type is supported', function () {
      expect(this.$html.find('input').length).to.equal(2);
      expect(this.$html.find('label').length).to.equal(2);
    });
  });

  describe('Range inputs not supported', function () {

    beforeEach(function () {
      this.featureDetect.inputtypes.range = false;
      this.rangeInput = new this.RangeInput(this.$html);
      this.rangeInput.init();
      this.$inputText = this.$html.find('[data-dough-range-input]');
      this.$inputSlider = this.$html.find('.form__input-range');
    });

    it('keeps the text input in sync if the slider changes', function () {
      this.$inputSlider.val('2000').trigger('change');
      expect(this.$inputText.val()).to.equal('1500');
    });
  });

});
{'fraction_non_alphanumeric': 0.1690871369294606, 'fraction_numerical': 0.013485477178423237, 'mean_word_length': 3.1529073941134245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3371479', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1717, 'n_words': 325}