Popup: add test cases

This commit is contained in:
陈嘉涵 2017-08-29 16:45:28 +08:00
parent 625f6e7d8d
commit 3a642fce0c
3 changed files with 59 additions and 1 deletions

View File

@ -99,6 +99,7 @@ export default {
* 显示popup
*/
open() {
/* istanbul ignore if */
if (this.$isServer) return;
if (this.opened) return;

View File

@ -34,7 +34,7 @@ describe('PayOrder', () => {
propsData: {
price: 3005,
buttonText: '提交订单',
buttonType: 'normal'
buttonType: 'default'
}
});

View File

@ -1,5 +1,6 @@
import Popup from 'packages/popup';
import { mount } from 'avoriaz';
import { triggerTouch } from '../utils';
describe('Popup', () => {
let wrapper;
@ -57,4 +58,60 @@ describe('Popup', () => {
expect(wrapper.hasClass('van-popup')).to.be.true;
expect(wrapper.instance().currentTransition).to.equal('popup-fade');
});
it('popup prevent scroll', (done) => {
wrapper = mount(Popup, {
propsData: {
preventScroll: true,
value: true
}
});
expect(wrapper.hasClass('van-popup')).to.be.true;
setTimeout(() => {
expect(wrapper.data().currentValue).to.be.true;
wrapper.vm.value = false;
triggerTouch(document, 'touchstart', 0, 0);
triggerTouch(document, 'touchmove', 0, 10);
triggerTouch(document, 'touchmove', 0, 30);
triggerTouch(document, 'touchmove', 0, -30);
setTimeout(() => {
expect(wrapper.data().currentValue).to.be.false;
done();
}, 300);
}, 300);
});
it('popup modal', (done) => {
wrapper = mount(Popup, {
propsData: {
preventScroll: true,
value: true
}
});
wrapper.vm.$on('input', val => {
wrapper.vm.value = val;
});
expect(wrapper.hasClass('van-popup')).to.be.true;
const modal = document.querySelector('.van-modal');
setTimeout(() => {
triggerTouch(modal, 'touchstart', 0, 0);
triggerTouch(modal, 'touchmove', 0, 10);
triggerTouch(modal, 'touchmove', 0, 30);
triggerTouch(modal, 'touchmove', 0, -30);
expect(modal).to.exist;
modal.click();
setTimeout(() => {
expect(wrapper.data().currentValue).to.be.false;
done();
}, 300);
}, 300);
});
});