Skip to content

Commit 0117c1e

Browse files
authored
fix: allow thumbnail upload on Videos page if no thumbnail (#2388)
* fix: allow thumbnail upload if no thumbnail * fix: improve thumbnail upload impl * test: fix tests * test: fix tests * fix: do not show thumbnail upload if not allowed * test: fix coverage * test: add thumbnail test * fix: display thumbnail overlay when video status is success
1 parent 0f7c8de commit 0117c1e

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

src/files-and-videos/videos-page/VideoThumbnail.jsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,30 @@ const VideoThumbnail = ({
4747
const isFailed = VIDEO_FAILURE_STATUSES.includes(status);
4848
const failedMessage = intl.formatMessage(messages.failedCheckboxLabel);
4949

50-
const showThumbnail = allowThumbnailUpload && thumbnail && isUploaded;
50+
const showThumbnail = allowThumbnailUpload && isUploaded;
5151

5252
return (
5353
<div className="video-thumbnail row justify-content-center align-itmes-center">
54-
{allowThumbnailUpload && showThumbnail && <div className="thumbnail-overlay" />}
54+
{allowThumbnailUpload && isUploaded && <div className="thumbnail-overlay" />}
5555
{showThumbnail && !thumbnailError && pageLoadStatus === RequestStatus.SUCCESSFUL ? (
5656
<>
5757
<div className="border rounded">
58-
<Image
59-
style={imageSize}
60-
className="m-1 bg-light-300"
61-
src={thumbnail}
62-
alt={intl.formatMessage(messages.thumbnailAltMessage, { displayName })}
63-
onError={() => setThumbnailError(true)}
64-
/>
58+
{ thumbnail ? (
59+
<Image
60+
style={imageSize}
61+
className="m-1 bg-light-300"
62+
src={thumbnail}
63+
alt={intl.formatMessage(messages.thumbnailAltMessage, { displayName })}
64+
onError={() => setThumbnailError(true)}
65+
/>
66+
) : (
67+
<div
68+
className="row justify-content-center align-items-center m-0"
69+
style={imageSize}
70+
>
71+
<Icon src={VideoFile} style={{ height: '48px', width: '48px' }} />
72+
</div>
73+
)}
6574
</div>
6675
<div className="add-thumbnail" data-testid={`video-thumbnail-${id}`}>
6776
<Button
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { render, fireEvent, screen } from '@testing-library/react';
3+
import { IntlProvider } from '@edx/frontend-platform/i18n';
4+
import VideoThumbnail from './VideoThumbnail';
5+
import { VIDEO_SUCCESS_STATUSES } from './data/constants';
6+
import { RequestStatus } from '../../data/constants';
7+
8+
it('shows fallback icon if thumbnail fails to load', () => {
9+
const { container } = render(
10+
<IntlProvider locale="en">
11+
<VideoThumbnail
12+
thumbnail="http://bad-url/image.png"
13+
displayName="Test Video"
14+
id="vid1"
15+
imageSize={{ width: '100px', height: '100px' }}
16+
handleAddThumbnail={jest.fn()}
17+
videoImageSettings={{ videoImageUploadEnabled: true, supportedFileFormats: { jpg: 'image/jpg' } }}
18+
status={VIDEO_SUCCESS_STATUSES[0]}
19+
pageLoadStatus={RequestStatus.SUCCESSFUL}
20+
/>
21+
</IntlProvider>,
22+
);
23+
24+
const image = screen.getByRole('img', { name: /video thumbnail/i });
25+
expect(image).toBeInTheDocument();
26+
fireEvent.error(image);
27+
28+
expect(screen.queryByRole('img', { name: /video thumbnail/i })).toBeNull();
29+
30+
const fallbackSvg = container.querySelector('svg[role="img"]');
31+
expect(fallbackSvg).toBeInTheDocument();
32+
});

0 commit comments

Comments
 (0)