[improvement] ActionSheet: add test cases

This commit is contained in:
陈嘉涵 2019-05-30 21:05:56 +08:00
parent cc36334625
commit e8daae912a
2 changed files with 55 additions and 1 deletions

View File

@ -4,6 +4,10 @@ exports[`callback events 1`] = `
<div class="van-popup van-popup--bottom van-action-sheet" name="van-popup-slide-bottom">
<div class="van-action-sheet__item van-hairline--top"><span class="van-action-sheet__name">Option</span></div>
<div class="van-action-sheet__item van-action-sheet__item--disabled van-hairline--top"><span class="van-action-sheet__name">Option</span></div>
<div class="van-action-sheet__item van-action-sheet__item--disabled van-hairline--top">
<div class="van-loading van-loading--circular"><span class="van-loading__spinner van-loading__spinner--circular" style="color: rgb(201, 201, 201); width: 20px; height: 20px;"><svg viewBox="25 25 50 50" class="van-loading__circular"><circle cx="50" cy="50" r="20" fill="none"></circle></svg></span></div>
</div>
<div class="van-action-sheet__item van-hairline--top"><span class="van-action-sheet__name">Option</span><span class="van-action-sheet__subname">Subname</span></div>
<div class="van-action-sheet__cancel">Cancel</div>
</div>
`;
@ -15,3 +19,5 @@ exports[`disable lazy-render 1`] = `
<div class="van-action-sheet__cancel">Cancel</div>
</div>
`;
exports[`render title and default slot 1`] = ``;

View File

@ -9,7 +9,9 @@ test('callback events', () => {
const actions = [
{ name: 'Option', callback },
{ name: 'Option', disabled: true }
{ name: 'Option', disabled: true },
{ name: 'Option', loading: true },
{ name: 'Option', subname: 'Subname' },
];
const wrapper = mount(ActionSheet, {
@ -39,6 +41,37 @@ test('callback events', () => {
expect(wrapper).toMatchSnapshot();
});
test('click overlay and close', () => {
const onInput = jest.fn();
const div = document.createElement('div');
mount({
template: `
<div>
<action-sheet
:value="true"
:get-container="getContainer"
@input="onInput"
/>
</div>
`,
components: {
ActionSheet
},
data() {
return {
getContainer: () => div
};
},
methods: {
onInput
}
});
div.querySelector('.van-overlay').click();
expect(onInput).toHaveBeenCalledWith(false);
});
test('disable lazy-render', () => {
const wrapper = mount(ActionSheet, {
propsData: {
@ -54,6 +87,21 @@ test('disable lazy-render', () => {
expect(wrapper).toMatchSnapshot();
});
test('render title and default slot', () => {
const wrapper = mount(ActionSheet, {
propsData: {
title: 'Title'
},
scopedSlots: {
default() {
return 'Default';
}
}
});
expect(wrapper).toMatchSnapshot();
});
test('get container', () => {
const wrapper = mount(ActionSheet, {
propsData: {