amis2/packages/amis/__tests__/event-action/url.test.tsx
zhaojianhui 3e08ea7b0e
feat: 事件动作-打开页面优化,新增内容区打开、浏览器当前页打开、浏览器新开页打开 (#9273)
* feat: 打开页面支持页面跳转、浏览器跳转

* 修改时处理

* feat: 打开页面支持页面跳转、浏览器跳转

* feat: 打开页面支持页面跳转、浏览器跳转-删除无用代码

* test: 打开页面-补充文档、测试用例

* test: 打开页面-补充文档、测试用例

* test: 打开页面动作修改字段linkType为targetType

* 遗漏文件提交

---------

Co-authored-by: zhaojianhui <zhaojianhui@baidu.com>
2024-01-05 15:54:20 +08:00

106 lines
2.6 KiB
TypeScript

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'
);
});