fix(Toast): may lose forbid click when has multiple toasts (#5398)

This commit is contained in:
neverland
2019-12-27 10:57:47 +08:00
committed by GitHub
parent e9a9388202
commit cf43e6ee75
3 changed files with 46 additions and 7 deletions
+27 -5
View File
@@ -2,6 +2,7 @@ import Vue from 'vue';
import Toast from '..';
import ToastVue from '../Toast';
import { later } from '../../../test';
import { lockClick } from '../lock-click';
test('create a forbidClick toast', async () => {
const toast = Toast({
@@ -13,11 +14,15 @@ test('create a forbidClick toast', async () => {
expect(toast.$el.outerHTML).toMatchSnapshot();
await later();
expect(document.body.classList.contains('van-toast--unclickable')).toBeTruthy();
expect(
document.body.classList.contains('van-toast--unclickable')
).toBeTruthy();
toast.forbidClick = false;
await later();
expect(document.body.classList.contains('van-toast--unclickable')).toBeFalsy();
expect(
document.body.classList.contains('van-toast--unclickable')
).toBeFalsy();
});
it('toast disappeared after duration', async () => {
@@ -156,15 +161,17 @@ test('onClose callback', () => {
test('closeOnClick option', async () => {
Toast.allowMultiple();
const toast = Toast({
message: 'toast',
closeOnClick: true
message: 'toast'
});
await later();
toast.$el.click();
expect(toast.value).toBeTruthy();
await later();
toast.closeOnClick = true;
toast.$el.click();
expect(toast.value).toBeFalsy();
Toast.allowMultiple(false);
});
@@ -172,3 +179,18 @@ test('register component', () => {
Vue.use(Toast);
expect(Vue.component(ToastVue.name)).toBeTruthy();
});
test('lockClick function', () => {
const CLASSNAME = 'van-toast--unclickable';
expect(document.body.classList.contains(CLASSNAME)).toBeFalsy();
lockClick(true);
expect(document.body.classList.contains(CLASSNAME)).toBeTruthy();
lockClick(true);
lockClick(false);
expect(document.body.classList.contains(CLASSNAME)).toBeTruthy();
lockClick(false);
expect(document.body.classList.contains(CLASSNAME)).toBeFalsy();
});