mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 16:44:21 +00:00
actionsheet unit test
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import Vue from 'vue';
|
||||
import ActionSheet from 'packages/actionsheet';
|
||||
import { mount } from 'avoriaz';
|
||||
|
||||
@@ -13,5 +14,103 @@ describe('ActionSheet', () => {
|
||||
});
|
||||
|
||||
expect(wrapper.hasClass('zan-actionsheet')).to.be.true;
|
||||
expect(wrapper.contains('.zan-actionsheet__list')).to.be.true;
|
||||
expect(wrapper.instance().actions.length).to.equal(0);
|
||||
expect(wrapper.instance().overlay).to.be.true;
|
||||
expect(wrapper.instance().closeOnClickOverlay).to.be.true;
|
||||
});
|
||||
|
||||
it('create displayed actionsheet', () => {
|
||||
wrapper = mount(ActionSheet, {
|
||||
propsData: {
|
||||
value: true
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper.instance().currentValue).to.be.true;
|
||||
});
|
||||
|
||||
it('create title type actionsheet', () => {
|
||||
wrapper = mount(ActionSheet, {
|
||||
propsData: {
|
||||
title: 'test'
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper.hasClass('zan-actionsheet--withtitle')).to.be.true;
|
||||
expect(wrapper.contains('.zan-actionsheet__header')).to.be.true;
|
||||
expect(wrapper.contains('.zan-actionsheet__content')).to.be.true;
|
||||
});
|
||||
|
||||
it('create actions actionsheet', () => {
|
||||
wrapper = mount(ActionSheet, {
|
||||
propsData: {
|
||||
actions: [
|
||||
{
|
||||
name: '有赞E卡',
|
||||
subname: '(剩余260.50元)'
|
||||
},
|
||||
{
|
||||
name: '信用卡支付',
|
||||
loading: true
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
const actionItems = wrapper.find('.zan-actionsheet__item');
|
||||
|
||||
expect(actionItems.length).to.equal(2);
|
||||
expect(actionItems[0].contains('.zan-actionsheet__name')).to.be.true;
|
||||
expect(actionItems[0].contains('.zan-actionsheet__subname')).to.be.true;
|
||||
expect(actionItems[1].contains('.zan-actionsheet__loading')).to.be.true;
|
||||
});
|
||||
|
||||
it('handle actionsheet item click with callback', () => {
|
||||
let called = false;
|
||||
wrapper = mount(ActionSheet, {
|
||||
propsData: {
|
||||
actions: [
|
||||
{
|
||||
name: '有赞E卡',
|
||||
callback: () => {
|
||||
called = true;
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
const actionItem = wrapper.find('.zan-actionsheet__item')[0];
|
||||
actionItem.simulate('click');
|
||||
expect(called).to.be.true;
|
||||
});
|
||||
|
||||
it('create actionsheet with cancel button', () => {
|
||||
wrapper = mount(ActionSheet, {
|
||||
propsData: {
|
||||
cancelText: 'cancel'
|
||||
}
|
||||
});
|
||||
|
||||
const cancelButton = wrapper.find('.zan-actionsheet__button')[0];
|
||||
expect(wrapper.contains('.zan-actionsheet__button')).to.be.true;
|
||||
expect(cancelButton.text()).to.equal('cancel');
|
||||
});
|
||||
|
||||
it('toggle actionsheet value', () => {
|
||||
wrapper = mount(ActionSheet, {
|
||||
propsData: {
|
||||
value: false
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper.data().currentValue).to.be.false;
|
||||
wrapper.vm.value = true;
|
||||
wrapper.update();
|
||||
Vue.nextTick(() => {
|
||||
expect(wrapper.data().currentValue).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -110,7 +110,6 @@ describe('Switch', () => {
|
||||
});
|
||||
|
||||
it('toggle switch value from v-model', function(done) {
|
||||
let checked = false;
|
||||
wrapper = mount(Switch, {
|
||||
propsData: {
|
||||
value: false
|
||||
|
Reference in New Issue
Block a user