TimeSelect: improve test

This commit is contained in:
qingwei.li 2016-10-25 19:23:57 +08:00
parent 2f0ba607f4
commit ede57a7abf
2 changed files with 63 additions and 5 deletions

View File

@ -27,6 +27,7 @@
minutes minutes
}; };
} }
/* istanbul ignore next */
return null; return null;
}; };

View File

@ -1,4 +1,4 @@
import { createTest, createVue } from '../util'; import { createTest, createVue, destroyVM } from '../util';
import TimeSelect from 'packages/time-select'; import TimeSelect from 'packages/time-select';
import Vue from 'vue'; import Vue from 'vue';
@ -14,7 +14,6 @@ describe('TimeSelect', () => {
}, true); }, true);
const input = vm.$el.querySelector('input'); const input = vm.$el.querySelector('input');
input.blur();
input.focus(); input.focus();
input.blur(); input.blur();
@ -23,6 +22,7 @@ describe('TimeSelect', () => {
expect(vm.picker.end).to.equal('18:30'); expect(vm.picker.end).to.equal('18:30');
expect(vm.picker.step).to.equal('00:15'); expect(vm.picker.step).to.equal('00:15');
expect(vm.$el.querySelector('input').getAttribute('placeholder')).to.equal('test'); expect(vm.$el.querySelector('input').getAttribute('placeholder')).to.equal('test');
destroyVM(vm);
done(); done();
}); });
}); });
@ -44,7 +44,6 @@ describe('TimeSelect', () => {
}, true); }, true);
const input = vm.$el.querySelector('input'); const input = vm.$el.querySelector('input');
input.blur();
input.focus(); input.focus();
input.blur(); input.blur();
@ -56,6 +55,7 @@ describe('TimeSelect', () => {
target.click(); target.click();
Vue.nextTick(_ => { Vue.nextTick(_ => {
expect(vm.value).to.equal(time); expect(vm.value).to.equal(time);
destroyVM(vm);
done(); done();
}); });
}); });
@ -67,7 +67,6 @@ describe('TimeSelect', () => {
}, true); }, true);
const input = vm.$el.querySelector('input'); const input = vm.$el.querySelector('input');
input.blur();
input.focus(); input.focus();
input.blur(); input.blur();
@ -75,7 +74,65 @@ describe('TimeSelect', () => {
expect(input.value).to.equal('14:30'); expect(input.value).to.equal('14:30');
expect(vm.picker.$el.querySelector('.selected')).to.be.ok; expect(vm.picker.$el.querySelector('.selected')).to.be.ok;
expect(vm.picker.$el.querySelector('.selected').textContent).to.equal('14:30'); expect(vm.picker.$el.querySelector('.selected').textContent).to.equal('14:30');
destroyVM(vm);
done(); done();
}, 500); }, 50);
});
it('set minTime', done => {
const vm = createVue(`
<el-time-select
ref="picker"
:picker-options="{
minTime: '14:30'
}">
</el-time-select>
`, true);
const input = vm.$el.querySelector('input');
const picker = vm.$refs.picker;
input.focus();
input.blur();
setTimeout(_ => {
const elms = picker.picker.$el.querySelectorAll('.disabled');
const elm = elms[elms.length - 1];
expect(elm.textContent).to.equal('14:30');
destroyVM(vm);
done();
}, 50);
});
it('minTime < value', done => {
const vm = createVue({
template: `
<el-time-select
ref="picker"
v-model="value"
:picker-options="{
minTime: '14:30'
}">
</el-time-select>
`,
data() {
return { value: '09:30' };
}
}, true);
const input = vm.$el.querySelector('input');
const picker = vm.$refs.picker;
input.focus();
input.blur();
setTimeout(_ => {
vm.value = '10:30';
setTimeout(_ => {
expect(picker.picker.value).to.equal('09:30');
destroyVM(vm);
done();
}, 50);
}, 50);
}); });
}); });