[Improvement] Slider: add step & bar-height prop (#915)

This commit is contained in:
neverland
2018-04-23 20:19:41 +08:00
committed by GitHub
parent 19f4c9c028
commit b93a2e3c00
7 changed files with 160 additions and 350 deletions

View File

@@ -19,7 +19,6 @@ describe('Slider', () => {
expect(wrapper.hasClass('van-slider')).to.be.true;
expect(wrapper.find('.van-slider__bar').length).to.equal(1);
expect(wrapper.find('.van-slider__finished-portion').length).to.equal(1);
expect(wrapper.vm.value).to.equal(50);
expect(wrapper.hasClass('van-slider--disabled')).to.equal(true);
@@ -40,8 +39,17 @@ describe('Slider', () => {
});
const eventStub = sinon.stub(wrapper.vm, '$emit');
const $bar = wrapper.find('.van-slider__bar')[0];
const $bar = wrapper.find('.van-slider')[0];
$bar.trigger('click');
const button = wrapper.find('.van-slider__button')[0];
triggerTouch(button, 'touchstart', 0, 0);
expect(wrapper.vm.startX).to.equal(undefined);
triggerTouch(button, 'touchmove', 50, 0);
expect(wrapper.vm.offsetX).to.equal(undefined);
triggerTouch(button, 'touchend', 50, 0);
expect(wrapper.vm.offsetX).to.equal(undefined);
expect(eventStub.called).to.equal(false);
@@ -55,44 +63,28 @@ describe('Slider', () => {
expect(eventStub.called).to.equal(true);
});
it('Customized style', () => {
const COLOR = '#123';
wrapper = mount(Slider, {
propsData: {
pivotColor: COLOR,
barColor: COLOR,
loadedBarColor: COLOR,
value: 50
}
});
expect(wrapper.vm.barStyle.backgroundColor).to.equal(COLOR);
expect(wrapper.vm.pivotStyle.backgroundColor).to.equal(COLOR);
expect(wrapper.vm.finishedStyle.backgroundColor).to.equal(COLOR);
});
it('drag pivot', () => {
it('drag button', () => {
wrapper = mount(Slider, {
propsData: {
value: 50
}
});
const pivot = wrapper.find('.van-slider__pivot')[0];
triggerTouch(pivot, 'touchstart', 0, 0);
const button = wrapper.find('.van-slider__button')[0];
triggerTouch(button, 'touchstart', 0, 0);
expect(wrapper.vm.startX).to.equal(0);
triggerTouch(pivot, 'touchmove', 50, 0);
triggerTouch(button, 'touchmove', 50, 0);
expect(wrapper.vm.offsetX).to.equal(50);
triggerTouch(pivot, 'touchend', 50, 0);
triggerTouch(button, 'touchend', 50, 0);
expect(wrapper.vm.offsetX).to.equal(50);
wrapper.setData({
disabled: true
});
triggerTouch(pivot, 'touchstart', 0, 0);
triggerTouch(button, 'touchstart', 0, 0);
expect(wrapper.vm.startX).to.equal(0);
});
});