|
| 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