improve the test coverage (#11447)

This commit is contained in:
Jikkai Xiao 2018-06-01 11:27:53 +08:00 committed by baiyaaaaa
parent 203744a686
commit 40cf8ee0e6
4 changed files with 88 additions and 3 deletions

View File

@ -27,6 +27,28 @@ describe('Menu', () => {
}, 20);
}, 20);
});
it('background-color', done => {
vm = createVue({
template: `
<el-menu default-active="2"
background-color="#f00"
text-color="#000"
active-text-color="#0f0">
<el-menu-item index="1" ref="item1">处理中心</el-menu-item>
<el-menu-item index="2" ref="item2">订单管理</el-menu-item>
</el-menu>
`
}, true);
expect(vm.$el.style.backgroundColor).to.equal('rgb(255, 0, 0)');
expect(vm.$refs.item1.$el.style.backgroundColor).to.equal('rgb(255, 0, 0)');
expect(vm.$refs.item1.$el.style.color).to.equal('rgb(0, 0, 0)');
expect(vm.$refs.item2.$el.style.color).to.equal('rgb(0, 255, 0)');
triggerEvent(vm.$refs.item1.$el, 'mouseenter');
setTimeout(_ => {
expect(vm.$refs.item1.$el.style.backgroundColor).to.equal('rgb(204, 0, 0)');
done();
}, 20);
});
it('menu-item click', done => {
vm = createVue({
template: `

View File

@ -50,6 +50,25 @@ describe('Radio', () => {
done();
}, 10);
});
it('border', () => {
vm = createVue({
template: `
<el-radio
v-model="radio"
label="3"
border
>
</el-radio>
`,
data() {
return {
radio: ''
};
}
}, true);
let radioElm = vm.$el;
expect(radioElm.classList.contains('is-bordered')).to.be.true;
});
it('change event', done => {
vm = createVue({
template: `

View File

@ -112,12 +112,13 @@ describe('Slider', () => {
vm = createVue({
template: `
<div>
<el-slider v-model="value"></el-slider>
<el-slider v-model="value" :vertical="vertical"></el-slider>
</div>
`,
data() {
return {
vertical: false,
value: 0
};
}
@ -128,7 +129,44 @@ describe('Slider', () => {
slider.onDragEnd();
setTimeout(() => {
expect(vm.value > 0).to.true;
done();
vm.vertical = true;
vm.value = 0;
vm.$nextTick(() => {
expect(vm.value === 0).to.true;
slider.onButtonDown({ clientY: 0, preventDefault() {} });
slider.onDragging({ clientY: -100 });
slider.onDragEnd();
setTimeout(() => {
expect(vm.value > 0).to.true;
done();
}, 10);
});
}, 10);
});
it('accessibility', done => {
vm = createVue({
template: `
<div>
<el-slider v-model="value"></el-slider>
</div>
`,
data() {
return {
value: 0.1
};
}
}, true);
const slider = vm.$children[0].$children[0];
slider.onRightKeyDown();
setTimeout(() => {
expect(vm.value).to.equal(1);
slider.onLeftKeyDown();
setTimeout(() => {
expect(vm.value).to.equal(0);
done();
}, 10);
}, 10);
});

View File

@ -37,7 +37,11 @@ describe('Switch', () => {
vm = createVue({
template: `
<div>
<el-switch v-model="value"></el-switch>
<el-switch
v-model="value"
activeColor="#0f0"
inactiveColor="#f00">
</el-switch>
</div>
`,
@ -49,8 +53,10 @@ describe('Switch', () => {
}, true);
const core = vm.$el.querySelector('.el-switch__core');
expect(core.style.backgroundColor).to.equal('rgb(0, 255, 0)');
core.click();
setTimeout(() => {
expect(core.style.backgroundColor).to.equal('rgb(255, 0, 0)');
expect(vm.value).to.equal(false);
core.click();
setTimeout(() => {