feat(Dialog): add open、close event (#4633)

This commit is contained in:
neverland
2019-09-30 10:55:50 +08:00
committed by GitHub
parent 48bd6d86d8
commit 02a81a1ac3
5 changed files with 34 additions and 62 deletions

View File

@@ -2,20 +2,10 @@
exports[`renders demo correctly 1`] = `
<div>
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">
提示弹窗
</span></button> <button class="van-button van-button--primary van-button--normal"><span class="van-button__text">
提示弹窗(无标题)
</span></button></div>
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">
确认弹窗
</span></button></div>
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">
异步关闭
</span></button></div>
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">
组件调用
</span></button>
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">提示弹窗</span></button> <button class="van-button van-button--primary van-button--normal"><span class="van-button__text">提示弹窗(无标题)</span></button></div>
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">确认弹窗</span></button></div>
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">异步关闭</span></button></div>
<div><button class="van-button van-button--primary van-button--normal"><span class="van-button__text">组件调用</span></button>
<div role="dialog" aria-labelledby="标题" class="van-dialog" style="display: none;" name="van-dialog-bounce">
<div class="van-dialog__header">标题</div>
<div class="van-dialog__content"><img src="https://img.yzcdn.cn/vant/apple-3.jpg"></div>

View File

@@ -1,6 +1,6 @@
import Vue from 'vue';
import Dialog from '..';
import DialogVue from '../Dialog';
import DialogComponent from '../Dialog';
import { mount, later, trigger } from '../../../test/utils';
test('Dialog function call', async () => {
@@ -33,7 +33,7 @@ test('Dialog function call', async () => {
});
test('before close', () => {
const wrapper = mount(DialogVue, {
const wrapper = mount(DialogComponent, {
propsData: {
value: true,
showCancelButton: true,
@@ -72,11 +72,11 @@ test('set default options', () => {
test('register component', () => {
Vue.use(Dialog);
expect(Vue.component(DialogVue.name)).toBeTruthy();
expect(Vue.component(DialogComponent.name)).toBeTruthy();
});
test('button color', () => {
const wrapper = mount(DialogVue, {
const wrapper = mount(DialogComponent, {
propsData: {
value: true,
showCancelButton: true,
@@ -88,7 +88,7 @@ test('button color', () => {
});
test('button text', () => {
const wrapper = mount(DialogVue, {
const wrapper = mount(DialogComponent, {
propsData: {
value: true,
showCancelButton: true,
@@ -100,11 +100,11 @@ test('button text', () => {
});
test('dialog component', () => {
expect(Dialog.Component).toEqual(DialogVue);
expect(Dialog.Component).toEqual(DialogComponent);
});
test('default slot', () => {
const wrapper = mount(DialogVue, {
const wrapper = mount(DialogComponent, {
propsData: {
value: true
},
@@ -116,7 +116,7 @@ test('default slot', () => {
});
test('title slot', () => {
const wrapper = mount(DialogVue, {
const wrapper = mount(DialogComponent, {
propsData: {
value: true
},
@@ -126,3 +126,11 @@ test('title slot', () => {
});
expect(wrapper).toMatchSnapshot();
});
test('open & close event', () => {
const wrapper = mount(DialogComponent);
wrapper.vm.value = true;
expect(wrapper.emitted('open')).toBeTruthy();
wrapper.vm.value = false;
expect(wrapper.emitted('close')).toBeTruthy();
});