Unverified Commit 52bc19c3 authored by Sudheer's avatar Sudheer Committed by cpanato

Add a check for percent value on uploadProgress. (#2223)

* progess percent can be undefined if the file size is unknown
    so adding a check to not show progress bar and avoid toFixed convertion
parent 34389e84
......@@ -74,3 +74,65 @@ exports[`component/file_preview/file_progress_preview should match snapshot 1`]
</div>
</div>
`;
exports[`component/file_preview/file_progress_preview snapshot for percent value undefined 1`] = `
<div
className="file-preview post-image__column"
data-client-id="clientId"
key="clientId"
>
<div
className="post-image__thumbnail"
>
<div
className="file-icon image"
/>
</div>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
>
<div
className="post-image__detail"
>
<FilenameOverlay
canDownload={false}
compactDisplay={false}
fileInfo={
Object {
"name": "file",
"percent": undefined,
"type": "image/png",
}
}
handleImageClick={null}
index="clientId"
/>
<span
className="post-image__uploadingTxt"
>
<FormattedMessage
defaultMessage="Uploading..."
id="admin.plugin.uploading"
values={Object {}}
/>
<span />
</span>
</div>
</div>
<div>
<a
className="file-preview__remove"
onClick={[Function]}
>
<i
className="fa fa-remove"
title="Remove Icon"
/>
</a>
</div>
</div>
</div>
`;
......@@ -28,7 +28,7 @@ export default class FileProgressPreview extends React.PureComponent {
const {fileInfo, clientId} = this.props;
if (fileInfo) {
percent = fileInfo.percent;
const percentTxt = ` (${percent.toFixed(0)}%)`;
const percentTxt = percent && ` (${percent.toFixed(0)}%)`;
const fileType = getFileTypeFromMime(fileInfo.type);
previewImage = <div className={'file-icon ' + Utils.getIconClassName(fileType)}/>;
......@@ -57,11 +57,13 @@ export default class FileProgressPreview extends React.PureComponent {
</React.Fragment>
)}
</span>
<ProgressBar
className='post-image__progressBar'
now={percent}
active={percent === 100}
/>
{percent && (
<ProgressBar
className='post-image__progressBar'
now={percent}
active={percent === 100}
/>
)}
</React.Fragment>
);
}
......
......@@ -27,4 +27,19 @@ describe('component/file_preview/file_progress_preview', () => {
);
expect(wrapper).toMatchSnapshot();
});
test('snapshot for percent value undefined', () => {
const props = {
...baseProps,
fileInfo: {
...fileInfo,
percent: undefined,
},
};
const wrapper = shallow(
<FileProgressPreview {...props}/>
);
expect(wrapper).toMatchSnapshot();
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment