Skip to content

Commit

Permalink
Merge f227b80 into 831f72b
Browse files Browse the repository at this point in the history
  • Loading branch information
Leopoldthecoder committed Oct 21, 2016
2 parents 831f72b + f227b80 commit b951299
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/slider/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
v-model="inputValue"
v-if="showInput"
class="el-slider__input"
@keyup.native="onInputChange()"
@keyup.native="onInputChange"
ref="input"
:step="step"
:min="min"
Expand Down
36 changes: 27 additions & 9 deletions test/unit/specs/slider.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createTest, createVue } from '../util';
import { createTest, createVue, triggerEvent } from '../util';
import Slider from 'packages/slider';
import Vue from 'vue';

describe('Slider', () => {
it('create', () => {
Expand All @@ -26,10 +25,10 @@ describe('Slider', () => {
}, true);
setTimeout(() => {
vm.value = 40;
Vue.nextTick(() => {
vm.$nextTick(() => {
expect(vm.value).to.equal(50);
vm.value = 120;
Vue.nextTick(() => {
vm.$nextTick(() => {
expect(vm.value).to.equal(100);
done();
});
Expand All @@ -38,12 +37,30 @@ describe('Slider', () => {
});

it('show tooltip', () => {
const vm = createTest(Slider);
const vm = createVue({
template: `
<div>
<el-slider v-model="value">
</el-slider>
</div>
`,

data() {
return {
value: 0
};
}
}, true);
const slider = vm.$children[0];
const popup = vm.$el.querySelector('.el-slider__pop');
vm.onDragStart({ clientX: 0 });
expect(getComputedStyle(popup).display).to.not.equal('none');
vm.onDragEnd();
expect(popup.style.display).to.equal('none');
slider.onDragStart({ clientX: 0 });
vm.$nextTick(() => {
expect(popup.style.display).to.not.equal('none');
slider.onDragEnd();
setTimeout(() => {
expect(popup.style.display).to.equal('none');
}, 350);
});
});

it('drag', done => {
Expand Down Expand Up @@ -109,6 +126,7 @@ describe('Slider', () => {
}
}, true);
setTimeout(() => {
triggerEvent(vm.$el.querySelector('.el-input-number'), 'keyup');
const inputNumber = vm.$el.querySelector('.el-input-number').__vue__;
inputNumber.currentValue = 40;
setTimeout(() => {
Expand Down
7 changes: 5 additions & 2 deletions test/unit/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ exports.createTest = function(Compo, propsData = {}, mounted = false) {

/**
* 触发一个事件
* mouseenter, mouseleave, mouseover 等
* mouseenter, mouseleave, mouseover, keyup
* @param {Element} elm
* @param {EventName} name
* @param {options} opts
*/
exports.triggerEvent = function(elm, name, opts) {
const evt = document.createEvent('MouseEvents');
const isMouseEvent = /^mouse/.test(name);
const isKeyEvent = /^key/.test(name);
if (!isMouseEvent && !isKeyEvent) return;
const evt = document.createEvent(isMouseEvent ? 'MouseEvents' : 'KeyboardEvent');

evt.initEvent(name, ...opts);
elm.dispatchEvent
Expand Down

0 comments on commit b951299

Please sign in to comment.