mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
chore: 补充 input-image 的 autoFill 单元测试 (#5507)
This commit is contained in:
parent
1edaf425b3
commit
f139f9f508
@ -63,6 +63,9 @@ npm run build
|
||||
# 执行测试用例
|
||||
npm test --workspaces
|
||||
|
||||
# 测试某个用例
|
||||
npm test --workspace amis inputImage
|
||||
|
||||
# 查看测试用例覆盖率
|
||||
npm run coverage
|
||||
|
||||
|
86
packages/amis/__tests__/renderers/Form/inputImage.test.tsx
Normal file
86
packages/amis/__tests__/renderers/Form/inputImage.test.tsx
Normal file
@ -0,0 +1,86 @@
|
||||
import React = require('react');
|
||||
import PageRenderer from '../../../../amis-core/src/renderers/Form';
|
||||
import * as renderer from 'react-test-renderer';
|
||||
import {
|
||||
render,
|
||||
fireEvent,
|
||||
waitFor,
|
||||
getByText,
|
||||
prettyDOM
|
||||
} from '@testing-library/react';
|
||||
import '../../../src';
|
||||
import {render as amisRender} from '../../../src';
|
||||
import {makeEnv, wait} from '../../helper';
|
||||
|
||||
test('Renderer:input-image autoFill', async () => {
|
||||
const fetcher = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
status: 0,
|
||||
msg: 'ok',
|
||||
data: {
|
||||
value: 'img.png',
|
||||
filename: 'filename.png',
|
||||
myUrl: 'http://amis.com/image.png'
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
global.URL.createObjectURL = jest.fn();
|
||||
|
||||
const {
|
||||
debug,
|
||||
container,
|
||||
findByText,
|
||||
getByLabelText,
|
||||
findByPlaceholderText,
|
||||
findByDisplayValue
|
||||
} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'form',
|
||||
api: '/api/xxx',
|
||||
body: [
|
||||
{
|
||||
type: 'input-image',
|
||||
name: 'img',
|
||||
label: 'img',
|
||||
receiver: '/api/upload/file',
|
||||
autoFill: {
|
||||
// 不知道为啥这里不能用 ${url},可能是有什么地方和真实浏览器不一致
|
||||
myUrl: '${myUrl}'
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'myUrl'
|
||||
}
|
||||
],
|
||||
title: 'The form',
|
||||
actions: []
|
||||
},
|
||||
{},
|
||||
makeEnv({fetcher})
|
||||
)
|
||||
);
|
||||
|
||||
const fileInput = container.querySelector(
|
||||
'input[type=file]'
|
||||
)! as HTMLInputElement;
|
||||
|
||||
const file = new File(['file'], 'ping.png', {
|
||||
type: 'image/png'
|
||||
});
|
||||
|
||||
fireEvent.change(fileInput, {
|
||||
target: {files: [file]}
|
||||
});
|
||||
|
||||
await wait(500);
|
||||
|
||||
const textInput = container.querySelector(
|
||||
'input[name=myUrl]'
|
||||
)! as HTMLInputElement;
|
||||
|
||||
expect(textInput.value).toBe('http://amis.com/image.png');
|
||||
});
|
@ -83,7 +83,7 @@
|
||||
"@rollup/plugin-typescript": "^8.3.4",
|
||||
"@svgr/rollup": "^6.2.1",
|
||||
"@testing-library/jest-dom": "^5.16.4",
|
||||
"@testing-library/react": "^13.0.0",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@types/async": "^2.0.45",
|
||||
"@types/codemirror": "^5.60.3",
|
||||
"@types/echarts": "^4.9.2",
|
||||
|
Loading…
Reference in New Issue
Block a user