fix: ensure hyperlink renders correctly based on videoSource presence (#2400)
* fix: ensure hyperlink renders correctly based on videoSource presence * refactor: remove unnecessary blank lines in VideoPreviewWidget tests
This commit is contained in:
@@ -47,7 +47,7 @@ export const VideoPreviewWidget = ({
|
||||
<Stack gap={1} className="justify-content-center">
|
||||
<h4 className="text-primary mb-0">{blockTitle}</h4>
|
||||
<LanguageNamesWidget transcripts={transcripts} />
|
||||
{videoType && (
|
||||
{videoType && videoSource && (
|
||||
<Hyperlink
|
||||
className="text-primary x-small"
|
||||
destination={videoSource}
|
||||
|
||||
@@ -43,5 +43,54 @@ describe('VideoPreviewWidget', () => {
|
||||
);
|
||||
expect(screen.queryByText('No transcripts added')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders hyperlink when videoSource is provided', () => {
|
||||
render(
|
||||
<VideoPreviewWidget
|
||||
videoSource="https://example.com/video.mp4"
|
||||
intl={mockIntl}
|
||||
transcripts={[]}
|
||||
blockTitle="Test Video"
|
||||
thumbnail=""
|
||||
/>,
|
||||
);
|
||||
|
||||
const hyperlink = screen.getByRole('link');
|
||||
expect(hyperlink).toBeInTheDocument();
|
||||
expect(hyperlink).toHaveAttribute('href', 'https://example.com/video.mp4');
|
||||
expect(hyperlink).toHaveAttribute('target', '_blank');
|
||||
expect(hyperlink).toHaveAttribute('rel', 'noopener noreferrer');
|
||||
});
|
||||
|
||||
test('does not render hyperlink when videoSource is empty', () => {
|
||||
render(
|
||||
<VideoPreviewWidget
|
||||
videoSource=""
|
||||
intl={mockIntl}
|
||||
transcripts={[]}
|
||||
blockTitle="Test Video"
|
||||
thumbnail=""
|
||||
/>,
|
||||
);
|
||||
|
||||
const hyperlink = screen.queryByRole('link');
|
||||
expect(hyperlink).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders YouTube video type as hyperlink when videoSource is YouTube URL', () => {
|
||||
render(
|
||||
<VideoPreviewWidget
|
||||
videoSource="https://youtu.be/dQw4w9WgXcQ"
|
||||
intl={mockIntl}
|
||||
transcripts={[]}
|
||||
blockTitle="YouTube Video"
|
||||
thumbnail=""
|
||||
/>,
|
||||
);
|
||||
|
||||
const hyperlink = screen.getByRole('link');
|
||||
expect(hyperlink).toBeInTheDocument();
|
||||
expect(hyperlink).toHaveAttribute('href', 'https://youtu.be/dQw4w9WgXcQ');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user