chore:补充发送请求动作silent单测

This commit is contained in:
lvxiaojiao 2023-09-22 09:40:22 +08:00
parent 2dec657afa
commit b2fb4f2fa4
3 changed files with 162 additions and 15 deletions

View File

@ -288,7 +288,7 @@ run action ajax
#### 静默模式
当配置`options.silent: true`时,请求完成后不会弹出提示信息。
当配置`silent: true`时,请求完成后不会弹出提示信息。
```schema
{
@ -316,9 +316,7 @@ run action ajax
success: '成功了!欧耶',
failed: '失败了呢。。'
},
},
options: {
silent: true,
silent: true
},
data: {
age: 18

View File

@ -633,3 +633,131 @@ test('EventAction:ajax data3', async () => {
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);
debugger;
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);
});
});

View File

@ -1092,6 +1092,7 @@ describe('18. inner events', () => {
});
test('19. fetchInitData silent true', async () => {
const notify = jest.fn();
const fetcher = jest.fn().mockImplementationOnce(() => {
return new Promise(resolve =>
resolve({
@ -1105,27 +1106,47 @@ test('19. fetchInitData silent true', async () => {
const {container} = render(
amisRender(
{
type: 'crud',
api: {
method: 'get',
url: '/api/mock/sample',
silent: true
},
columns: [
type: 'page',
body: [
{
name: 'engine',
label: 'Rendering engine'
type: 'crud',
api: {
method: 'get',
url: '/api/mock/sample',
silent: true
},
columns: [
{
name: 'engine',
label: 'Rendering engine'
}
]
},
{
type: 'crud',
api: {
method: 'get',
url: '/api/mock/sample',
silent: false
},
columns: [
{
name: 'engine',
label: 'Rendering engine'
}
]
}
]
},
{},
{
fetcher
fetcher,
notify
}
)
);
await waitFor(() => {
expect(container.querySelector('.cxd-Toast')).not.toBeInTheDocument();
expect(notify).toBeCalledTimes(1);
});
});