fix(ShareSheet): title slot not work

This commit is contained in:
chenjiahan
2020-04-09 13:09:32 +08:00
committed by neverland
parent fc4d89b474
commit 1d07aa88ba
7 changed files with 148 additions and 47 deletions
@@ -23,5 +23,12 @@ exports[`renders demo correctly 1`] = `
</div>
<!---->
</div>
<div>
<div role="button" tabindex="0" class="van-cell van-cell--clickable">
<div class="van-cell__title"><span>显示分享面板</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
<!----></i>
</div>
<!---->
</div>
</div>
`;
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`cancel-text prop 1`] = `<button type="button" class="van-share-sheet__cancel">foo</button>`;
exports[`description prop 1`] = `<span class="van-share-sheet__description">foo</span>`;
exports[`title & description slot 1`] = `
<div class="van-popup van-popup--round van-popup--bottom van-popup--safe-area-inset-bottom van-share-sheet" name="van-popup-slide-bottom">
<div class="van-share-sheet__header">
<h2 class="van-share-sheet__title">Custom Title</h2><span class="van-share-sheet__description">Custom Description</span>
</div>
<div class="van-share-sheet__options"></div><button type="button" class="van-share-sheet__cancel">取消</button>
</div>
`;
+72
View File
@@ -0,0 +1,72 @@
import ShareSheet from '..';
import { mount } from '../../../test';
test('cancel-text prop', () => {
const wrapper = mount(ShareSheet, {
propsData: {
value: true,
cancelText: 'foo',
},
});
expect(wrapper.find('.van-share-sheet__cancel')).toMatchSnapshot();
wrapper.setProps({ cancelText: '' });
expect(wrapper.contains('.van-share-sheet__cancel')).toBeFalsy();
});
test('description prop', () => {
const wrapper = mount(ShareSheet, {
propsData: {
value: true,
description: 'foo',
},
});
expect(wrapper.find('.van-share-sheet__description')).toMatchSnapshot();
wrapper.setProps({ description: '' });
expect(wrapper.contains('.van-share-sheet__description')).toBeFalsy();
});
test('select event', () => {
const wrapper = mount(ShareSheet, {
propsData: {
value: true,
options: [{ icon: 'wechat', name: 'wechat' }],
},
});
wrapper.find('.van-share-sheet__option').trigger('click');
expect(wrapper.emitted('select')[0]).toEqual([
{ icon: 'wechat', name: 'wechat' },
0,
]);
});
test('cancel event', () => {
const wrapper = mount(ShareSheet, {
propsData: {
value: true,
},
});
wrapper.find('.van-share-sheet__cancel').trigger('click');
expect(wrapper.emitted('input')[0][0]).toEqual(false);
expect(wrapper.emitted('cancel')[0]).toBeTruthy();
});
test('title & description slot', () => {
const wrapper = mount(ShareSheet, {
propsData: {
value: true,
},
scopedSlots: {
title: () => 'Custom Title',
description: () => 'Custom Description',
},
});
expect(wrapper).toMatchSnapshot();
});