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:
Pradeep
2025-08-28 15:14:17 +05:30
committed by GitHub
parent 6646c8ed0f
commit 0f2dd4a88f
2 changed files with 50 additions and 1 deletions

View File

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

View File

@@ -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');
});
});
});