Skip to content

Commit ae4c4eb

Browse files
asadali145xitij2000
authored andcommitted
fix: allow thumbnail upload on Videos page if no thumbnail (openedx#2388) (openedx#2434)
* 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 5bb9e1f commit ae4c4eb

2 files changed

Lines changed: 50 additions & 9 deletions

File tree

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

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

51-
const showThumbnail = allowThumbnailUpload && thumbnail && isUploaded;
51+
const showThumbnail = allowThumbnailUpload && isUploaded;
5252

5353
return (
5454
<div className="video-thumbnail row justify-content-center align-itmes-center">
55-
{allowThumbnailUpload && showThumbnail && <div className="thumbnail-overlay" />}
55+
{allowThumbnailUpload && isUploaded && <div className="thumbnail-overlay" />}
5656
{showThumbnail && !thumbnailError && pageLoadStatus === RequestStatus.SUCCESSFUL ? (
5757
<>
5858
<div className="border rounded">
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-
/>
59+
{ thumbnail ? (
60+
<Image
61+
style={imageSize}
62+
className="m-1 bg-light-300"
63+
src={thumbnail}
64+
alt={intl.formatMessage(messages.thumbnailAltMessage, { displayName })}
65+
onError={() => setThumbnailError(true)}
66+
/>
67+
) : (
68+
<div
69+
className="row justify-content-center align-items-center m-0"
70+
style={imageSize}
71+
>
72+
<Icon src={VideoFile} style={{ height: '48px', width: '48px' }} />
73+
</div>
74+
)}
6675
</div>
6776
<div className="add-thumbnail" data-testid={`video-thumbnail-${id}`}>
6877
<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)