
var expect = require('expect.js');
var Slider = require('../index.js');
var React = require('react');
var ReactDOM = require('react-dom');
var TestUtils = require('react-addons-test-utils');
var Simulate = TestUtils.Simulate;
var $ = require('jquery');
require('../assets/index.less');

describe('rc-slider', function () {
  this.timeout(5000);
  var div = document.createElement('div');
  document.body.appendChild(div);

  afterEach(function () {
    ReactDOM.unmountComponentAtNode(div);
  });

  it('should render a simple slider with value correctly!', function () {
    var slider = ReactDOM.render(
      <Slider className='rc-slider' defaultValue={40}/>,
      div
    );
    var node = $(div);
    expect(node.find('.rc-slider').length).to.be(1);
    expect(node.find('.rc-slider-handle').length).to.be(1);
    expect(node.find('.rc-slider-track').length).to.be(1);
    expect(slider.state.upperBound).to.be(40);
    var trackWidth = node.find('.rc-slider-track')[0].style.width;
    expect(trackWidth).to.eql(node.find('.rc-slider-handle')[0].style.left);
  });

  it('should render a slider with correct numbers of step!', function () {
    var slider = ReactDOM.render(
      <Slider className='rc-slider' step={20}/>,
      div
    );
    var node = $(div);
    expect(node.find('.rc-slider').length).to.be(1);
    expect(node.find('.rc-slider-handle').length).to.be(1);
    expect(node.find('.rc-slider-track').length).to.be(1);
    expect(slider.state.upperBound).to.be(0);

    var sliderWithDots = ReactDOM.render(
      <Slider className='rc-slider' step={20} dots/>,
      div
    );
    var node1 = $(div);
    expect(node1.find('.rc-slider-dot').length).to.be(6);
  });

  it('should render a slider with marks correctly!', function () {
    var slider = ReactDOM.render(
      <Slider marks={["一","二","三","四","五"]} defaultIndex={3} />,
      div
    );
    var node = $(div);
    expect(node.find('.rc-slider').length).to.be(1);
    expect(node.find('.rc-slider-handle').length).to.be(1);
    expect(node.find('.rc-slider-track').length).to.be(1);
    expect(node.find('.rc-slider-dot').length).to.be(slider.props.marks.length);
    expect(node.find('.rc-slider-mark').length).to.be(1);
    expect(node.find('.rc-slider-mark-text').length).to.be(slider.props.marks.length);
    expect(slider.getIndex(slider.state.upperBound)).to.be(3);
  });

  // it('should mouseDown works!', function (done) {
  //   var slider = ReactDOM.render(
  //     <Slider marks={["一","二","三","四","五"]} />,
  //     div
  //   );
  //   var selectedStep = slider.refs.step3.getDOMNode();

  //   Simulate.mouseDown(selectedStep);

  //   setTimeout( function() {
  //     expect(slider.state.active).to.be('active');
  //     done();
  //   }, 200);
  // });

});

@@ -1808,37 +1808,61 @@
  marks=%7B
-%5B%22%E4%B8%80%22,%22%E4%BA%8C%22,%22%E4%B8%89%22,%22%E5%9B%9B%22,%22%E4%BA%94%22%5D
+%7B0: %22%E4%B8%80%22, 20: %22%E4%BA%8C%22, 40: %22%E4%B8%89%22, 60: %22%E5%9B%9B%22, 100: %22%E4%BA%94%22%7D
 %7D defaul
@@ -1866,16 +1866,17 @@
 ault
-Index=%7B3
+Value=%7B40
 %7D /%3E
@@ -2134,32 +2134,44 @@
 ).length).to.be(
+Object.keys(
 slider.props.mar
@@ -2164,32 +2164,33 @@
 ider.props.marks
+)
 .length);%0A    ex
@@ -2300,16 +2300,28 @@
 ).to.be(
+Object.keys(
 slider.p
@@ -2330,16 +2330,17 @@
 ps.marks
+)
 .length)
@@ -2363,24 +2363,8 @@
 der.
-getIndex(slider.
 stat
@@ -2380,17 +2380,17 @@
 und)
-)
 .to.be(
-3
+40
 );%0A 

update unit test