improve tests (#3033)

pull/3063/head
杨奕 2017-02-24 17:37:06 +08:00 committed by baiyaaaaa
parent c77489a44e
commit 067541e8d9
7 changed files with 102 additions and 13 deletions

View File

@ -474,7 +474,8 @@ There are two ways to expand child option items.
label: 'Design Documentation' label: 'Design Documentation'
}] }]
}], }],
selectedOptions: [] selectedOptions: [],
selectedOptions2: []
}; };
}, },
methods: { methods: {

View File

@ -505,7 +505,8 @@
label: '组件交互文档' label: '组件交互文档'
}] }]
}], }],
selectedOptions: [] selectedOptions: [],
selectedOptions2: []
}; };
}, },
methods: { methods: {

View File

@ -47,11 +47,9 @@
this.cursorTop = (100 - value) * height / 100; this.cursorTop = (100 - value) * height / 100;
this.background = 'hsl(' + this.color.get('hue') + ', 100%, 50%)'; this.background = 'hsl(' + this.color.get('hue') + ', 100%, 50%)';
} },
},
mounted() { handleDrag(event) {
const handleDrag = (event) => {
const el = this.$el; const el = this.$el;
const rect = el.getBoundingClientRect(); const rect = el.getBoundingClientRect();
@ -69,14 +67,16 @@
saturation: left / rect.width * 100, saturation: left / rect.width * 100,
value: 100 - top / rect.height * 100 value: 100 - top / rect.height * 100
}); });
}; }
},
mounted() {
draggable(this.$el, { draggable(this.$el, {
drag: (event) => { drag: (event) => {
handleDrag(event); this.handleDrag(event);
}, },
end: (event) => { end: (event) => {
handleDrag(event); this.handleDrag(event);
} }
}); });

View File

@ -209,6 +209,7 @@
padding: 6px; padding: 6px;
border: 1px solid #bfcbd9; border: 1px solid #bfcbd9;
border-radius: 4px; border-radius: 4px;
font-size: 0;
} }
@descendent color { @descendent color {
@ -237,7 +238,7 @@
@descendent empty { @descendent empty {
font-size: 12px; font-size: 12px;
vertical-align: middle; vertical-align: middle;
margin-top: -2px; margin-top: 4px;
color: #666; color: #666;
} }
@ -248,6 +249,7 @@
margin-left: 8px; margin-left: 8px;
width: 12px; width: 12px;
color: #888; color: #888;
font-size: 12px;
} }
@descendent panel { @descendent panel {

View File

@ -138,7 +138,7 @@ describe('Carousel', () => {
vm = createVue({ vm = createVue({
template: ` template: `
<div> <div>
<el-carousel :autoplay="false" trigger="click"> <el-carousel :autoplay="false" trigger="click" ref="carousel">
<el-carousel-item v-for="item in 3"></el-carousel-item> <el-carousel-item v-for="item in 3"></el-carousel-item>
</el-carousel> </el-carousel>
</div> </div>
@ -147,9 +147,11 @@ describe('Carousel', () => {
setTimeout(() => { setTimeout(() => {
const items = vm.$el.querySelectorAll('.el-carousel__item'); const items = vm.$el.querySelectorAll('.el-carousel__item');
const carousel = vm.$refs.carousel;
vm.$el.querySelectorAll('.el-carousel__indicator')[2].click(); vm.$el.querySelectorAll('.el-carousel__indicator')[2].click();
setTimeout(() => { setTimeout(() => {
expect(items[2].classList.contains('is-active')).to.true; expect(items[2].classList.contains('is-active')).to.true;
carousel.handleButtonEnter('right');
vm.$el.querySelector('.el-carousel__arrow--right').click(); vm.$el.querySelector('.el-carousel__arrow--right').click();
setTimeout(() => { setTimeout(() => {
expect(items[0].classList.contains('is-active')).to.true; expect(items[0].classList.contains('is-active')).to.true;

View File

@ -11,7 +11,7 @@ describe('ColorPicker', () => {
if (dropdown && dropdown.parentNode) dropdown.parentNode.removeChild(dropdown); if (dropdown && dropdown.parentNode) dropdown.parentNode.removeChild(dropdown);
}); });
it('should works', () => { it('should work', () => {
vm = createTest(ColorPicker, true); vm = createTest(ColorPicker, true);
expect(vm.$el).to.exist; expect(vm.$el).to.exist;
}); });
@ -133,5 +133,87 @@ describe('ColorPicker', () => {
}, 30); }, 30);
}, ANIMATION_TIME); }, ANIMATION_TIME);
}); });
it('should change hue when clicking the hue bar', (done) => {
const vm = createVue({
template: `
<el-color-picker v-model="color"></el-color-picker>
`,
data() {
return {
color: '#f00'
};
}
}, true);
const trigger = vm.$el.querySelector('.el-color-picker__trigger');
trigger.click();
setTimeout(() => {
const hueBar = document.querySelector('.el-color-hue-slider');
hueBar.__vue__.handleClick({ target: null, clientX: 0, clientY: 1000 });
vm.$nextTick(() => {
const picker = vm.$children[0];
expect(picker.color._hue > 0).to.true;
done();
});
}, ANIMATION_TIME);
});
it('should change alpha when clicking the alpha bar', (done) => {
const vm = createVue({
template: `
<el-color-picker v-model="color" show-alpha></el-color-picker>
`,
data() {
return {
color: '#f00'
};
}
}, true);
const trigger = vm.$el.querySelector('.el-color-picker__trigger');
trigger.click();
setTimeout(() => {
const alphaBar = document.querySelector('.el-color-alpha-slider');
alphaBar.__vue__.handleClick({ target: null, clientX: 50, clientY: 0 });
vm.$nextTick(() => {
const picker = vm.$children[0];
expect(picker.color._alpha < 1).to.true;
done();
});
}, ANIMATION_TIME);
});
it('should change saturation and value when clicking the sv-panel', (done) => {
const vm = createVue({
template: `
<el-color-picker v-model="color" color-format="hsv"></el-color-picker>
`,
data() {
return {
color: 'hsv(0, 50%, 50%)'
};
}
}, true);
const trigger = vm.$el.querySelector('.el-color-picker__trigger');
trigger.click();
setTimeout(() => {
const svPanel = document.querySelector('.el-color-svpanel');
svPanel.__vue__.handleDrag({ clientX: 0, clientY: 0 });
vm.$nextTick(() => {
const picker = vm.$children[0];
expect(picker.color._saturation !== 50).to.true;
expect(picker.color._value !== 50).to.true;
done();
});
}, ANIMATION_TIME);
});
}); });

View File

@ -146,7 +146,8 @@ describe('Menu', () => {
}); });
}); });
}); });
describe('submenu', () => { describe('submenu', function() {
this.timeout(3000);
it('toggle', done => { it('toggle', done => {
vm = createVue({ vm = createVue({
template: ` template: `