[Improvement] Dialog: optimize style without content (#1233)

This commit is contained in:
neverland
2018-06-06 20:18:32 +08:00
committed by GitHub
parent 74aa001bb6
commit 14522d52bd
5 changed files with 75 additions and 14 deletions

View File

@@ -17,7 +17,7 @@ exports[`renders demo correctly 1`] = `
<!----><span class="van-button__text">高级用法</span></button>
<div class="van-dialog" style="display:none;">
<!---->
<div class="van-hairline van-dialog__content">
<div class="van-dialog__content">
<div placeholder="请输入用户名" class="van-cell van-hairline van-field">
<!---->
<div class="van-cell__title"><span>用户名</span>
@@ -45,7 +45,7 @@ exports[`renders demo correctly 1`] = `
<!---->
</div>
</div>
<div class="van-dialog__footer van-dialog__footer--buttons">
<div class="van-hairline--top van-dialog__footer van-dialog__footer--buttons">
<button class="van-button van-button--default van-button--large van-dialog__cancel">
<!----><span class="van-button__text">
取消

View File

@@ -0,0 +1,63 @@
import Vue from 'vue';
import Dialog from '..';
import DialogVue from '../dialog';
import { mount } from '@vue/test-utils';
import { later, transitionStub } from '../../../test/utils';
transitionStub();
test('Dialog function call', async() => {
Dialog.close();
Dialog.alert('1');
const callback = jest.fn();
const dialog = document.querySelector('.van-dialog');
await later();
expect(dialog.style.display).toEqual('');
Dialog.close();
await later();
expect(dialog.style.display).toEqual('none');
Dialog.confirm().catch(callback);
document.querySelector('.van-dialog__cancel').click();
await later();
expect(callback.mock.calls[0][0]).toEqual('cancel');
Dialog.confirm().then(callback);
document.querySelector('.van-dialog__confirm').click();
await later();
expect(callback.mock.calls[1][0]).toEqual('confirm');
});
test('before close', () => {
const wrapper = mount(DialogVue, {
propsData: {
beforeClose: (action, done) => done(false)
}
});
const cancel = wrapper.find('.van-dialog__cancel');
cancel.trigger('click');
expect(wrapper.emitted('cancel')).toBeFalsy();
wrapper.setProps({
beforeClose: (action, done) => done()
});
cancel.trigger('click');
expect(wrapper.emitted('cancel')).toBeTruthy();
});
test('set default options', () => {
Dialog.setDefaultOptions({ lockScroll: false });
expect(Dialog.currentOptions.lockScroll).toBeFalsy();
Dialog.resetDefaultOptions();
expect(Dialog.currentOptions.lockScroll).toBeTruthy();
});
test('register component', () => {
Vue.use(Dialog);
expect(Vue.component(DialogVue.name)).toBeTruthy();
});