vendor: amis 6.13.0 base (fork root)
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`EventAction:ajax 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
发送请求
|
||||
</span>
|
||||
</button>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
18岁的天空
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
发送请求2
|
||||
</span>
|
||||
</button>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
18岁的天空,status:0,msg:ok
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:ajax args 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
发送请求
|
||||
</span>
|
||||
</button>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
18岁的天空
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
发送请求2
|
||||
</span>
|
||||
</button>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
18岁的天空,status:0,msg:ok
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:ajax sendOn 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
发送请求
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,160 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`EventAction:custom 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作1
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作2
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作3
|
||||
</span>
|
||||
</button>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
18岁的天空
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:custom 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作1
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作2
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作3
|
||||
</span>
|
||||
</button>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
18岁的天空
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:custom 3`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作1
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作2
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
自定义动作3
|
||||
</span>
|
||||
</button>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
17岁的天空
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,597 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`1. EventAction:dialog args 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="amis-dialog-widget cxd-Modal cxd-Modal--1th"
|
||||
role="dialog"
|
||||
>
|
||||
<div
|
||||
class="cxd-Modal-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Modal-content in"
|
||||
>
|
||||
<div
|
||||
class="cxd-Modal-header"
|
||||
>
|
||||
<a
|
||||
class="cxd-Modal-close"
|
||||
data-position="left"
|
||||
data-tooltip="关闭"
|
||||
>
|
||||
<icon-mock
|
||||
classname="icon icon-close"
|
||||
icon="close"
|
||||
/>
|
||||
</a>
|
||||
<div
|
||||
class="cxd-Modal-title"
|
||||
>
|
||||
模态弹窗
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Modal-body"
|
||||
role="dialog-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开子弹窗
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default ml-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
关闭当前弹窗
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default ml-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
触发确认
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default ml-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
触发取消
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Modal-footer"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
取消
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
确认
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`1. EventAction:dialog args 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`1. EventAction:dialog args 3`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`1. EventAction:dialog args 4`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`1. EventAction:dialog args 5`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`1. EventAction:dialog args 6`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`1. EventAction:dialog args 7`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`2. EventAction:dialog 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="amis-dialog-widget cxd-Modal cxd-Modal--1th"
|
||||
role="dialog"
|
||||
>
|
||||
<div
|
||||
class="cxd-Modal-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Modal-content in"
|
||||
>
|
||||
<div
|
||||
class="cxd-Modal-header"
|
||||
>
|
||||
<a
|
||||
class="cxd-Modal-close"
|
||||
data-position="left"
|
||||
data-tooltip="关闭"
|
||||
>
|
||||
<icon-mock
|
||||
classname="icon icon-close"
|
||||
icon="close"
|
||||
/>
|
||||
</a>
|
||||
<div
|
||||
class="cxd-Modal-title"
|
||||
>
|
||||
模态弹窗
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Modal-body"
|
||||
role="dialog-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开子弹窗
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default ml-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
关闭当前弹窗
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default ml-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
触发确认
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default ml-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
触发取消
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Modal-footer"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
取消
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
确认
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`2. EventAction:dialog 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`2. EventAction:dialog 3`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`2. EventAction:dialog 4`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`2. EventAction:dialog 5`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`2. EventAction:dialog 6`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`2. EventAction:dialog 7`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,112 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`EventAction:disabled 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<div
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default is-disabled"
|
||||
disabled=""
|
||||
>
|
||||
<span>
|
||||
按钮1
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
按钮2
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default is-disabled"
|
||||
disabled=""
|
||||
>
|
||||
<span>
|
||||
按钮3
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
按钮4
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
按钮5
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
按钮6
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="cxd-Panel cxd-Panel--default cxd-Panel--form"
|
||||
data-role="container"
|
||||
>
|
||||
<div
|
||||
class="cxd-Panel-heading"
|
||||
>
|
||||
<h3
|
||||
class="cxd-Panel-title"
|
||||
>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
表单
|
||||
</span>
|
||||
</span>
|
||||
</h3>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Panel-body"
|
||||
>
|
||||
<form
|
||||
class="cxd-Form cxd-Form--normal"
|
||||
novalidate=""
|
||||
>
|
||||
<input
|
||||
style="display: none;"
|
||||
type="submit"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default is-disabled ml-2"
|
||||
disabled=""
|
||||
>
|
||||
<span>
|
||||
我的状态变了
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,561 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`EventAction:drawer 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="amis-dialog-widget cxd-Drawer cxd-Drawer--right cxd-Drawer--md cxd-Modal--1th"
|
||||
role="dialog"
|
||||
>
|
||||
<div
|
||||
class="cxd-Drawer-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Drawer-content in"
|
||||
>
|
||||
<a
|
||||
class="cxd-Drawer-close"
|
||||
>
|
||||
<icon-mock
|
||||
classname="icon icon-close"
|
||||
icon="close"
|
||||
/>
|
||||
</a>
|
||||
<div
|
||||
class="cxd-Drawer-header"
|
||||
>
|
||||
<div
|
||||
class="cxd-Drawer-title"
|
||||
>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
模态抽屉
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Drawer-body"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Spinner cxd-Spinner--overlay in"
|
||||
data-testid="spinner"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-icon cxd-Spinner-icon--lg cxd-Spinner-icon--default"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Drawer-footer"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
取消
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
确认
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer 3`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer 4`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer 5`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer 6`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer 7`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer args 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="amis-dialog-widget cxd-Drawer cxd-Drawer--right cxd-Drawer--md cxd-Modal--1th"
|
||||
role="dialog"
|
||||
>
|
||||
<div
|
||||
class="cxd-Drawer-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Drawer-content in"
|
||||
>
|
||||
<a
|
||||
class="cxd-Drawer-close"
|
||||
>
|
||||
<icon-mock
|
||||
classname="icon icon-close"
|
||||
icon="close"
|
||||
/>
|
||||
</a>
|
||||
<div
|
||||
class="cxd-Drawer-header"
|
||||
>
|
||||
<div
|
||||
class="cxd-Drawer-title"
|
||||
>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
模态抽屉
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Drawer-body"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Spinner cxd-Spinner--overlay in"
|
||||
data-testid="spinner"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-icon cxd-Spinner-icon--lg cxd-Spinner-icon--default"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Drawer-footer"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
取消
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
确认
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer args 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer args 3`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer args 4`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer args 5`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer args 6`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`EventAction:drawer args 7`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开抽屉
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,106 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`EventAction:prevent 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default ml-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
打开弹窗
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="amis-dialog-widget cxd-Modal cxd-Modal--1th"
|
||||
role="dialog"
|
||||
>
|
||||
<div
|
||||
class="cxd-Modal-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Modal-content in"
|
||||
>
|
||||
<div
|
||||
class="cxd-Modal-header"
|
||||
>
|
||||
<a
|
||||
class="cxd-Modal-close"
|
||||
data-position="left"
|
||||
data-tooltip="关闭"
|
||||
>
|
||||
<icon-mock
|
||||
classname="icon icon-close"
|
||||
icon="close"
|
||||
/>
|
||||
</a>
|
||||
<div
|
||||
class="cxd-Modal-title"
|
||||
>
|
||||
提示
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Modal-body"
|
||||
role="dialog-body"
|
||||
>
|
||||
<div
|
||||
class="cxd-Alert cxd-Alert--warning"
|
||||
>
|
||||
<div
|
||||
class="cxd-Alert-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Alert-desc"
|
||||
>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
确认后将不关闭弹窗
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Modal-footer"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--default cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
取消
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
确认
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
819
packages/amis/__tests__/event-action/ajax.test.tsx
Normal file
819
packages/amis/__tests__/event-action/ajax.test.tsx
Normal file
@@ -0,0 +1,819 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv, wait} from '../helper';
|
||||
|
||||
test('EventAction:ajax args', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
id: 'page_001',
|
||||
data: {
|
||||
name: 'lll'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
args: {
|
||||
api: {
|
||||
url: '/api/xxx',
|
||||
method: 'get'
|
||||
},
|
||||
messages: {
|
||||
success: '成功了!欧耶',
|
||||
failed: '失败了呢。。'
|
||||
}
|
||||
},
|
||||
outputVar: 'result'
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'page_001',
|
||||
args: {
|
||||
value: '${event.data.result.responseData}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '${age}岁的天空'
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求2',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
args: {
|
||||
api: {
|
||||
url: '/api/xxx',
|
||||
method: 'get'
|
||||
},
|
||||
messages: {
|
||||
success: '成功了!欧耶',
|
||||
failed: '失败了呢。。'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'page_001',
|
||||
args: {
|
||||
value: '${event.data}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '${responseResult.responseData.age}岁的天空,status:${responseResult.responseStatus},msg:${responseResult.responseMsg}'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('发送请求'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('18岁的天空')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText('发送请求2'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('18岁的天空,status:0,msg:ok')).toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('EventAction:ajax', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
id: 'page_001',
|
||||
data: {
|
||||
name: 'lll'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx',
|
||||
method: 'get'
|
||||
},
|
||||
messages: {
|
||||
success: '成功了!欧耶',
|
||||
failed: '失败了呢。。'
|
||||
},
|
||||
outputVar: 'result'
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'page_001',
|
||||
args: {
|
||||
value: '${event.data.result.responseData}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '${age}岁的天空'
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求2',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx',
|
||||
method: 'get'
|
||||
},
|
||||
messages: {
|
||||
success: '成功了!欧耶',
|
||||
failed: '失败了呢。。'
|
||||
}
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'page_001',
|
||||
args: {
|
||||
value: '${event.data}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '${responseResult.responseData.age}岁的天空,status:${responseResult.responseStatus},msg:${responseResult.responseMsg}'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('发送请求'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('18岁的天空')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText('发送请求2'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('18岁的天空,status:0,msg:ok')).toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('EventAction:ajax data1', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'amis',
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'lll'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
args: {
|
||||
api: {
|
||||
url: '/api/xxx?name=${event.data.name}',
|
||||
method: 'post',
|
||||
data: {
|
||||
myname1: '${name}',
|
||||
myname2: '\\${name}',
|
||||
myname3: '${text}',
|
||||
myname4: '\\${text}'
|
||||
}
|
||||
}
|
||||
},
|
||||
outputVar: 'result'
|
||||
},
|
||||
{
|
||||
actionType: 'ajax',
|
||||
args: {
|
||||
api: {
|
||||
url: '/api/xxx?q1=${result.responseData.age}',
|
||||
method: 'post',
|
||||
data: {
|
||||
param1: '${event.data.result.responseData.name}',
|
||||
param2: '${responseData.name}',
|
||||
param3: '${result.name}',
|
||||
param4: '${event.data.responseData.name}'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
actionType: 'ajax',
|
||||
args: {
|
||||
api: {
|
||||
url: '/api/xxx?name=${event.data.name}',
|
||||
method: 'post',
|
||||
data: {
|
||||
myname1: '${name}',
|
||||
myname2: '\\${name}',
|
||||
myname3: '${text}',
|
||||
myname4: '\\${text}'
|
||||
}
|
||||
},
|
||||
other: '${name}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
data: {
|
||||
text: '${lll}'
|
||||
}
|
||||
},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('发送请求')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/发送请求/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(3);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/xxx?name=lll');
|
||||
expect(fetcher.mock.calls[0][0].data).toMatchObject({
|
||||
myname1: 'lll',
|
||||
myname2: '${name}',
|
||||
myname3: '${lll}',
|
||||
myname4: '${text}'
|
||||
});
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/xxx?q1=18');
|
||||
expect(fetcher.mock.calls[1][0].data).toMatchObject({
|
||||
param1: 'amis',
|
||||
param2: 'amis',
|
||||
param3: 'amis',
|
||||
param4: 'amis'
|
||||
});
|
||||
// 测试干扰配置
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/xxx?name=lll');
|
||||
expect(fetcher.mock.calls[0][0].data).toMatchObject({
|
||||
myname1: 'lll',
|
||||
myname2: '${name}',
|
||||
myname3: '${lll}',
|
||||
myname4: '${text}'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('EventAction:ajax data2', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'amis',
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'lll'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx?name=${event.data.name}',
|
||||
method: 'post',
|
||||
data: {
|
||||
myname1: '${name}',
|
||||
myname2: '\\${name}',
|
||||
myname3: '${text}',
|
||||
myname4: '\\${text}'
|
||||
}
|
||||
},
|
||||
outputVar: 'result'
|
||||
},
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx?q1=${result.responseData.age}',
|
||||
method: 'post',
|
||||
data: {
|
||||
param1: '${event.data.result.responseData.name}',
|
||||
param2: '${responseData.name}',
|
||||
param3: '${result.name}',
|
||||
param4: '${event.data.responseData.name}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
data: {
|
||||
text: '${lll}'
|
||||
}
|
||||
},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('发送请求')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/发送请求/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/xxx?name=lll');
|
||||
expect(fetcher.mock.calls[0][0].data).toMatchObject({
|
||||
myname1: 'lll',
|
||||
myname2: '${name}',
|
||||
myname3: '${lll}',
|
||||
myname4: '${text}'
|
||||
});
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/xxx?q1=18');
|
||||
expect(fetcher.mock.calls[1][0].data).toMatchObject({
|
||||
param1: 'amis',
|
||||
param2: 'amis',
|
||||
param3: 'amis',
|
||||
param4: 'amis'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('EventAction:ajax data3', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'amis',
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '表单外的校验按钮',
|
||||
className: 'mb-2',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'form_validate',
|
||||
outputVar: 'validateResult',
|
||||
actionType: 'validate'
|
||||
},
|
||||
{
|
||||
outputVar: 'responseResult',
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
method: 'post',
|
||||
url: '/api/xxx1',
|
||||
data: {
|
||||
name: '${name}',
|
||||
email: '${email}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_validate',
|
||||
data: {
|
||||
name: 'amis',
|
||||
email: 'amis@baidu.com'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '姓名:',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
type: 'input-text',
|
||||
label: '邮箱:',
|
||||
required: true,
|
||||
validations: {
|
||||
isEmail: true
|
||||
}
|
||||
}
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '表单内的校验按钮',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'form_validate',
|
||||
outputVar: 'validateResult',
|
||||
actionType: 'validate'
|
||||
},
|
||||
{
|
||||
outputVar: 'responseResult',
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
method: 'post',
|
||||
url: '/api/xxx2',
|
||||
data: {
|
||||
name: '${name}',
|
||||
email: '${email}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '无data',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'form_validate',
|
||||
outputVar: 'validateResult',
|
||||
actionType: 'validate'
|
||||
},
|
||||
{
|
||||
outputVar: 'responseResult',
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
method: 'post',
|
||||
url: '/api/xxx3'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '字符串api无参数',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'form_validate',
|
||||
outputVar: 'validateResult',
|
||||
actionType: 'validate'
|
||||
},
|
||||
{
|
||||
outputVar: 'responseResult',
|
||||
actionType: 'ajax',
|
||||
api: 'post:/api/xxx4'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('表单外的校验按钮')).toBeInTheDocument();
|
||||
expect(getByText('表单内的校验按钮')).toBeInTheDocument();
|
||||
expect(getByText('无data')).toBeInTheDocument();
|
||||
expect(getByText('字符串api无参数')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/表单外的校验按钮/));
|
||||
await wait(200);
|
||||
fireEvent.click(getByText(/表单内的校验按钮/));
|
||||
await wait(200);
|
||||
fireEvent.click(getByText(/无data/));
|
||||
await wait(200);
|
||||
fireEvent.click(getByText(/字符串api无参数/));
|
||||
await wait(200);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(4);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/xxx1');
|
||||
expect(fetcher.mock.calls[0][0].data).toMatchObject({
|
||||
name: '',
|
||||
email: ''
|
||||
});
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/xxx2');
|
||||
expect(fetcher.mock.calls[1][0].data).toMatchObject({
|
||||
name: 'amis',
|
||||
email: 'amis@baidu.com'
|
||||
});
|
||||
expect(fetcher.mock.calls[2][0].url).toEqual('/api/xxx3');
|
||||
expect(fetcher.mock.calls[2][0].data).toMatchObject({});
|
||||
expect(fetcher.mock.calls[3][0].url).toEqual('/api/xxx4');
|
||||
expect(fetcher.mock.calls[3][0].data).toMatchObject({});
|
||||
});
|
||||
});
|
||||
|
||||
test('EventAction:ajax silent', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok'
|
||||
}
|
||||
});
|
||||
});
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求1',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx1',
|
||||
method: 'post',
|
||||
silent: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求2',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx2',
|
||||
method: 'post',
|
||||
silent: false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求3',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx3',
|
||||
method: 'post'
|
||||
},
|
||||
options: {
|
||||
silent: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求4',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx4',
|
||||
method: 'post'
|
||||
},
|
||||
options: {
|
||||
silent: false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
fetcher,
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('发送请求1')).toBeInTheDocument();
|
||||
expect(getByText('发送请求2')).toBeInTheDocument();
|
||||
expect(getByText('发送请求3')).toBeInTheDocument();
|
||||
expect(getByText('发送请求4')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/发送请求1/));
|
||||
fireEvent.click(getByText(/发送请求2/));
|
||||
fireEvent.click(getByText(/发送请求3/));
|
||||
fireEvent.click(getByText(/发送请求4/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(4);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/xxx1');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/xxx2');
|
||||
expect(fetcher.mock.calls[2][0].url).toEqual('/api/xxx3');
|
||||
expect(fetcher.mock.calls[3][0].url).toEqual('/api/xxx4');
|
||||
expect(notify).toBeCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
test('EventAction:ajax sendOn', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送请求',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: {
|
||||
url: '/api/xxx',
|
||||
method: 'get',
|
||||
sendOn: '${1 !== 1}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('发送请求'));
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
74
packages/amis/__tests__/event-action/copy.test.tsx
Normal file
74
packages/amis/__tests__/event-action/copy.test.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv} from '../helper';
|
||||
|
||||
test('EventAction:copy', async () => {
|
||||
const copy = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
content: 'http://www.baidu.com'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '复制',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'copy',
|
||||
args: {
|
||||
content: 'the content is ${content}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '复制富文本',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'copy',
|
||||
args: {
|
||||
format: 'text/html',
|
||||
content:
|
||||
'the content is <a href="http://www.baidu.com">link</a> <b>bold</b>'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
copy
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('复制'));
|
||||
await waitFor(() => {
|
||||
expect(copy).toHaveBeenCalled();
|
||||
});
|
||||
expect(copy.mock.calls[0][0]).toEqual('the content is http://www.baidu.com');
|
||||
|
||||
fireEvent.click(getByText('复制富文本'));
|
||||
await waitFor(() => {
|
||||
expect(copy).toHaveBeenCalled();
|
||||
});
|
||||
expect(copy.mock.calls[1][0]).toEqual(
|
||||
'the content is <a href="http://www.baidu.com">link</a> <b>bold</b>'
|
||||
);
|
||||
expect(copy.mock.calls[1][1]).toEqual({format: undefined});
|
||||
});
|
||||
125
packages/amis/__tests__/event-action/custom.test.tsx
Normal file
125
packages/amis/__tests__/event-action/custom.test.tsx
Normal file
@@ -0,0 +1,125 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv} from '../helper';
|
||||
|
||||
test('EventAction:custom', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
id: 'page_001',
|
||||
data: {
|
||||
age: '22'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '自定义动作1',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'custom',
|
||||
args: {
|
||||
script:
|
||||
"doAction({actionType: 'ajax', api: '/api/xxx', outputVar: 'result'});"
|
||||
}
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'page_001',
|
||||
args: {
|
||||
value: '${event.data.result.responseData}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '自定义动作2',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'custom',
|
||||
args: {
|
||||
script:
|
||||
"doAction({actionType: 'ajax', api: '/api/xxx', outputVar: 'result'});event.stopPropagation();"
|
||||
}
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'page_001',
|
||||
args: {
|
||||
value: '${event.data.result.responseData}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '自定义动作3',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'custom',
|
||||
args: {
|
||||
script:
|
||||
"doAction({actionType: 'setValue', componentId: 'page_001', args: {value: {age: 17}}});"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '${age}岁的天空'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('自定义动作1'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('18岁的天空')).toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('自定义动作2'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('18岁的天空')).toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('自定义动作3'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('17岁的天空')).toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
730
packages/amis/__tests__/event-action/dialog.test.tsx
Normal file
730
packages/amis/__tests__/event-action/dialog.test.tsx
Normal file
@@ -0,0 +1,730 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv, wait} from '../helper';
|
||||
|
||||
test('1. EventAction:dialog args', async () => {
|
||||
const notify = jest.fn();
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开弹窗',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
args: {
|
||||
dialog: {
|
||||
type: 'dialog',
|
||||
id: 'dialog_001',
|
||||
title: '模态弹窗',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开子弹窗',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
args: {
|
||||
dialog: {
|
||||
type: 'dialog',
|
||||
title: '模态子弹窗',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '关闭父弹窗',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'closeDialog',
|
||||
componentId: 'dialog_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '关闭当前弹窗',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'closeDialog'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '触发确认',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'confirm',
|
||||
componentId: 'dialog_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '触发取消',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'cancel',
|
||||
componentId: 'dialog_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
onEvent: {
|
||||
confirm: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: 'confirm'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
cancel: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: 'cancel'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container,
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
// events
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('确认'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('取消')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('取消'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// actions
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('关闭当前弹窗')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('关闭当前弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('打开子弹窗')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('打开子弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('关闭父弹窗')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('关闭父弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('触发确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('触发确认'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('触发取消')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('触发取消'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
}, 7000);
|
||||
|
||||
test('2. EventAction:dialog', async () => {
|
||||
const notify = jest.fn();
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开弹窗',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
type: 'dialog',
|
||||
id: 'dialog_001',
|
||||
title: '模态弹窗',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开子弹窗',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
type: 'dialog',
|
||||
title: '模态子弹窗',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '关闭父弹窗',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'closeDialog',
|
||||
componentId: 'dialog_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '关闭当前弹窗',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'closeDialog'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '触发确认',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'confirm',
|
||||
componentId: 'dialog_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '触发取消',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'cancel',
|
||||
componentId: 'dialog_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
onEvent: {
|
||||
confirm: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: 'confirm'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
cancel: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: 'cancel'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container,
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
// events
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('确认'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('取消')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('取消'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// actions
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('关闭当前弹窗')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('关闭当前弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('打开子弹窗')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('打开子弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('关闭父弹窗')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('关闭父弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('触发确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('触发确认'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('触发取消')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('触发取消'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
}, 7000);
|
||||
|
||||
test('3. EventAction:dialog data', async () => {
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'amis'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开弹窗',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
args: {
|
||||
dialog: {
|
||||
type: 'dialog',
|
||||
id: 'dialog_001',
|
||||
title: '模态弹窗${event.data.name}',
|
||||
body: [
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '你好,我是${name}、${name1}、${name2}'
|
||||
}
|
||||
],
|
||||
data: {
|
||||
name1: '${name}',
|
||||
name2: '${event.data.name}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container
|
||||
})
|
||||
)
|
||||
);
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
// events
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).toBeInTheDocument();
|
||||
expect(getByText('模态弹窗')).toBeInTheDocument();
|
||||
expect(getByText('你好,我是、amis、amis')).toBeInTheDocument(); // 因为事件动作给args提前做了映射
|
||||
});
|
||||
}, 7000);
|
||||
|
||||
test('4. EventAction:dialog data2', async () => {
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'amis'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开弹窗',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
type: 'dialog',
|
||||
id: 'dialog_001',
|
||||
title: '模态弹窗${event.data.name}',
|
||||
body: [
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '你好,我是${name}、${name1}、${name2}'
|
||||
}
|
||||
],
|
||||
data: {
|
||||
name1: '${name}',
|
||||
name2: '${event.data.name}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container
|
||||
})
|
||||
)
|
||||
);
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
// events
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).toBeInTheDocument();
|
||||
expect(getByText('模态弹窗')).toBeInTheDocument();
|
||||
expect(getByText('你好,我是、amis、amis')).toBeInTheDocument();
|
||||
});
|
||||
}, 7000);
|
||||
|
||||
// // test('EventAction:alert', async () => {
|
||||
// // const alert = jest.fn();
|
||||
// // const {getByText, container}: any = render(
|
||||
// // amisRender(
|
||||
// // {
|
||||
// // type: 'page',
|
||||
// // data: {
|
||||
// // msg: '去吃饭了'
|
||||
// // },
|
||||
// // body: [
|
||||
// // {
|
||||
// // type: 'button',
|
||||
// // label: '提示对话框',
|
||||
// // level: 'primary',
|
||||
// // onEvent: {
|
||||
// // click: {
|
||||
// // actions: [
|
||||
// // {
|
||||
// // actionType: 'alert',
|
||||
// // args: {
|
||||
// // msg: '<a href="http://www.baidu.com" target="_blank">${msg}~</a>'
|
||||
// // }
|
||||
// // }
|
||||
// // ]
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// // ]
|
||||
// // },
|
||||
// // {},
|
||||
// // makeEnv({
|
||||
// // getModalContainer: () => container,
|
||||
// // alert
|
||||
// // })
|
||||
// // )
|
||||
// // );
|
||||
|
||||
// // fireEvent.click(getByText('提示对话框'));
|
||||
// // await waitFor(() => {
|
||||
// // expect(alert).toHaveBeenCalled();
|
||||
// // });
|
||||
// // expect(alert.mock.calls[0][0]).toEqual(
|
||||
// // '<a href="http://www.baidu.com" target="_blank">去吃饭了~</a>'
|
||||
// // );
|
||||
// // });
|
||||
|
||||
// // test('EventAction:confirm', async () => {
|
||||
// // const confirm = jest.fn();
|
||||
// // const {getByText, container}: any = render(
|
||||
// // amisRender(
|
||||
// // {
|
||||
// // type: 'page',
|
||||
// // data: {
|
||||
// // title: '操作确认',
|
||||
// // msg: '要删除它吗?'
|
||||
// // },
|
||||
// // body: [
|
||||
// // {
|
||||
// // type: 'button',
|
||||
// // label: '确认对话框',
|
||||
// // level: 'primary',
|
||||
// // onEvent: {
|
||||
// // click: {
|
||||
// // actions: [
|
||||
// // {
|
||||
// // actionType: 'confirmDialog',
|
||||
// // args: {
|
||||
// // title: '${title}',
|
||||
// // msg: '<span style="color:red">${msg}</span>'
|
||||
// // }
|
||||
// // }
|
||||
// // ]
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// // ]
|
||||
// // },
|
||||
// // {},
|
||||
// // makeEnv({
|
||||
// // getModalContainer: () => container,
|
||||
// // confirm
|
||||
// // })
|
||||
// // )
|
||||
// // );
|
||||
|
||||
// // fireEvent.click(getByText('确认对话框'));
|
||||
// // await waitFor(() => {
|
||||
// // expect(confirm).toHaveBeenCalled();
|
||||
// // });
|
||||
// // expect(confirm.mock.calls[0][0]).toEqual(
|
||||
// // '<span style="color:red">要删除它吗?</span>'
|
||||
// // );
|
||||
// // expect(confirm.mock.calls[0][1]).toEqual('操作确认');
|
||||
// // });
|
||||
|
||||
test('5. EventAction:dialog formitem without form', async () => {
|
||||
const onAction = jest.fn();
|
||||
let portal: any = null;
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: 'Dialog',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '表单页面',
|
||||
body: [
|
||||
{
|
||||
label: 'A',
|
||||
type: 'input-text',
|
||||
name: 'a'
|
||||
},
|
||||
{
|
||||
label: 'B',
|
||||
type: 'input-text',
|
||||
name: 'b'
|
||||
}
|
||||
],
|
||||
onEvent: {
|
||||
confirm: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'custom',
|
||||
script: onAction
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => portal
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
portal = container;
|
||||
await wait(200);
|
||||
const button = getByText('Dialog');
|
||||
fireEvent.click(button);
|
||||
await wait(200);
|
||||
|
||||
fireEvent.change(container.querySelector('[name="a"]')!, {
|
||||
target: {value: '1'}
|
||||
});
|
||||
|
||||
await wait(200);
|
||||
fireEvent.change(container.querySelector('[name="b"]')!, {
|
||||
target: {value: '2'}
|
||||
});
|
||||
|
||||
await wait(200);
|
||||
fireEvent.click(getByText('确认'));
|
||||
await wait(300);
|
||||
expect(onAction).toHaveBeenCalled();
|
||||
expect(onAction.mock.calls[0][2].data).toMatchObject({a: '1', b: '2'});
|
||||
});
|
||||
147
packages/amis/__tests__/event-action/disabled.test.tsx
Normal file
147
packages/amis/__tests__/event-action/disabled.test.tsx
Normal file
@@ -0,0 +1,147 @@
|
||||
import {fireEvent, render} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv, wait} from '../helper';
|
||||
|
||||
test('EventAction:disabled', async () => {
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
btnDisabled: true,
|
||||
btnNotDisabled: false
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮1',
|
||||
disabledOn: '${btnDisabled}'
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮2',
|
||||
disabledOn: '${btnNotDisabled}',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'disabled',
|
||||
componentId: 'ui:button_test_3'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮3',
|
||||
disabledOn: '${btnNotDisabled}',
|
||||
id: 'ui:button_test_3'
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮4',
|
||||
disabledOn: '${btnNotDisabled}',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'enabled',
|
||||
componentId: 'ui:button_test_5'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮5',
|
||||
disabled: true,
|
||||
id: 'ui:button_test_5'
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮6',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'disabled',
|
||||
componentId: 'ui:form_disable'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'ui:form_disable',
|
||||
title: '表单',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
className: 'ml-2',
|
||||
label: '我的状态变了'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText(/按钮2/));
|
||||
fireEvent.click(getByText(/按钮4/));
|
||||
fireEvent.click(getByText(/按钮6/));
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('EventAction:disabledFormItem', async () => {
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'form',
|
||||
body: [
|
||||
{
|
||||
type: 'textarea',
|
||||
id: 'textarea',
|
||||
name: 'textarea',
|
||||
disabled: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '启用textarea',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'enabled',
|
||||
componentId: 'textarea'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({})
|
||||
)
|
||||
);
|
||||
|
||||
expect(container.querySelector('textarea[name="textarea"]')).toBeDisabled();
|
||||
fireEvent.click(getByText(/启用textarea/));
|
||||
await wait(200);
|
||||
expect(
|
||||
container.querySelector('textarea[name="textarea"]')
|
||||
).not.toBeDisabled();
|
||||
});
|
||||
560
packages/amis/__tests__/event-action/drawer.test.tsx
Normal file
560
packages/amis/__tests__/event-action/drawer.test.tsx
Normal file
@@ -0,0 +1,560 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv, wait} from '../helper';
|
||||
|
||||
test('EventAction:drawer args', async () => {
|
||||
const notify = jest.fn();
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开抽屉',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'drawer',
|
||||
args: {
|
||||
drawer: {
|
||||
type: 'drawer',
|
||||
id: 'drawer_001',
|
||||
title: '模态抽屉',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开子抽屉',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'drawer',
|
||||
args: {
|
||||
drawer: {
|
||||
type: 'drawer',
|
||||
title: '模态子抽屉',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '关闭父抽屉',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'closeDrawer',
|
||||
componentId: 'drawer_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '关闭当前抽屉',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'closeDrawer'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '触发确认',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'confirm',
|
||||
componentId: 'drawer_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '触发取消',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'cancel',
|
||||
componentId: 'drawer_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
onEvent: {
|
||||
confirm: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: 'confirm'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
cancel: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: 'cancel'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container,
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
// events
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('确认'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('取消')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('取消'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// actions
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('关闭当前抽屉')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('关闭当前抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('打开子抽屉')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('打开子抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('关闭父抽屉')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('关闭父抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('触发确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('触发确认'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('触发取消')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('触发取消'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
}, 7000);
|
||||
|
||||
test('EventAction:drawer', async () => {
|
||||
const notify = jest.fn();
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开抽屉',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'drawer',
|
||||
drawer: {
|
||||
type: 'drawer',
|
||||
id: 'drawer_001',
|
||||
title: '模态抽屉',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开子抽屉',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'drawer',
|
||||
drawer: {
|
||||
type: 'drawer',
|
||||
title: '模态子抽屉',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '关闭父抽屉',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'closeDrawer',
|
||||
componentId: 'drawer_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '关闭当前抽屉',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'closeDrawer'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '触发确认',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'confirm',
|
||||
componentId: 'drawer_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '触发取消',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'cancel',
|
||||
componentId: 'drawer_001'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
onEvent: {
|
||||
confirm: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: 'confirm'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
cancel: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: 'cancel'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container,
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
// events
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('确认'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('取消')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('取消'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// actions
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('关闭当前抽屉')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('关闭当前抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('打开子抽屉')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('打开子抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('关闭父抽屉')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('关闭父抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('触发确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('触发确认'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('触发取消')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('触发取消'));
|
||||
await wait(300);
|
||||
expect(notify).toHaveBeenCalled();
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).not.toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
}, 7000);
|
||||
|
||||
test('EventAction:drawer data', async () => {
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'amis'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开抽屉',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'drawer',
|
||||
args: {
|
||||
drawer: {
|
||||
type: 'drawer',
|
||||
id: 'drawer_001',
|
||||
title: '模态弹窗${event.data.name}',
|
||||
body: [
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '你好,我是${name}、${name1}、${name2}'
|
||||
}
|
||||
],
|
||||
data: {
|
||||
name1: '${name}',
|
||||
name2: '${event.data.name}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container
|
||||
})
|
||||
)
|
||||
);
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
// events
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).toBeInTheDocument();
|
||||
expect(getByText('模态弹窗')).toBeInTheDocument();
|
||||
expect(getByText('你好,我是、amis、amis')).toBeInTheDocument(); // 因为事件动作给args提前做了映射
|
||||
});
|
||||
}, 7000);
|
||||
|
||||
test('EventAction:drawer data2', async () => {
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'amis'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开抽屉',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'drawer',
|
||||
drawer: {
|
||||
type: 'drawer',
|
||||
id: 'drawer_001',
|
||||
title: '模态弹窗${event.data.name}',
|
||||
body: [
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '你好,我是${name}、${name1}、${name2}'
|
||||
}
|
||||
],
|
||||
data: {
|
||||
name1: '${name}',
|
||||
name2: '${event.data.name}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
// events
|
||||
fireEvent.click(getByText('打开抽屉'));
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[role="dialog"]')).toBeInTheDocument();
|
||||
expect(getByText('模态弹窗')).toBeInTheDocument();
|
||||
expect(getByText('你好,我是、amis、amis')).toBeInTheDocument();
|
||||
});
|
||||
}, 7000);
|
||||
46
packages/amis/__tests__/event-action/email.test.tsx
Normal file
46
packages/amis/__tests__/event-action/email.test.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv} from '../helper';
|
||||
|
||||
test('EventAction:email', async () => {
|
||||
window.open = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '发送邮件',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'email',
|
||||
args: {
|
||||
to: 'amis@baidu.com',
|
||||
cc: 'baidu@baidu.com',
|
||||
subject: '这是邮件主题',
|
||||
body: '这是邮件正文'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('发送邮件'));
|
||||
await waitFor(() => {
|
||||
expect(window.open).toHaveBeenCalledWith(
|
||||
'mailto:amis@baidu.com?cc=baidu%40baidu.com&subject=%E8%BF%99%E6%98%AF%E9%82%AE%E4%BB%B6%E4%B8%BB%E9%A2%98&body=%E8%BF%99%E6%98%AF%E9%82%AE%E4%BB%B6%E6%AD%A3%E6%96%87'
|
||||
);
|
||||
});
|
||||
});
|
||||
88
packages/amis/__tests__/event-action/hidden.test.tsx
Normal file
88
packages/amis/__tests__/event-action/hidden.test.tsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv, wait} from '../helper';
|
||||
|
||||
test('EventAction:hidden', async () => {
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
btnHidden: true,
|
||||
btnNotHidden: false
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮1',
|
||||
hiddenOn: '${btnHidden}'
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮2',
|
||||
className: 'btn_2',
|
||||
hiddenOn: '${btnNotHidden}',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'hidden',
|
||||
componentId: 'ui:button_test_3'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮3',
|
||||
className: 'btn_3',
|
||||
hiddenOn: '${btnNotHidden}',
|
||||
id: 'ui:button_test_3'
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮4',
|
||||
className: 'btn_4',
|
||||
hiddenOn: '${btnNotHidden}',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'show',
|
||||
componentId: 'ui:button_test_5'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '按钮5',
|
||||
className: 'btn_5',
|
||||
hidden: true,
|
||||
id: 'ui:button_test_5'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('.btn_2')).toBeInTheDocument();
|
||||
expect(container.querySelector('.btn_3')).toBeInTheDocument();
|
||||
expect(container.querySelector('.btn_4')).toBeInTheDocument();
|
||||
expect(container.querySelector('.btn_5')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/按钮2/));
|
||||
await wait(300);
|
||||
expect(container.querySelector('.btn_3')).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(getByText(/按钮4/));
|
||||
await wait(300);
|
||||
expect(container.querySelector('.btn_5')).toBeInTheDocument();
|
||||
});
|
||||
172
packages/amis/__tests__/event-action/prevent.test.tsx
Normal file
172
packages/amis/__tests__/event-action/prevent.test.tsx
Normal file
@@ -0,0 +1,172 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv} from '../helper';
|
||||
|
||||
test('EventAction:prevent', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
className: 'ml-2',
|
||||
label: '打开弹窗',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
type: 'dialog',
|
||||
title: '提示',
|
||||
id: 'dialog_001',
|
||||
data: {
|
||||
myage: '22'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'alert',
|
||||
body: '确认后将不关闭弹窗',
|
||||
level: 'warning'
|
||||
}
|
||||
],
|
||||
onEvent: {
|
||||
confirm: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msg: '不关闭'
|
||||
},
|
||||
preventDefault: true,
|
||||
stopPropagation: true
|
||||
},
|
||||
{
|
||||
actionType: 'ajax',
|
||||
args: {
|
||||
api: {
|
||||
url: '/api/xxx',
|
||||
method: 'get'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container,
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
fireEvent.click(getByText('打开弹窗'));
|
||||
await waitFor(() => {
|
||||
expect(getByText('确认')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText('确认'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalled();
|
||||
expect(container.querySelector('[role="dialog"]')).toBeInTheDocument();
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
expect(fetcher).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('EventAction:ignoreError', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
let container: HTMLElement;
|
||||
const renderResult: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '按钮',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'reload',
|
||||
componentId: 'notfound',
|
||||
ignoreError: true
|
||||
},
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: '/api/test3'
|
||||
},
|
||||
{
|
||||
actionType: 'custom',
|
||||
script:
|
||||
"const myMsg = '我是自定义JS';\nsdfsdfsdf();\ndoAction({\n actionType: 'toast',\n args: {\n msg: myMsg\n }\n});\n",
|
||||
ignoreError: true
|
||||
},
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: '/api/test4'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
getModalContainer: () => container,
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
const getByText = renderResult.getByText;
|
||||
container = renderResult.container;
|
||||
|
||||
fireEvent.click(getByText('按钮'));
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/test3');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/test4');
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,646 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`doAction:page reload 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default mb-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
刷新Page数据加载请求
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="title"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的标题:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="title"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="Test Page Component"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="age"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的年龄:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="age"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`doAction:page reload 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Spinner cxd-Spinner--overlay in"
|
||||
data-testid="spinner"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-icon cxd-Spinner-icon--lg cxd-Spinner-icon--default"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default mb-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
刷新Page数据加载请求
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="title"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的标题:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="title"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="Test Page Component"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="age"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的年龄:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="age"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`doAction:page reload with data 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default mb-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
刷新Page数据加载请求,同时把年龄更新为18
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="title"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的标题:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="title"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="Test Page Component"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="age"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的年龄:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="age"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`doAction:page reload with data 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-overlay in"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Spinner cxd-Spinner--overlay in"
|
||||
data-testid="spinner"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-icon cxd-Spinner-icon--lg cxd-Spinner-icon--default"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default mb-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
刷新Page数据加载请求,同时把年龄更新为18
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="title"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的标题:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="title"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="Test Page Component"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="age"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的年龄:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="age"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="18"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`doAction:page reload with data(same name) 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default mb-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
刷新Page数据加载请求,请求返回的date会覆盖动作传递的date
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="title"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的标题:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="title"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="Test Page Component"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="date"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
日期:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="date"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="2017-10-13"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`doAction:page reload with data(same name) 2`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-overlay"
|
||||
/>
|
||||
<div
|
||||
class="cxd-Spinner cxd-Spinner--overlay"
|
||||
data-testid="spinner"
|
||||
>
|
||||
<div
|
||||
class="cxd-Spinner-icon cxd-Spinner-icon--lg cxd-Spinner-icon--default"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default mb-2"
|
||||
type="button"
|
||||
>
|
||||
<span>
|
||||
刷新Page数据加载请求,请求返回的date会覆盖动作传递的date
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="title"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
我的标题:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="title"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="Test Page Component"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="date"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
日期:
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
name="date"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="2017-10-13"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,87 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv} from '../../helper';
|
||||
|
||||
test('EventAction:action', async () => {
|
||||
const notify = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
btnDisabled: true,
|
||||
btnNotDisabled: false
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: 'action',
|
||||
level: 'primary',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发点击事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mouseenter: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发鼠标移入事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mouseleave: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发鼠标移出事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('action'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发点击事件', {
|
||||
msg: '派发点击事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.mouseEnter(getByText('action'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发鼠标移入事件', {
|
||||
msg: '派发鼠标移入事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.mouseLeave(getByText('action'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发鼠标移出事件', {
|
||||
msg: '派发鼠标移出事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv} from '../../helper';
|
||||
|
||||
test('EventAction:avatar', async () => {
|
||||
const notify = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
btnDisabled: true,
|
||||
btnNotDisabled: false
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'avatar',
|
||||
text: 'AM',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发点击事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mouseenter: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发鼠标移入事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mouseleave: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发鼠标移出事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const avatar = container.querySelector('.cxd-Avatar');
|
||||
fireEvent.click(avatar);
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发点击事件', {
|
||||
msg: '派发点击事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.mouseEnter(avatar);
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发鼠标移入事件', {
|
||||
msg: '派发鼠标移入事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.mouseLeave(avatar);
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发鼠标移出事件', {
|
||||
msg: '派发鼠标移出事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv} from '../../helper';
|
||||
|
||||
test('EventAction:collapse', async () => {
|
||||
const notify = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {},
|
||||
body: [
|
||||
{
|
||||
type: 'collapse',
|
||||
header: '折叠器',
|
||||
body: [
|
||||
{
|
||||
type: 'tpl',
|
||||
tpl: '内容',
|
||||
wrapperComponent: '',
|
||||
inline: false
|
||||
}
|
||||
],
|
||||
onEvent: {
|
||||
expand: {
|
||||
weight: 0,
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发展开事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
collapse: {
|
||||
weight: 0,
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发收起事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('折叠器'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发收起事件', {
|
||||
msg: '派发收起事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.click(getByText('折叠器'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发展开事件', {
|
||||
msg: '派发展开事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv} from '../../helper';
|
||||
|
||||
test('EventAction:container', async () => {
|
||||
const notify = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'container',
|
||||
body: '这里是容器内容区',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发点击事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mouseenter: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发鼠标移入事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mouseleave: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发鼠标移出事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('这里是容器内容区'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发点击事件', {
|
||||
msg: '派发点击事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.mouseEnter(getByText('这里是容器内容区'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发鼠标移入事件', {
|
||||
msg: '派发鼠标移入事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.mouseLeave(getByText('这里是容器内容区'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发鼠标移出事件', {
|
||||
msg: '派发鼠标移出事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
});
|
||||
582
packages/amis/__tests__/event-action/renderers/crud.test.tsx
Normal file
582
packages/amis/__tests__/event-action/renderers/crud.test.tsx
Normal file
@@ -0,0 +1,582 @@
|
||||
import React = require('react');
|
||||
import * as renderer from 'react-test-renderer';
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv, replaceReactAriaIds, wait} from '../../helper';
|
||||
|
||||
test('doAction:crud reload', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
count: 171,
|
||||
rows: [
|
||||
{
|
||||
engine: 'Trident - pbz7l',
|
||||
browser: 'Internet Explorer 4.0',
|
||||
platform: 'Win 95+',
|
||||
version: '4',
|
||||
grade: 'X',
|
||||
badgeText: '默认',
|
||||
id: 1
|
||||
},
|
||||
{
|
||||
engine: 'Trident - tir4m8',
|
||||
browser: 'Internet Explorer 5.0',
|
||||
platform: 'Win 95+',
|
||||
version: '5',
|
||||
grade: 'C',
|
||||
badgeText: '危险',
|
||||
id: 2
|
||||
},
|
||||
{
|
||||
engine: 'Trident - wcn6f',
|
||||
browser: 'Internet Explorer 5.5',
|
||||
platform: 'Win 95+',
|
||||
version: '5.5',
|
||||
grade: 'A',
|
||||
id: 3
|
||||
},
|
||||
{
|
||||
engine: 'Trident - uwmcbf',
|
||||
browser: 'Internet Explorer 6',
|
||||
platform: 'Win 98+',
|
||||
version: '6',
|
||||
grade: 'A',
|
||||
id: 4
|
||||
},
|
||||
{
|
||||
engine: 'Trident - yjgst7',
|
||||
browser: 'Internet Explorer 7',
|
||||
platform: 'Win XP SP2+',
|
||||
version: '7',
|
||||
grade: 'A',
|
||||
id: 5
|
||||
},
|
||||
{
|
||||
engine: 'Trident - w9ee2k',
|
||||
browser: 'AOL browser (AOL desktop)',
|
||||
platform: 'Win XP',
|
||||
version: '6',
|
||||
grade: 'A',
|
||||
id: 6
|
||||
},
|
||||
{
|
||||
engine: 'Gecko - hi6cd',
|
||||
browser: 'Firefox 1.0',
|
||||
platform: 'Win 98+ / OSX.2+',
|
||||
version: '1.7',
|
||||
grade: 'A',
|
||||
id: 7
|
||||
},
|
||||
{
|
||||
engine: 'Gecko - 4kxz6',
|
||||
browser: 'Firefox 1.5',
|
||||
platform: 'Win 98+ / OSX.2+',
|
||||
version: '1.8',
|
||||
grade: 'A',
|
||||
id: 8
|
||||
},
|
||||
{
|
||||
engine: 'Gecko - x0u91o',
|
||||
browser: 'Firefox 2.0',
|
||||
platform: 'Win 98+ / OSX.2+',
|
||||
version: '1.8',
|
||||
grade: 'A',
|
||||
id: 9
|
||||
},
|
||||
{
|
||||
engine: 'Gecko - iou01',
|
||||
browser: 'Firefox 3.0',
|
||||
platform: 'Win 2k+ / OSX.3+',
|
||||
version: '1.9',
|
||||
grade: 'A',
|
||||
id: 10
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'amis',
|
||||
age: 18,
|
||||
date: '2023-6-6'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新CRUD数据加载请求',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'crud_reload',
|
||||
actionType: 'reload'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'crud',
|
||||
api: '/api/mock2/sample',
|
||||
id: 'crud_reload',
|
||||
syncLocation: false,
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
label: 'ID'
|
||||
},
|
||||
{
|
||||
name: 'engine',
|
||||
label: 'Rendering engine'
|
||||
},
|
||||
{
|
||||
name: 'browser',
|
||||
label: 'Browser'
|
||||
},
|
||||
{
|
||||
name: 'platform',
|
||||
label: 'Platform(s)'
|
||||
},
|
||||
{
|
||||
name: 'version',
|
||||
label: 'Engine version'
|
||||
},
|
||||
{
|
||||
name: 'grade',
|
||||
label: 'CSS grade'
|
||||
},
|
||||
{
|
||||
type: 'operation',
|
||||
label: '操作',
|
||||
buttons: [
|
||||
{
|
||||
label: '详情',
|
||||
type: 'button',
|
||||
level: 'link',
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '查看详情',
|
||||
body: {
|
||||
type: 'form',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'engine',
|
||||
label: 'Engine'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'browser',
|
||||
label: 'Browser'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'platform',
|
||||
label: 'platform'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'version',
|
||||
label: 'version'
|
||||
},
|
||||
{
|
||||
type: 'control',
|
||||
label: 'grade',
|
||||
body: {
|
||||
type: 'tag',
|
||||
label: '${grade}',
|
||||
displayMode: 'normal',
|
||||
color: 'active'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'button',
|
||||
level: 'link',
|
||||
className: 'text-danger',
|
||||
disabledOn: "this.grade === 'A'"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('刷新CRUD数据加载请求')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/刷新CRUD数据加载请求/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual(
|
||||
'/api/mock2/sample?page=1&perPage=10'
|
||||
);
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual(
|
||||
'/api/mock2/sample?page=1&perPage=10'
|
||||
);
|
||||
});
|
||||
|
||||
await wait(500);
|
||||
replaceReactAriaIds(container);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:crud reload with data1', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688714086
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'amis',
|
||||
age: 18,
|
||||
date: '2023-6-6'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新CRUD数据加载请求,同时追加参数date',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'crud_reload',
|
||||
actionType: 'reload',
|
||||
data: {
|
||||
date: '${date}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'crud',
|
||||
api: '/api/mock2/sample',
|
||||
id: 'crud_reload',
|
||||
syncLocation: false,
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
label: 'ID'
|
||||
},
|
||||
{
|
||||
name: 'engine',
|
||||
label: 'Rendering engine'
|
||||
},
|
||||
{
|
||||
name: 'browser',
|
||||
label: 'Browser'
|
||||
},
|
||||
{
|
||||
name: 'platform',
|
||||
label: 'Platform(s)'
|
||||
},
|
||||
{
|
||||
name: 'version',
|
||||
label: 'Engine version'
|
||||
},
|
||||
{
|
||||
name: 'grade',
|
||||
label: 'CSS grade'
|
||||
},
|
||||
{
|
||||
type: 'operation',
|
||||
label: '操作',
|
||||
buttons: [
|
||||
{
|
||||
label: '详情',
|
||||
type: 'button',
|
||||
level: 'link',
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '查看详情',
|
||||
body: {
|
||||
type: 'form',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'engine',
|
||||
label: 'Engine'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'browser',
|
||||
label: 'Browser'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'platform',
|
||||
label: 'platform'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'version',
|
||||
label: 'version'
|
||||
},
|
||||
{
|
||||
type: 'control',
|
||||
label: 'grade',
|
||||
body: {
|
||||
type: 'tag',
|
||||
label: '${grade}',
|
||||
displayMode: 'normal',
|
||||
color: 'active'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'button',
|
||||
level: 'link',
|
||||
className: 'text-danger',
|
||||
disabledOn: "this.grade === 'A'"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByText('刷新CRUD数据加载请求,同时追加参数date')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/刷新CRUD数据加载请求,同时追加参数date/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual(
|
||||
'/api/mock2/sample?page=1&perPage=10'
|
||||
);
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual(
|
||||
'/api/mock2/sample?page=1&date=2023-6-6&perPage=10'
|
||||
);
|
||||
});
|
||||
|
||||
replaceReactAriaIds(container);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:crud reload with data2', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688714086
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
name: 'amis',
|
||||
age: 18,
|
||||
date: '2023-6-6'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新CRUD数据加载请求,同时追加按钮所在数据域的所有数据',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'crud_reload',
|
||||
actionType: 'reload',
|
||||
data: {
|
||||
'&': '$$',
|
||||
'author': 'fex'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'crud',
|
||||
api: '/api/mock2/sample',
|
||||
id: 'crud_reload',
|
||||
syncLocation: false,
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
label: 'ID'
|
||||
},
|
||||
{
|
||||
name: 'engine',
|
||||
label: 'Rendering engine'
|
||||
},
|
||||
{
|
||||
name: 'browser',
|
||||
label: 'Browser'
|
||||
},
|
||||
{
|
||||
name: 'platform',
|
||||
label: 'Platform(s)'
|
||||
},
|
||||
{
|
||||
name: 'version',
|
||||
label: 'Engine version'
|
||||
},
|
||||
{
|
||||
name: 'grade',
|
||||
label: 'CSS grade'
|
||||
},
|
||||
{
|
||||
type: 'operation',
|
||||
label: '操作',
|
||||
buttons: [
|
||||
{
|
||||
label: '详情',
|
||||
type: 'button',
|
||||
level: 'link',
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '查看详情',
|
||||
body: {
|
||||
type: 'form',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'engine',
|
||||
label: 'Engine'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'browser',
|
||||
label: 'Browser'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'platform',
|
||||
label: 'platform'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'version',
|
||||
label: 'version'
|
||||
},
|
||||
{
|
||||
type: 'control',
|
||||
label: 'grade',
|
||||
body: {
|
||||
type: 'tag',
|
||||
label: '${grade}',
|
||||
displayMode: 'normal',
|
||||
color: 'active'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'button',
|
||||
level: 'link',
|
||||
className: 'text-danger',
|
||||
disabledOn: "this.grade === 'A'"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByText('刷新CRUD数据加载请求,同时追加按钮所在数据域的所有数据')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(
|
||||
getByText(/刷新CRUD数据加载请求,同时追加按钮所在数据域的所有数据/)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual(
|
||||
'/api/mock2/sample?page=1&perPage=10'
|
||||
);
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual(
|
||||
'/api/mock2/sample?page=1&name=amis&age=18&date=2023-6-6&author=fex&perPage=10'
|
||||
);
|
||||
});
|
||||
|
||||
replaceReactAriaIds(container);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,428 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`EventAction:inputRange 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="cxd-Page"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-content"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-main"
|
||||
>
|
||||
<div
|
||||
class="cxd-Page-body"
|
||||
role="page-body"
|
||||
>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal"
|
||||
data-amis-name="range"
|
||||
data-role="form-item"
|
||||
>
|
||||
<div
|
||||
class="cxd-RangeControl cxd-InputRange cxd-Form-control"
|
||||
>
|
||||
<div
|
||||
class="cxd-InputRange-wrap"
|
||||
>
|
||||
<div
|
||||
class="cxd-InputRange-track cxd-InputRange-track--background"
|
||||
>
|
||||
<div
|
||||
class="cxd-InputRange-track-active"
|
||||
style="width: 0%; left: 0%;"
|
||||
/>
|
||||
<div
|
||||
class="cxd-InputRange-handle"
|
||||
style="left: 0%; z-index: 1;"
|
||||
>
|
||||
<div
|
||||
class="cxd-InputRange-handle-icon"
|
||||
>
|
||||
<icon-mock
|
||||
classname="icon icon-slider-handle"
|
||||
icon="slider-handle"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-InputRange-label pos-top"
|
||||
>
|
||||
<span>
|
||||
0
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-InputRange-input"
|
||||
>
|
||||
<div
|
||||
class="cxd-Number cxd-Number--borderFull"
|
||||
>
|
||||
<div
|
||||
class="cxd-Number-handler-wrap"
|
||||
>
|
||||
<span
|
||||
aria-disabled="false"
|
||||
aria-label="Increase Value"
|
||||
class="cxd-Number-handler cxd-Number-handler-up"
|
||||
role="button"
|
||||
unselectable="on"
|
||||
>
|
||||
<span
|
||||
class="cxd-Number-handler-up-inner"
|
||||
unselectable="on"
|
||||
/>
|
||||
</span>
|
||||
<span
|
||||
aria-disabled="true"
|
||||
aria-label="Decrease Value"
|
||||
class="cxd-Number-handler cxd-Number-handler-down cxd-Number-handler-down-disabled"
|
||||
role="button"
|
||||
unselectable="on"
|
||||
>
|
||||
<span
|
||||
class="cxd-Number-handler-down-inner"
|
||||
unselectable="on"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Number-input-wrap"
|
||||
>
|
||||
<input
|
||||
aria-valuemax="100"
|
||||
aria-valuemin="0"
|
||||
aria-valuenow="0"
|
||||
autocomplete="off"
|
||||
class="cxd-Number-input"
|
||||
role="spinbutton"
|
||||
step="1"
|
||||
value="0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a
|
||||
class="cxd-InputRange-clear"
|
||||
>
|
||||
<icon-mock
|
||||
classname="icon icon-close"
|
||||
icon="close"
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Panel cxd-Panel--default cxd-Panel--form"
|
||||
data-role="container"
|
||||
>
|
||||
<div
|
||||
class="cxd-Panel-heading"
|
||||
>
|
||||
<h3
|
||||
class="cxd-Panel-title"
|
||||
>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
表单
|
||||
</span>
|
||||
</span>
|
||||
</h3>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Panel-body"
|
||||
>
|
||||
<form
|
||||
class="cxd-Form cxd-Form--normal"
|
||||
novalidate=""
|
||||
>
|
||||
<input
|
||||
style="display: none;"
|
||||
type="submit"
|
||||
/>
|
||||
<div
|
||||
class="cxd-JsonField cxd-Form--debug"
|
||||
>
|
||||
<div
|
||||
class="react-json-view"
|
||||
style="font-family: monospace; cursor: default; background-color: rgba(0, 0, 0, 0); position: relative;"
|
||||
>
|
||||
<div
|
||||
class="pretty-json-container object-container"
|
||||
>
|
||||
<div
|
||||
class="object-content"
|
||||
>
|
||||
<div
|
||||
class="object-key-val"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
style="display: inline-block; cursor: pointer;"
|
||||
>
|
||||
<div
|
||||
class="icon-container"
|
||||
style="display: inline-block; width: 17px;"
|
||||
>
|
||||
<span
|
||||
class="expanded-icon"
|
||||
>
|
||||
<svg
|
||||
fill="#586e75"
|
||||
height="1em"
|
||||
style="vertical-align: middle; color: rgb(88, 110, 117); height: 1em; width: 1em;"
|
||||
viewBox="0 0 1792 1792"
|
||||
width="1em"
|
||||
>
|
||||
<path
|
||||
d="M1344 800v64q0 14-9 23t-23 9h-832q-14 0-23-9t-9-23v-64q0-14 9-23t23-9h832q14 0 23 9t9 23zm128 448v-832q0-66-47-113t-113-47h-832q-66 0-113 47t-47 113v832q0 66 47 113t113 47h832q66 0 113-47t47-113zm128-832v832q0 119-84.5 203.5t-203.5 84.5h-832q-119 0-203.5-84.5t-84.5-203.5v-832q0-119 84.5-203.5t203.5-84.5h832q119 0 203.5 84.5t84.5 203.5z"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<span />
|
||||
<span
|
||||
style="display: inline-block; cursor: pointer; font-weight: bold; color: rgb(0, 43, 54);"
|
||||
>
|
||||
{
|
||||
</span>
|
||||
</span>
|
||||
<div
|
||||
class="object-meta-data"
|
||||
style="display: inline-block; padding: 0px 0px 0px 10px;"
|
||||
>
|
||||
<span
|
||||
class="object-size"
|
||||
style="color: rgba(0, 0, 0, 0.3); border-radius: 3px; font-style: italic; margin: 0px 6px 0px 0px; cursor: default;"
|
||||
>
|
||||
2
|
||||
item
|
||||
s
|
||||
</span>
|
||||
</div>
|
||||
</span>
|
||||
<div
|
||||
class="pushed-content object-container"
|
||||
>
|
||||
<div
|
||||
class="object-content"
|
||||
style="margin-left: 6px;"
|
||||
>
|
||||
<div
|
||||
class="variable-row"
|
||||
style="border-left: 1px solid rgb(235, 235, 235); padding: 3px 5px 3px 20px;"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="object-key"
|
||||
style="display: inline-block; color: rgb(0, 43, 54); letter-spacing: 0.5px; font-style: none; vertical-align: top; opacity: 0.85;"
|
||||
>
|
||||
<span
|
||||
style="vertical-align: top;"
|
||||
>
|
||||
"
|
||||
</span>
|
||||
<span
|
||||
style="display: inline-block;"
|
||||
>
|
||||
rangeValue
|
||||
</span>
|
||||
<span
|
||||
style="vertical-align: top;"
|
||||
>
|
||||
"
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
style="display: inline-block; margin: 0px 5px; color: rgb(0, 43, 54); vertical-align: top;"
|
||||
>
|
||||
:
|
||||
</span>
|
||||
</span>
|
||||
<div
|
||||
class="variable-value"
|
||||
style="display: inline-block; padding-right: 6px; position: relative; cursor: default;"
|
||||
>
|
||||
<div
|
||||
style="display: inline-block; color: rgb(203, 75, 22);"
|
||||
>
|
||||
<span
|
||||
class="string-value"
|
||||
style="cursor: default;"
|
||||
>
|
||||
"
|
||||
值为0
|
||||
"
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="variable-row"
|
||||
style="border-left: 1px solid rgb(235, 235, 235); padding: 3px 5px 3px 20px;"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="object-key"
|
||||
style="display: inline-block; color: rgb(0, 43, 54); letter-spacing: 0.5px; font-style: none; vertical-align: top; opacity: 0.85;"
|
||||
>
|
||||
<span
|
||||
style="vertical-align: top;"
|
||||
>
|
||||
"
|
||||
</span>
|
||||
<span
|
||||
style="display: inline-block;"
|
||||
>
|
||||
rangeEvent
|
||||
</span>
|
||||
<span
|
||||
style="vertical-align: top;"
|
||||
>
|
||||
"
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
style="display: inline-block; margin: 0px 5px; color: rgb(0, 43, 54); vertical-align: top;"
|
||||
>
|
||||
:
|
||||
</span>
|
||||
</span>
|
||||
<div
|
||||
class="variable-value"
|
||||
style="display: inline-block; padding-right: 6px; position: relative; cursor: default;"
|
||||
>
|
||||
<div
|
||||
style="display: inline-block; color: rgb(203, 75, 22);"
|
||||
>
|
||||
<span
|
||||
class="string-value"
|
||||
style="cursor: default;"
|
||||
>
|
||||
"
|
||||
触发了blur
|
||||
"
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
class="brace-row"
|
||||
>
|
||||
<span
|
||||
style="display: inline-block; cursor: pointer; font-weight: bold; color: rgb(0, 43, 54); padding-left: 3px;"
|
||||
>
|
||||
}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal input-text-range-value"
|
||||
data-amis-name="rangeValue"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
滑块值
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl is-disabled"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
disabled=""
|
||||
name="rangeValue"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="值为0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Form-item cxd-Form-item--normal input-text-range-event"
|
||||
data-amis-name="rangeEvent"
|
||||
data-role="form-item"
|
||||
>
|
||||
<label
|
||||
class="cxd-Form-label"
|
||||
>
|
||||
<span>
|
||||
<span
|
||||
class="cxd-TplField fr-view"
|
||||
>
|
||||
<span>
|
||||
滑块事件
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
<div
|
||||
class="cxd-Form-control cxd-TextControl is-disabled"
|
||||
>
|
||||
<div
|
||||
class="cxd-TextControl-input"
|
||||
>
|
||||
<input
|
||||
autocomplete="off"
|
||||
class=""
|
||||
disabled=""
|
||||
name="rangeEvent"
|
||||
placeholder=""
|
||||
size="10"
|
||||
type="text"
|
||||
value="触发了blur"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div
|
||||
class="cxd-Panel-footerWrap"
|
||||
>
|
||||
<div
|
||||
class="cxd-Panel-btnToolbar cxd-Panel-footer"
|
||||
>
|
||||
<button
|
||||
class="cxd-Button cxd-Button--primary cxd-Button--size-default"
|
||||
type="submit"
|
||||
>
|
||||
<span>
|
||||
提交
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,225 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../../src';
|
||||
import {render as amisRender} from '../../../../src';
|
||||
import {makeEnv, wait} from '../../../helper';
|
||||
|
||||
test('EventAction:combo', async () => {
|
||||
// const notify = jest.fn();
|
||||
// const {getByText, container}: any = render(
|
||||
// amisRender(
|
||||
// {
|
||||
// type: 'page',
|
||||
// title: 'combo',
|
||||
// body: [
|
||||
// {
|
||||
// type: 'form',
|
||||
// id: 'u:71e9bb1ed157',
|
||||
// title: '表单',
|
||||
// data: {
|
||||
// combo: [
|
||||
// {
|
||||
// name: 'Tom',
|
||||
// age: 18
|
||||
// },
|
||||
// {
|
||||
// name: 'Jerry',
|
||||
// age: 22
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
// body: [
|
||||
// {
|
||||
// type: 'button',
|
||||
// label: '更新数据',
|
||||
// onEvent: {
|
||||
// click: {
|
||||
// actions: [
|
||||
// {
|
||||
// actionType: 'setValue',
|
||||
// componentId: 'u:54031932ab8c',
|
||||
// args: {
|
||||
// value: [
|
||||
// {
|
||||
// name: 'Jack',
|
||||
// age: 22
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// type: 'button',
|
||||
// label: 'clear',
|
||||
// onEvent: {
|
||||
// click: {
|
||||
// actions: [
|
||||
// {
|
||||
// actionType: 'clear',
|
||||
// componentId: 'u:54031932ab8c'
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// type: 'button',
|
||||
// label: 'reset',
|
||||
// onEvent: {
|
||||
// click: {
|
||||
// actions: [
|
||||
// {
|
||||
// actionType: 'reset',
|
||||
// componentId: 'u:54031932ab8c'
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// type: 'combo',
|
||||
// label: '组合输入',
|
||||
// name: 'combo',
|
||||
// id: 'u:54031932ab8c',
|
||||
// multiple: true,
|
||||
// tabsMode: true,
|
||||
// resetValue: [
|
||||
// {
|
||||
// name: 'Tom',
|
||||
// age: 18
|
||||
// }
|
||||
// ],
|
||||
// items: [
|
||||
// {
|
||||
// type: 'input-text',
|
||||
// name: 'name'
|
||||
// },
|
||||
// {
|
||||
// type: 'input-text',
|
||||
// name: 'age'
|
||||
// },
|
||||
// {
|
||||
// type: 'button',
|
||||
// label: '自增第${index}项的年龄',
|
||||
// onEvent: {
|
||||
// click: {
|
||||
// actions: [
|
||||
// {
|
||||
// actionType: 'setValue',
|
||||
// componentId: 'u:54031932ab8c',
|
||||
// args: {
|
||||
// value: {
|
||||
// age: '${age+1}'
|
||||
// },
|
||||
// index: '${index}'
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// onEvent: {
|
||||
// add: {
|
||||
// actions: [
|
||||
// {
|
||||
// actionType: 'toast',
|
||||
// args: {
|
||||
// msgType: 'info',
|
||||
// msg: '派发新增事件'
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
// delete: {
|
||||
// actions: [
|
||||
// {
|
||||
// actionType: 'toast',
|
||||
// args: {
|
||||
// msgType: 'info',
|
||||
// msg: '派发删除事件'
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
// tabsChange: {
|
||||
// actions: [
|
||||
// {
|
||||
// actionType: 'toast',
|
||||
// args: {
|
||||
// msgType: 'info',
|
||||
// msg: '派发选项卡切换事件'
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
// {},
|
||||
// makeEnv({
|
||||
// notify
|
||||
// })
|
||||
// )
|
||||
// );
|
||||
// await waitFor(() => {
|
||||
// expect(getByText('新增')).toBeInTheDocument();
|
||||
// });
|
||||
// fireEvent.click(getByText('新增'));
|
||||
// await waitFor(() => {
|
||||
// expect(notify).toHaveBeenCalledWith('info', '派发新增事件', {
|
||||
// msg: '派发新增事件',
|
||||
// msgType: 'info'
|
||||
// });
|
||||
// });
|
||||
// fireEvent.click(
|
||||
// container.querySelectorAll(
|
||||
// 'div[data-tooltip="删除"]'
|
||||
// )[1] as HTMLInputElement
|
||||
// );
|
||||
// await waitFor(() => {
|
||||
// expect(notify).toHaveBeenCalledWith('info', '派发删除事件', {
|
||||
// msg: '派发删除事件',
|
||||
// msgType: 'info'
|
||||
// });
|
||||
// expect(notify).toHaveBeenCalledWith('info', '派发选项卡切换事件', {
|
||||
// msg: '派发选项卡切换事件',
|
||||
// msgType: 'info'
|
||||
// });
|
||||
// });
|
||||
// await waitFor(() => {
|
||||
// expect(getByText('自增第0项的年龄')).toBeInTheDocument();
|
||||
// });
|
||||
// fireEvent.click(getByText('自增第0项的年龄'));
|
||||
// await waitFor(() => {
|
||||
// expect(
|
||||
// container.querySelector('input[name=age]')?.getAttribute('value')
|
||||
// ).toBe('19');
|
||||
// });
|
||||
// await waitFor(() => {
|
||||
// expect(getByText('更新数据')).toBeInTheDocument();
|
||||
// });
|
||||
// fireEvent.click(getByText('更新数据'));
|
||||
// await waitFor(() => {
|
||||
// expect(
|
||||
// container.querySelector('input[name=name]')?.getAttribute('value')
|
||||
// ).toBe('Jack');
|
||||
// });
|
||||
// fireEvent.click(getByText('reset'));
|
||||
// await waitFor(() => {
|
||||
// expect(
|
||||
// container.querySelector('input[name=name]')?.getAttribute('value')
|
||||
// ).toBe('Tom');
|
||||
// });
|
||||
// fireEvent.click(getByText('clear'));
|
||||
// await waitFor(() => {
|
||||
// expect(
|
||||
// container.querySelector('div[class="cxd-Tabs-content"]')
|
||||
// ).toBeEmptyDOMElement();
|
||||
// });
|
||||
});
|
||||
@@ -0,0 +1,960 @@
|
||||
import React = require('react');
|
||||
import * as renderer from 'react-test-renderer';
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../../src';
|
||||
import {render as amisRender} from '../../../../src';
|
||||
import {makeEnv, wait} from '../../../helper';
|
||||
|
||||
test('doAction:form validate', async () => {
|
||||
const notify = jest.fn();
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '校验表单',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'validate',
|
||||
componentId: 'form_validate',
|
||||
outputVar: 'form_validate_result'
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'validate_info',
|
||||
args: {
|
||||
value: '${event.data.form_validate_result|json}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'validate_info',
|
||||
id: 'validate_info',
|
||||
label: '验证信息:'
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_validate',
|
||||
api: '/api/mock2/form/saveForm',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '姓名:',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
type: 'input-text',
|
||||
label: '邮箱:',
|
||||
required: true,
|
||||
validations: {
|
||||
isEmail: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('校验表单')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/校验表单/));
|
||||
|
||||
await wait(300);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual(
|
||||
`{ "error": "依赖的部分字段没有通过验证", "errors": { "name": [ "这是必填项" ], "email": [ "这是必填项" ] }, "payload": {}}`
|
||||
);
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.change(container.querySelector('[name="name"]')!, {
|
||||
target: {value: 'amis'}
|
||||
});
|
||||
|
||||
fireEvent.change(container.querySelector('[name="email"]')!, {
|
||||
target: {value: 'amis@baidu.com'}
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[value="amis"]')).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[value="amis@baidu.com"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.change(container.querySelector('[name="validate_info"]')!, {
|
||||
target: {value: ''}
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual('');
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/校验表单/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('.is-error .is-required .has-error--isRequired')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
await wait(300);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual(
|
||||
`{ "error": "", "payload": { "name": "amis", "email": "amis@baidu.com" }}`
|
||||
);
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:form submit', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
id: 1
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '提交表单',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'submit',
|
||||
componentId: 'form_submit',
|
||||
outputVar: 'form_submit_result'
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'submit_info',
|
||||
args: {
|
||||
value: '${event.data.form_submit_result|json}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'submit_info',
|
||||
id: 'submit_info',
|
||||
label: '提交信息:'
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_submit',
|
||||
api: '/api/mock2/form/saveForm',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '姓名:',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
type: 'input-text',
|
||||
label: '邮箱:',
|
||||
required: true,
|
||||
validations: {
|
||||
isEmail: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('提交表单')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/提交表单/));
|
||||
|
||||
await wait(300);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="submit_info"]') as any)?.value
|
||||
).toEqual(
|
||||
`{ "error": "依赖的部分字段没有通过验证", "errors": { "name": [ "这是必填项" ], "email": [ "这是必填项" ] }, "payload": {}}`
|
||||
);
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.change(container.querySelector('[name="name"]')!, {
|
||||
target: {value: 'amis'}
|
||||
});
|
||||
|
||||
fireEvent.change(container.querySelector('[name="email"]')!, {
|
||||
target: {value: 'amis@baidu.com'}
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[value="amis"]')).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[value="amis@baidu.com"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.change(container.querySelector('[name="submit_info"]')!, {
|
||||
target: {value: ''}
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="submit_info"]') as any)?.value
|
||||
).toEqual('');
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText(/提交表单/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('.is-error .is-required .has-error--isRequired')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
await wait(300);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="submit_info"]') as any)?.value
|
||||
).toEqual(
|
||||
`{ "error": "", "payload": { "name": "amis", "email": "amis@baidu.com" }, "responseData": { "id": 1 }}`
|
||||
);
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:form force validate before submit', async () => {
|
||||
const notify = jest.fn();
|
||||
const {container, getByText, queryByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'form',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'value1',
|
||||
validations: {
|
||||
equalsField: 'value2'
|
||||
},
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
name: 'value2',
|
||||
type: 'input-text',
|
||||
validations: {
|
||||
equalsField: 'value1'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('提交')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/提交/));
|
||||
|
||||
await wait(300);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(queryByText('输入的数据与 value2 值不一致')).toBeInTheDocument();
|
||||
expect(queryByText('输入的数据与 value1 值不一致')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.change(container.querySelector('[name="value2"]')!, {
|
||||
target: {value: '1'}
|
||||
});
|
||||
|
||||
await wait(300);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(queryByText('输入的数据与 value1 值不一致')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/提交/));
|
||||
|
||||
await wait(300);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(queryByText('输入的数据与 value2 值不一致')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:form setValue', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
id: 1
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '修改表单数据',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'form_setvalue',
|
||||
args: {
|
||||
value: {
|
||||
name: 'amis',
|
||||
email: 'amis@baidu.com'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_setvalue',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '姓名:'
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
type: 'input-text',
|
||||
label: '邮箱:'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('修改表单数据')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/修改表单数据/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[value="amis"]')).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[value="amis@baidu.com"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:form reload default', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688714086
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新表单',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'reload',
|
||||
componentId: 'form_reload'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_reload',
|
||||
debug: true,
|
||||
initApi: '/api/mock2/form/initData',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '姓名:'
|
||||
},
|
||||
{
|
||||
name: 'author',
|
||||
type: 'input-text',
|
||||
label: '作者:'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await wait(500); // 等待 initApi 加载完
|
||||
expect(
|
||||
(container.querySelector('[name="author"]') as HTMLInputElement).value
|
||||
).toEqual('fex');
|
||||
|
||||
const author: HTMLInputElement = container.querySelector('[name="author"]')!;
|
||||
fireEvent.change(author, {
|
||||
target: {value: 'amis'}
|
||||
});
|
||||
|
||||
expect(
|
||||
(container.querySelector('[name="author"]') as HTMLInputElement).value
|
||||
).toEqual('amis');
|
||||
|
||||
// expect(container).toMatchSnapshot();
|
||||
|
||||
await wait(200);
|
||||
expect(getByText('刷新表单')).toBeInTheDocument();
|
||||
fireEvent.click(getByText('刷新表单'));
|
||||
|
||||
await wait(200);
|
||||
|
||||
expect(
|
||||
(container.querySelector('[name="author"]') as HTMLInputElement).value
|
||||
).toEqual('fex');
|
||||
|
||||
// expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:form reload with data', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688714086
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新表单',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'reload',
|
||||
componentId: 'form_reload',
|
||||
data: {
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_reload',
|
||||
debug: true,
|
||||
initApi: '/api/mock2/form/initData',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '姓名:'
|
||||
},
|
||||
{
|
||||
name: 'author',
|
||||
type: 'input-text',
|
||||
label: '作者:'
|
||||
},
|
||||
{
|
||||
name: 'age',
|
||||
type: 'input-text',
|
||||
label: '年龄:'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await wait(500);
|
||||
const author: HTMLInputElement = container.querySelector('[name="author"]')!;
|
||||
expect(author).toBeInTheDocument();
|
||||
fireEvent.change(author, {
|
||||
target: {value: 'amis'}
|
||||
});
|
||||
|
||||
await wait(200);
|
||||
expect(author.value).toEqual('amis');
|
||||
|
||||
expect(getByText('刷新表单')).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(getByText('刷新表单'));
|
||||
await wait(200);
|
||||
|
||||
expect(author.value).toEqual('fex');
|
||||
expect((container.querySelector('[name="age"]') as any)?.value).toEqual('18');
|
||||
});
|
||||
|
||||
test('doAction:form reset', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688714086
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '重置表单',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'reset',
|
||||
componentId: 'form_reset'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_reset',
|
||||
initApi: '/api/mock2/form/initData',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '姓名:'
|
||||
},
|
||||
{
|
||||
name: 'author',
|
||||
type: 'input-text',
|
||||
label: '作者:'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.change(container.querySelector('[name="author"]')!, {
|
||||
target: {value: 'amis'}
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect((container.querySelector('[name="author"]') as any)?.value).toEqual(
|
||||
'amis'
|
||||
);
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('重置表单')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/重置表单/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect((container.querySelector('[name="author"]') as any)?.value).toEqual(
|
||||
'fex'
|
||||
);
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:form clear', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688714086
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '清空表单',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'clear',
|
||||
componentId: 'form_clear'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_clear',
|
||||
debug: true,
|
||||
initApi: '/api/mock2/form/initData',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '姓名:'
|
||||
},
|
||||
{
|
||||
name: 'author',
|
||||
type: 'hidden',
|
||||
label: '作者:'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await wait(500);
|
||||
await waitFor(() => {
|
||||
expect(getByText('清空表单')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/清空表单/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('[value="Amis Renderer"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:form static&nonstatic', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688714086
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '静态模式',
|
||||
className: 'mr-2 mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'static',
|
||||
componentId: 'form_static'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '编辑模式',
|
||||
className: 'mr-2 mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'nonstatic',
|
||||
componentId: 'form_static'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_static',
|
||||
title: '表单',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'text',
|
||||
label: '输入框',
|
||||
mode: 'horizontal',
|
||||
value: 'text'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('静态模式')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/静态模式/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('.cxd-Form-static')).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('.cxd-TextControl-input')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('编辑模式')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/编辑模式/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('.cxd-TextControl-input')
|
||||
).toBeInTheDocument();
|
||||
expect(container.querySelector('.cxd-Form-static')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:form valdiate requiredOn', async () => {
|
||||
const onSubmit = jest.fn();
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'form',
|
||||
submitText: '提交表单',
|
||||
body: [
|
||||
{
|
||||
type: 'switch',
|
||||
name: 'a',
|
||||
label: 'a'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'b',
|
||||
requiredOn: '${a}',
|
||||
label: 'b'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
onSubmit
|
||||
},
|
||||
makeEnv({})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('提交表单'));
|
||||
await wait(200);
|
||||
expect(onSubmit).toBeCalled();
|
||||
|
||||
expect(container.querySelector('.cxd-Switch')!).toBeInTheDocument();
|
||||
fireEvent.click(container.querySelector('.cxd-Switch')!);
|
||||
await wait(300);
|
||||
fireEvent.click(getByText('提交表单'));
|
||||
await wait(300);
|
||||
|
||||
const ul = container.querySelector('.cxd-Form-feedback');
|
||||
expect(ul).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(container.querySelector('input[name="b"]')!, {
|
||||
target: {value: '123'}
|
||||
});
|
||||
fireEvent.click(getByText('提交表单'));
|
||||
|
||||
await wait(200);
|
||||
expect(onSubmit).toBeCalledTimes(2);
|
||||
|
||||
expect(onSubmit.mock.calls[1][0]).toMatchObject({
|
||||
a: true,
|
||||
b: '123'
|
||||
});
|
||||
|
||||
expect(container.querySelector('.cxd-Form-feedback')).toBeNull();
|
||||
|
||||
fireEvent.change(container.querySelector('input[name="b"]')!, {
|
||||
target: {value: ''}
|
||||
});
|
||||
await wait(300);
|
||||
|
||||
expect(container.querySelector('.cxd-Form-feedback')).toBeInTheDocument();
|
||||
fireEvent.click(container.querySelector('.cxd-Switch')!);
|
||||
await wait(300);
|
||||
|
||||
expect(container.querySelector('.cxd-Form-feedback')).toBeNull();
|
||||
});
|
||||
119
packages/amis/__tests__/event-action/renderers/form/locationPicker.test.tsx
Executable file
119
packages/amis/__tests__/event-action/renderers/form/locationPicker.test.tsx
Executable file
@@ -0,0 +1,119 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../../src';
|
||||
import {render as amisRender} from '../../../../src';
|
||||
import {makeEnv, wait} from '../../../helper';
|
||||
|
||||
test('EventAction:locationPicker', async () => {
|
||||
const notify = jest.fn();
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'location-picker',
|
||||
id: 'location-picker',
|
||||
ak: 'LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7',
|
||||
coordinatesType: 'bd09',
|
||||
name: 'location',
|
||||
resetValue: {
|
||||
address: '北京市东城区天安门广场中央',
|
||||
lat: 39.910966,
|
||||
lng: 116.404165,
|
||||
city: '北京'
|
||||
},
|
||||
onEvent: {
|
||||
change: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'form',
|
||||
args: {
|
||||
value: {
|
||||
location: '${event.data.value | json}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form',
|
||||
debug: true,
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '位置信息:',
|
||||
name: 'location',
|
||||
id: 'input-text'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '赋值',
|
||||
id: 'u:d2662e693f82',
|
||||
className: 'button-set-value',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'setValue',
|
||||
args: {
|
||||
value: {
|
||||
address: '北京市东城区天安门内',
|
||||
lat: 39.914912,
|
||||
lng: 116.403982,
|
||||
city: '北京'
|
||||
}
|
||||
},
|
||||
componentId: 'location-picker'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '重置',
|
||||
id: 'u:a1d92fc92cbb',
|
||||
className: 'button-reset',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'reset',
|
||||
componentId: 'location-picker'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await wait(500);
|
||||
const buttonSetValue = container.querySelector('.button-set-value');
|
||||
|
||||
fireEvent.click(buttonSetValue!);
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(getByText('北京市东城区天安门内')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
const buttonReset = container.querySelector('.button-reset');
|
||||
|
||||
fireEvent.click(buttonReset!);
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(getByText('北京市东城区天安门广场中央')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,167 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
// import {fireEvent as fireEvent2} from '@testing-library/dom';
|
||||
import '../../../../src';
|
||||
import {render as amisRender} from '../../../../src';
|
||||
import {makeEnv, wait} from '../../../helper';
|
||||
|
||||
test('EventAction:inputRange', async () => {
|
||||
const notify = jest.fn();
|
||||
const {container} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'input-range',
|
||||
name: 'range',
|
||||
value: 10,
|
||||
min: 0,
|
||||
showInput: true,
|
||||
clearabled: true,
|
||||
onEvent: {
|
||||
change: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'form_data',
|
||||
args: {
|
||||
value: {
|
||||
rangeEvent: '触发了change',
|
||||
rangeValue: '值为${range}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
blur: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'form_data',
|
||||
args: {
|
||||
value: {
|
||||
rangeEvent: '触发了blur',
|
||||
rangeValue: '值为${range}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
focus: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'form_data',
|
||||
args: {
|
||||
value: {
|
||||
rangeEvent: '触发了focus',
|
||||
rangeValue: '值为${range}'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
id: 'form_data',
|
||||
title: '表单',
|
||||
debug: true,
|
||||
data: {
|
||||
rangeValue: '什么都没有',
|
||||
rangeEvent: '什么都没触发'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '滑块值',
|
||||
name: 'rangeValue',
|
||||
disabled: true,
|
||||
className: 'input-text-range-value'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '滑块事件',
|
||||
name: 'rangeEvent',
|
||||
disabled: true,
|
||||
className: 'input-text-range-event'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await wait(500);
|
||||
const inputs = container.querySelector('.cxd-InputRange-input input')!;
|
||||
|
||||
// input change
|
||||
const valueChange = 23;
|
||||
fireEvent.change(inputs, {
|
||||
target: {
|
||||
value: valueChange
|
||||
}
|
||||
});
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('[value="触发了change"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector(`[value="值为${valueChange}"]`)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
/**
|
||||
* 滑动 change case先注释掉,因为fireEvent.mouseMove时,event中拿不到pageX。
|
||||
// 滑动 change
|
||||
const slider = container.querySelector('.cxd-InputRange-handle-icon')!;
|
||||
fireEvent.mouseDown(slider);
|
||||
fireEvent.mouseMove(slider, {
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
});
|
||||
fireEvent.mouseUp(slider);
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('[value="触发了change"]')
|
||||
).toBeInTheDocument();
|
||||
expect(container.querySelector(`[value="值为0"]`)).toBeInTheDocument();
|
||||
});
|
||||
*/
|
||||
|
||||
// 临时替代滑动 change case
|
||||
fireEvent.change(inputs, {
|
||||
target: {
|
||||
value: 0
|
||||
}
|
||||
});
|
||||
await wait(300);
|
||||
|
||||
// focus
|
||||
fireEvent.focus(inputs);
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('[value="触发了focus"]')
|
||||
).toBeInTheDocument();
|
||||
expect(container.querySelector(`[value="值为0"]`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// blur
|
||||
fireEvent.blur(inputs);
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[value="触发了blur"]')).toBeInTheDocument();
|
||||
expect(container.querySelector(`[value="值为0"]`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
}, 10000);
|
||||
@@ -0,0 +1,102 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../../src';
|
||||
import {render as amisRender} from '../../../../src';
|
||||
import {makeEnv, wait} from '../../../helper';
|
||||
|
||||
test('EventAction:switch', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
id: 1
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '修改开关的值',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'u:6613bfa3a18e',
|
||||
actionType: 'setValue',
|
||||
args: {
|
||||
value: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
id: 'u:9d7d695145bb'
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
title: '表单',
|
||||
debug: true,
|
||||
body: [
|
||||
{
|
||||
label: '开启',
|
||||
type: 'switch',
|
||||
name: 'switch',
|
||||
id: 'u:6613bfa3a18e',
|
||||
value: false,
|
||||
mode: 'inline',
|
||||
onEvent: {
|
||||
change: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'ajax',
|
||||
api: '/api/mock2/form/saveForm?switch=${switch}'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
id: 'u:82d44e407eb0',
|
||||
actions: [
|
||||
{
|
||||
type: 'submit',
|
||||
label: '提交',
|
||||
primary: true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('修改开关的值')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(getByText(/修改开关的值/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('.is-checked')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
fireEvent.click(container.querySelector('.is-checked')!);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalled();
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual(
|
||||
'/api/mock2/form/saveForm?switch=false'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,290 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../../src';
|
||||
import {render as amisRender} from '../../../../src';
|
||||
import {makeEnv, wait} from '../../../helper';
|
||||
|
||||
test('doAction:formItem validate', async () => {
|
||||
const notify = jest.fn();
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '校验name',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'validateFormItem',
|
||||
componentId: 'name_validate',
|
||||
outputVar: 'form_validate_result'
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'validate_info',
|
||||
args: {
|
||||
value: '${event.data.form_validate_result|json}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '校验email',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'validateFormItem',
|
||||
componentId: 'email_validate',
|
||||
outputVar: 'form_validate_result'
|
||||
},
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'validate_info',
|
||||
args: {
|
||||
value: '${event.data.form_validate_result|json}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'validate_info',
|
||||
id: 'validate_info',
|
||||
label: '验证信息:'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'validate_res',
|
||||
id: 'validate_res',
|
||||
label: '验证结果:'
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
onEvent: {
|
||||
formItemValidateSucc: {
|
||||
actions: [
|
||||
{
|
||||
expression: '${event.data.__formName === "name"}',
|
||||
actionType: 'setValue',
|
||||
componentId: 'validate_res',
|
||||
args: {
|
||||
value: 'validate name success'
|
||||
}
|
||||
},
|
||||
{
|
||||
expression: '${event.data.__formName === "email"}',
|
||||
actionType: 'setValue',
|
||||
componentId: 'validate_res',
|
||||
args: {
|
||||
value: 'validate email success'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
formItemValidateError: {
|
||||
actions: [
|
||||
{
|
||||
expression: '${event.data.__formName === "name"}',
|
||||
actionType: 'setValue',
|
||||
componentId: 'validate_res',
|
||||
args: {
|
||||
value: 'validate name fail'
|
||||
}
|
||||
},
|
||||
{
|
||||
expression: '${event.data.__formName === "email"}',
|
||||
actionType: 'setValue',
|
||||
componentId: 'validate_res',
|
||||
args: {
|
||||
value: 'validate email fail'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
id: 'name_validate',
|
||||
name: 'name',
|
||||
label: '姓名:',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
type: 'input-text',
|
||||
id: 'email_validate',
|
||||
label: '邮箱:',
|
||||
required: true,
|
||||
validations: {
|
||||
isEmail: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// 校验 name
|
||||
await waitFor(() => {
|
||||
expect(getByText('校验name')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText(/校验name/));
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual(`{ "error": "这是必填项"}`);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_res"]') as any)?.value
|
||||
).toEqual('validate name fail');
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// 校验 email 必填
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(getByText('校验email')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText(/校验email/));
|
||||
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual(`{ "error": "这是必填项"}`);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_res"]') as any)?.value
|
||||
).toEqual('validate email fail');
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// 校验 email 格式
|
||||
fireEvent.change(container.querySelector('[name="email"]')!, {
|
||||
target: {value: 'invalid_email'}
|
||||
});
|
||||
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('[name="email"][value="invalid_email"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('校验email')).toBeInTheDocument();
|
||||
});
|
||||
fireEvent.click(getByText(/校验email/));
|
||||
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual(`{ "error": "Email 格式不正确", "value": "invalid_email"}`);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_res"]') as any)?.value
|
||||
).toEqual('validate email fail');
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// 填写值
|
||||
fireEvent.change(container.querySelector('[name="name"]')!, {
|
||||
target: {value: 'amis'}
|
||||
});
|
||||
|
||||
await wait(300);
|
||||
fireEvent.change(container.querySelector('[name="email"]')!, {
|
||||
target: {value: 'amis@baidu.com'}
|
||||
});
|
||||
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(container.querySelector('[value="amis"]')).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[value="amis@baidu.com"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// 清空错误信息
|
||||
fireEvent.change(container.querySelector('[name="validate_info"]')!, {
|
||||
target: {value: ''}
|
||||
});
|
||||
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual('');
|
||||
});
|
||||
|
||||
// 重新校验name
|
||||
fireEvent.click(getByText(/校验name/));
|
||||
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('.is-error .is-required .has-error--isRequired')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual(`{ "error": "", "value": "amis"}`);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_res"]') as any)?.value
|
||||
).toEqual('validate name success');
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
// 重新校验email
|
||||
fireEvent.click(getByText(/校验email/));
|
||||
|
||||
await wait(300);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
container.querySelector('.is-error .is-required .has-error--isRequired')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_info"]') as any)?.value
|
||||
).toEqual(`{ "error": "", "value": "amis@baidu.com"}`);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
(container.querySelector('[name="validate_res"]') as any)?.value
|
||||
).toEqual('validate email success');
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
}, 10000);
|
||||
87
packages/amis/__tests__/event-action/renderers/icon.test.tsx
Normal file
87
packages/amis/__tests__/event-action/renderers/icon.test.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv} from '../../helper';
|
||||
|
||||
test('EventAction:icon', async () => {
|
||||
const notify = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
btnDisabled: true,
|
||||
btnNotDisabled: false
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'icon',
|
||||
icon: 'cloud',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发点击事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mouseenter: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发鼠标移入事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mouseleave: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'info',
|
||||
msg: '派发鼠标移出事件'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const icon = container.querySelector('.cloud');
|
||||
fireEvent.click(icon);
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发点击事件', {
|
||||
msg: '派发点击事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.mouseEnter(icon);
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发鼠标移入事件', {
|
||||
msg: '派发鼠标移入事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
fireEvent.mouseLeave(icon);
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalledWith('info', '派发鼠标移出事件', {
|
||||
msg: '派发鼠标移出事件',
|
||||
msgType: 'info'
|
||||
});
|
||||
});
|
||||
});
|
||||
285
packages/amis/__tests__/event-action/renderers/page.test.tsx
Normal file
285
packages/amis/__tests__/event-action/renderers/page.test.tsx
Normal file
@@ -0,0 +1,285 @@
|
||||
import React = require('react');
|
||||
import * as renderer from 'react-test-renderer';
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv} from '../../helper';
|
||||
|
||||
test('doAction:page reload', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
title: 'Test Page Component',
|
||||
date: '2017-10-13'
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
initApi: '/api/mock2/page/initData',
|
||||
id: 'page_reload',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新Page数据加载请求',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'page_reload',
|
||||
actionType: 'reload'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的标题:',
|
||||
name: 'title'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的年龄:',
|
||||
name: 'age'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('刷新Page数据加载请求')).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="title"][value="Test Page Component"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid="spinner"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText(/刷新Page数据加载请求/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/mock2/page/initData');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/mock2/page/initData');
|
||||
expect(
|
||||
container.querySelector('[name="title"][value="Test Page Component"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:page reload with data', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
title: 'Test Page Component',
|
||||
date: '2017-10-13'
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
initApi: '/api/mock2/page/initData',
|
||||
id: 'page_reload',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新Page数据加载请求,同时把年龄更新为18',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'page_reload',
|
||||
actionType: 'reload',
|
||||
data: {
|
||||
age: '18'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的标题:',
|
||||
name: 'title'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的年龄:',
|
||||
name: 'age'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByText('刷新Page数据加载请求,同时把年龄更新为18')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="title"][value="Test Page Component"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid="spinner"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText(/刷新Page数据加载请求,同时把年龄更新为18/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/mock2/page/initData');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/mock2/page/initData');
|
||||
expect(
|
||||
container.querySelector('[name="title"][value="Test Page Component"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value="18"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:page reload with data(same name)', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
title: 'Test Page Component',
|
||||
date: '2017-10-13'
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
initApi: '/api/mock2/page/initData',
|
||||
id: 'page_reload',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新Page数据加载请求,请求返回的date会覆盖动作传递的date',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'page_reload',
|
||||
actionType: 'reload',
|
||||
data: {
|
||||
date: '2023-07-07'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的标题:',
|
||||
name: 'title'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '日期:',
|
||||
name: 'date'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByText('刷新Page数据加载请求,请求返回的date会覆盖动作传递的date')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="title"][value="Test Page Component"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="date"][value="2017-10-13"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid="spinner"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(
|
||||
getByText(/刷新Page数据加载请求,请求返回的date会覆盖动作传递的date/)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/mock2/page/initData');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/mock2/page/initData');
|
||||
expect(
|
||||
container.querySelector('[name="title"][value="Test Page Component"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="date"][value="2017-10-13"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
@@ -0,0 +1,159 @@
|
||||
import {fireEvent, render} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv, wait} from '../../helper';
|
||||
|
||||
test('pagination: pageNum change event', async () => {
|
||||
const mockFn = jest.fn();
|
||||
const pageChange = jest.fn();
|
||||
const {container} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'pagination',
|
||||
layout: 'total,perPage,pager,go',
|
||||
mode: 'normal',
|
||||
activePage: 2,
|
||||
lastPage: 99999,
|
||||
total: 999,
|
||||
perPage: 10,
|
||||
maxButtons: 7,
|
||||
showPerPage: true,
|
||||
perPageAvailable: [10, 20, 50, 100],
|
||||
showPageInput: true,
|
||||
disabled: false,
|
||||
id: 'u:1bf323bc4dbd',
|
||||
onPageChange: pageChange,
|
||||
onEvent: {
|
||||
change: {
|
||||
weight: 0,
|
||||
actions: [
|
||||
{
|
||||
actionType: 'custom',
|
||||
script: mockFn
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{},
|
||||
makeEnv({})
|
||||
)
|
||||
);
|
||||
// 当前页码改变
|
||||
const prev = container.querySelector('.cxd-Pagination-prev')!;
|
||||
fireEvent.click(prev); // 上一页
|
||||
await wait(100);
|
||||
expect(mockFn).toBeCalledTimes(1);
|
||||
await wait(200);
|
||||
expect(pageChange).toBeCalled();
|
||||
expect(pageChange.mock.calls[0]).toEqual([1, 10]);
|
||||
|
||||
const next = container.querySelector('.cxd-Pagination-next')!;
|
||||
fireEvent.click(next); // 下一页
|
||||
await wait(300);
|
||||
expect(mockFn).toBeCalledTimes(2);
|
||||
await wait(200);
|
||||
expect(pageChange).toBeCalled();
|
||||
expect(pageChange.mock.calls[1]).toEqual([3, 10]);
|
||||
|
||||
const go = container.querySelector('.cxd-Pagination-inputGroup')!;
|
||||
fireEvent.change(go.querySelector('.cxd-Pagination-inputGroup-input')!, {
|
||||
target: {value: 9}
|
||||
});
|
||||
await wait(400);
|
||||
fireEvent.click(go.querySelector('.cxd-Pagination-inputGroup-right')!); // 输入后点击go
|
||||
await wait(500);
|
||||
expect(mockFn).toBeCalledTimes(3);
|
||||
await wait(200);
|
||||
expect(pageChange).toBeCalled();
|
||||
expect(pageChange.mock.calls[2]).toEqual([9, 10]);
|
||||
|
||||
function getPagerItem() {
|
||||
const pager = container.querySelectorAll(
|
||||
'.cxd-Pagination > .cxd-Pagination-pager-item'
|
||||
);
|
||||
return pager[3];
|
||||
}
|
||||
fireEvent.click(getPagerItem()!); // 点击页码切换
|
||||
await wait(600);
|
||||
expect(mockFn).toBeCalledTimes(4);
|
||||
await wait(200);
|
||||
expect(pageChange).toBeCalled();
|
||||
expect(pageChange.mock.calls[3]).toEqual([4, 10]);
|
||||
});
|
||||
|
||||
test('pagination: prevent pageNum change event ', async () => {
|
||||
const mockFn = jest.fn();
|
||||
const pageChange = jest.fn();
|
||||
const {container} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'pagination',
|
||||
layout: 'total,perPage,pager,go',
|
||||
mode: 'normal',
|
||||
activePage: 2,
|
||||
lastPage: 99999,
|
||||
total: 999,
|
||||
perPage: 10,
|
||||
maxButtons: 7,
|
||||
showPerPage: true,
|
||||
perPageAvailable: [10, 20, 50, 100],
|
||||
showPageInput: true,
|
||||
disabled: false,
|
||||
id: 'u:1bf323bc4dbd',
|
||||
onPageChange: pageChange,
|
||||
onEvent: {
|
||||
change: {
|
||||
weight: 0,
|
||||
actions: [
|
||||
{
|
||||
actionType: 'custom',
|
||||
preventDefault: true, // 阻止事件默认行为
|
||||
script: mockFn
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{},
|
||||
makeEnv({})
|
||||
)
|
||||
);
|
||||
// 当前页码改变
|
||||
const prev = container.querySelector('.cxd-Pagination-prev')!;
|
||||
fireEvent.click(prev); // 上一页
|
||||
await wait(100);
|
||||
expect(mockFn).toBeCalledTimes(1);
|
||||
await wait(200);
|
||||
expect(pageChange).not.toBeCalled();
|
||||
|
||||
const next = container.querySelector('.cxd-Pagination-next')!;
|
||||
fireEvent.click(next); // 下一页
|
||||
await wait(300);
|
||||
expect(mockFn).toBeCalledTimes(2);
|
||||
await wait(200);
|
||||
expect(pageChange).not.toBeCalled();
|
||||
|
||||
const go = container.querySelector('.cxd-Pagination-inputGroup')!;
|
||||
fireEvent.change(go.querySelector('.cxd-Pagination-inputGroup-input')!, {
|
||||
target: {value: 9}
|
||||
});
|
||||
await wait(400);
|
||||
fireEvent.click(go.querySelector('.cxd-Pagination-inputGroup-right')!); // 输入后点击go
|
||||
await wait(500);
|
||||
expect(mockFn).toBeCalledTimes(3);
|
||||
await wait(200);
|
||||
expect(pageChange).not.toBeCalled();
|
||||
|
||||
function getPagerItem() {
|
||||
const pager = container.querySelectorAll(
|
||||
'.cxd-Pagination > .cxd-Pagination-pager-item'
|
||||
);
|
||||
return pager[3];
|
||||
}
|
||||
fireEvent.click(getPagerItem()!); // 点击页码切换
|
||||
await wait(600);
|
||||
expect(mockFn).toBeCalledTimes(4);
|
||||
await wait(200);
|
||||
expect(pageChange).not.toBeCalled();
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import {fireEvent, render} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv, wait} from '../../helper';
|
||||
|
||||
test('paginationWrapper: service + crud', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
label: '110101',
|
||||
name: '东城区',
|
||||
sale: 46861
|
||||
},
|
||||
{
|
||||
label: '110102',
|
||||
name: '西城区',
|
||||
sale: 44882
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'service',
|
||||
id: 'u:ff652047d747',
|
||||
api: {
|
||||
method: 'get',
|
||||
url: 'https://yapi.baidu-int.com/mock/42601/amis-chart/chart/sales/data2'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'pagination-wrapper',
|
||||
body: [
|
||||
{
|
||||
type: 'crud',
|
||||
source: '${items}',
|
||||
columns: [
|
||||
{
|
||||
name: 'label',
|
||||
label: '地区',
|
||||
type: 'text',
|
||||
id: 'u:331ab3342710'
|
||||
},
|
||||
{
|
||||
name: 'sale',
|
||||
label: '销售',
|
||||
type: 'text',
|
||||
id: 'u:3dba120eda1d'
|
||||
}
|
||||
],
|
||||
id: 'u:b3c77cb44fc8',
|
||||
perPageAvailable: [10]
|
||||
}
|
||||
],
|
||||
inputName: 'items',
|
||||
outputName: 'items',
|
||||
perPage: 20,
|
||||
position: 'bottom'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
await wait(200);
|
||||
const tds = [].slice
|
||||
.call(container.querySelectorAll('tbody td'))
|
||||
.map((td: any) => td.textContent);
|
||||
expect(tds).toEqual(['110101', '46861', '110102', '44882']);
|
||||
});
|
||||
515
packages/amis/__tests__/event-action/renderers/service.test.tsx
Normal file
515
packages/amis/__tests__/event-action/renderers/service.test.tsx
Normal file
@@ -0,0 +1,515 @@
|
||||
import React = require('react');
|
||||
import * as renderer from 'react-test-renderer';
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv, replaceReactAriaIds, wait} from '../../helper';
|
||||
|
||||
test('doAction:service reload', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688871102,
|
||||
info: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'form',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '名字:',
|
||||
name: 'name',
|
||||
value: 'amis'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '年龄:',
|
||||
name: 'age',
|
||||
value: 18
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新Service数据加载请求',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'service_reload',
|
||||
actionType: 'reload'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'service',
|
||||
api: '/api/mock2/form/initData',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的名字:',
|
||||
name: 'name'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的年龄:',
|
||||
name: 'age'
|
||||
}
|
||||
],
|
||||
id: 'service_reload'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('刷新Service数据加载请求')).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="name"][value="Amis Renderer"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid="spinner"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
replaceReactAriaIds(container);
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText(/刷新Service数据加载请求/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/mock2/form/initData');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/mock2/form/initData');
|
||||
expect(
|
||||
container.querySelector('[name="name"][value="Amis Renderer"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:service reload with data', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
name: 'Amis Renderer',
|
||||
author: 'fex',
|
||||
date: 1688871102,
|
||||
info: ''
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新Service数据加载请求,同时把年龄更新为18',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'service_reload',
|
||||
actionType: 'reload',
|
||||
data: {
|
||||
age: '18'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'service',
|
||||
api: '/api/mock2/form/initData',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的名字:',
|
||||
name: 'name'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的年龄:',
|
||||
name: 'age'
|
||||
}
|
||||
],
|
||||
id: 'service_reload'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByText('刷新Service数据加载请求,同时把年龄更新为18')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="name"][value="Amis Renderer"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid="spinner"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
replaceReactAriaIds(container);
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText(/刷新Service数据加载请求,同时把年龄更新为18/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/mock2/form/initData');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/mock2/form/initData');
|
||||
expect(
|
||||
container.querySelector('[name="name"][value="Amis Renderer"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value="18"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:service(schemaApi) reload', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
controls: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的名字:',
|
||||
name: 'name'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的年龄:',
|
||||
name: 'age'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新Service数据加载请求',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'service_reload',
|
||||
actionType: 'reload'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'service',
|
||||
schemaApi: '/api/schemaApi',
|
||||
id: 'service_reload'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('刷新Service数据加载请求')).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="name"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid="spinner"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
replaceReactAriaIds(container);
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText(/刷新Service数据加载请求/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/schemaApi?_replace=1');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/schemaApi?_replace=1');
|
||||
expect(
|
||||
container.querySelector('[name="name"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:service(schemaApi) reload with data', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
controls: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的名字:',
|
||||
name: 'name'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的年龄:',
|
||||
name: 'age'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新Service数据加载请求,同时把年龄更新为18',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'service_reload',
|
||||
actionType: 'reload',
|
||||
data: {
|
||||
age: '18'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'service',
|
||||
schemaApi: '/api/schemaApi',
|
||||
id: 'service_reload'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByText('刷新Service数据加载请求,同时把年龄更新为18')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="name"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid="spinner"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
replaceReactAriaIds(container);
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText(/刷新Service数据加载请求,同时把年龄更新为18/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/schemaApi?_replace=1');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/schemaApi?_replace=1');
|
||||
expect(
|
||||
container.querySelector('[name="name"][value=""]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value="18"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('doAction:service(schemaApi+data) reload with data', async () => {
|
||||
const notify = jest.fn();
|
||||
const fetcher = jest.fn().mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
data: {
|
||||
name: 'amis',
|
||||
age: 20
|
||||
},
|
||||
controls: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的名字:',
|
||||
name: 'name'
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '我的年龄:',
|
||||
name: 'age'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
const {container, getByText} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '刷新Service数据加载请求,同时把年龄更新为18',
|
||||
level: 'primary',
|
||||
className: 'mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
componentId: 'service_reload',
|
||||
actionType: 'reload',
|
||||
data: {
|
||||
age: '18'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'service',
|
||||
schemaApi: '/api/schemaApi',
|
||||
id: 'service_reload'
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify,
|
||||
fetcher
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
getByText('刷新Service数据加载请求,同时把年龄更新为18')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="name"][value="amis"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value="20"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[data-testid="spinner"]')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
replaceReactAriaIds(container);
|
||||
expect(container).toMatchSnapshot();
|
||||
|
||||
fireEvent.click(getByText(/刷新Service数据加载请求,同时把年龄更新为18/));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(fetcher.mock.calls[0][0].url).toEqual('/api/schemaApi?_replace=1');
|
||||
expect(fetcher.mock.calls[1][0].url).toEqual('/api/schemaApi?_replace=1');
|
||||
expect(
|
||||
container.querySelector('[name="name"][value="amis"]')
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
container.querySelector('[name="age"][value="18"]')
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
64
packages/amis/__tests__/event-action/toast.test.tsx
Normal file
64
packages/amis/__tests__/event-action/toast.test.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv} from '../helper';
|
||||
|
||||
test('EventAction:toast', async () => {
|
||||
const notify = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
msg: '我是全局警告消息,可以配置不同类型和弹出位置'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: 'toast',
|
||||
level: 'warning',
|
||||
className: 'mr-2 mb-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'toast',
|
||||
args: {
|
||||
msgType: 'warning',
|
||||
msg: '${msg}~',
|
||||
position: 'top-right',
|
||||
closeButton: true,
|
||||
showIcon: true,
|
||||
timeout: 5000
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
notify
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('toast'));
|
||||
await waitFor(() => {
|
||||
expect(notify).toHaveBeenCalled();
|
||||
});
|
||||
expect(notify.mock.calls[0][0]).toEqual('warning');
|
||||
expect(notify.mock.calls[0][1]).toEqual(
|
||||
'我是全局警告消息,可以配置不同类型和弹出位置~'
|
||||
);
|
||||
expect(notify.mock.calls[0][2]).toEqual({
|
||||
msgType: 'warning',
|
||||
msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
|
||||
position: 'top-right',
|
||||
closeButton: true,
|
||||
showIcon: true,
|
||||
timeout: 5000
|
||||
});
|
||||
});
|
||||
105
packages/amis/__tests__/event-action/url.test.tsx
Normal file
105
packages/amis/__tests__/event-action/url.test.tsx
Normal file
@@ -0,0 +1,105 @@
|
||||
import {fireEvent, render, waitFor} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
import {makeEnv} from '../helper';
|
||||
|
||||
test('EventAction:url & link', async () => {
|
||||
const jumpTo = jest.fn();
|
||||
const {getByText, container}: any = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'page',
|
||||
data: {
|
||||
myname: 'lvxj',
|
||||
myjon: 'player'
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'button',
|
||||
label: '跳转',
|
||||
level: 'primary',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'url',
|
||||
args: {
|
||||
url: 'http://www.baidu.com',
|
||||
blank: true,
|
||||
params: {
|
||||
name: 'jack',
|
||||
jon: '${myjon}'
|
||||
}
|
||||
},
|
||||
data: {
|
||||
name: '${myname}',
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
label: '打开',
|
||||
level: 'primary',
|
||||
className: 'ml-2',
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'link',
|
||||
args: {
|
||||
link: './expression',
|
||||
targetType: 'page',
|
||||
params: {
|
||||
name: 'jack',
|
||||
jon: '${myjon}'
|
||||
}
|
||||
},
|
||||
data: {
|
||||
name: '${myname}',
|
||||
age: 18
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{},
|
||||
makeEnv({
|
||||
jumpTo
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('跳转'));
|
||||
fireEvent.click(getByText('打开'));
|
||||
await waitFor(() => {
|
||||
expect(jumpTo).toHaveBeenCalled();
|
||||
});
|
||||
expect(jumpTo.mock.calls[0][0]).toEqual(
|
||||
'http://www.baidu.com?name=lvxj&jon=player&age=18'
|
||||
);
|
||||
expect(jumpTo.mock.calls[0][1]).toEqual({
|
||||
actionType: 'url',
|
||||
type: 'button',
|
||||
url: 'http://www.baidu.com',
|
||||
blank: true,
|
||||
params: {
|
||||
name: 'jack',
|
||||
jon: 'player'
|
||||
}
|
||||
});
|
||||
expect(jumpTo.mock.calls[0][2]).toEqual({
|
||||
age: 18,
|
||||
name: 'lvxj'
|
||||
});
|
||||
expect(jumpTo.mock.calls[1][0]).toEqual(
|
||||
'./expression?name=lvxj&jon=player&age=18'
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user