test: fix test cov (#27065)

* test:  upload and form

* refactor: tooltip always evaluates to true
This commit is contained in:
偏右 2020-10-10 13:32:27 +08:00 committed by GitHub
parent 2ed5a1e9d1
commit 4bf062c2a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 181 additions and 1 deletions

View File

@ -20,7 +20,7 @@ function toTooltipProps(tooltip: LabelTooltipType): WrapperTooltipProps | null {
return null;
}
if (tooltip && typeof tooltip === 'object' && !React.isValidElement(tooltip)) {
if (typeof tooltip === 'object' && !React.isValidElement(tooltip)) {
return tooltip as WrapperTooltipProps;
}

View File

@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Form.List should render empty without errors 1`] = `null`;

View File

@ -236,4 +236,9 @@ describe('Form.List', () => {
jest.useRealTimers();
});
});
it('should render empty without errors', () => {
const wrapper = mount(<Form.ErrorList />);
expect(wrapper.render()).toMatchSnapshot();
});
});

View File

@ -1313,6 +1313,161 @@ exports[`Upload List should support removeIcon and downloadIcon 1`] = `
</span>
`;
exports[`Upload List should support removeIcon and downloadIcon 2`] = `
<span
class=""
>
<div
class="ant-upload ant-upload-select ant-upload-select-picture"
>
<span
class="ant-upload"
role="button"
tabindex="0"
>
<input
accept=""
style="display: none;"
type="file"
/>
<button
type="button"
>
upload
</button>
</span>
</div>
<div
class="ant-upload-list ant-upload-list-picture"
>
<div
class=""
>
<span>
<div
class="ant-upload-list-item ant-upload-list-item-uploading ant-upload-list-item-list-type-picture"
>
<div
class="ant-upload-list-item-info"
>
<span>
<div
class="ant-upload-list-item-thumbnail"
>
<span
aria-label="loading"
class="anticon anticon-loading"
role="img"
>
<svg
aria-hidden="true"
class="anticon-spin"
data-icon="loading"
fill="currentColor"
focusable="false"
height="1em"
viewBox="0 0 1024 1024"
width="1em"
>
<path
d="M988 548c-19.9 0-36-16.1-36-36 0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 00-94.3-139.9 437.71 437.71 0 00-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7 26.7 63.1 40.2 130.2 40.2 199.3.1 19.9-16 36-35.9 36z"
/>
</svg>
</span>
</div>
<a
class="ant-upload-list-item-name ant-upload-list-item-name-icon-count-1"
href="https://cdn.xxx.com/aaa"
rel="noopener noreferrer"
target="_blank"
title="image"
>
image
</a>
<span
class="ant-upload-list-item-card-actions picture"
>
<button
class="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn"
title="Remove file"
type="button"
>
<i>
RM
</i>
</button>
</span>
</span>
</div>
<div
class="ant-upload-list-item-progress"
/>
</div>
</span>
</div>
<div
class=""
>
<span>
<div
class="ant-upload-list-item ant-upload-list-item-done ant-upload-list-item-list-type-picture"
>
<div
class="ant-upload-list-item-info"
>
<span>
<a
class="ant-upload-list-item-thumbnail"
href="https://cdn.xxx.com/aaa"
rel="noopener noreferrer"
target="_blank"
>
<img
alt="image"
class="ant-upload-list-item-image"
src="https://cdn.xxx.com/aaa"
/>
</a>
<a
class="ant-upload-list-item-name ant-upload-list-item-name-icon-count-2"
href="https://cdn.xxx.com/aaa"
rel="noopener noreferrer"
target="_blank"
title="image"
>
image
</a>
<span
class="ant-upload-list-item-card-actions picture"
>
<button
class="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn"
title="Download file"
type="button"
>
<i>
DL
</i>
</button>
<button
class="ant-btn ant-btn-text ant-btn-sm ant-btn-icon-only ant-upload-list-item-card-actions-btn"
title="Remove file"
type="button"
>
<i>
RM
</i>
</button>
</span>
</span>
</div>
</div>
</span>
</div>
</div>
</span>
`;
exports[`Upload List should support showRemoveIcon and showPreviewIcon 1`] = `
<span
class=""

View File

@ -510,6 +510,7 @@ describe('Upload List', () => {
await sleep();
expect(handleChange.mock.calls.length).toBe(2);
});
it('should support removeIcon and downloadIcon', () => {
const list = [
{
@ -541,6 +542,22 @@ describe('Upload List', () => {
</Upload>,
);
expect(wrapper.render()).toMatchSnapshot();
const wrapper2 = mount(
<Upload
listType="picture"
defaultFileList={list}
showUploadList={{
showRemoveIcon: true,
showDownloadIcon: true,
removeIcon: <i>RM</i>,
downloadIcon: () => <i>DL</i>,
}}
>
<button type="button">upload</button>
</Upload>,
);
expect(wrapper2.render()).toMatchSnapshot();
});
// https://github.com/ant-design/ant-design/issues/7762