Skip to content

Commit

Permalink
feat: implemented some pre release requirements on video detail page (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jajjibhai008 authored Aug 20, 2024
1 parent 036db74 commit fa8a2dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
35 changes: 12 additions & 23 deletions src/components/microlearning/VideoDetailPage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable max-len */
import React, { useEffect } from 'react';
import { Link, useLocation } from 'react-router-dom';
import {
Container, Breadcrumb, Row, Badge, Skeleton,
Container, Row, Badge, Skeleton,
Hyperlink,
Icon,
Button,
Expand All @@ -14,6 +13,7 @@ import {
} from '@openedx/paragon/icons';
import {
useVideoDetails, useEnterpriseCustomer, useVideoCourseMetadata,
useSubscriptions,
} from '../app/data';
import './styles/VideoDetailPage.scss';
import DelayedFallbackContainer from '../DelayedFallback/DelayedFallbackContainer';
Expand All @@ -22,6 +22,8 @@ import { getCoursePrice, useCoursePacingType } from '../course/data';
import VideoCourseReview from './VideoCourseReview';
import { hasTruthyValue, isDefinedAndNotNull } from '../../utils/common';
import { getLevelType } from './data/utils';
import { hasActivatedAndCurrentSubscription } from '../search/utils';
import { features } from '../../config';

const VideoPlayer = loadable(() => import(/* webpackChunkName: "videojs" */ '../video/VideoPlayer'), {
fallback: (
Expand All @@ -32,35 +34,32 @@ const VideoPlayer = loadable(() => import(/* webpackChunkName: "videojs" */ '../
});

const VideoDetailPage = () => {
const location = useLocation();
const { data: enterpriseCustomer } = useEnterpriseCustomer();
const { data: videoData } = useVideoDetails();
const { data: courseMetadata } = useVideoCourseMetadata(videoData?.courseKey);
const [pacingType, pacingTypeContent] = useCoursePacingType(courseMetadata?.activeCourseRun);
const { data: { subscriptionLicense } } = useSubscriptions();
const intl = useIntl();

const customOptions = {
showPlaybackMenu: true,
showTranscripts: true,
transcriptUrls: videoData?.transcriptUrls,
};
const enableVideos = (
features.FEATURE_ENABLE_VIDEO_CATALOG
&& hasActivatedAndCurrentSubscription(subscriptionLicense)
);

useEffect(() => {
if (videoData?.videoURL) {
VideoPlayer.preload();
}
}, [videoData?.videoURL]);

const routeLinks = [
{
label: 'Explore Videos',
to: `/${enterpriseCustomer.slug}/videos`,
},
];
if (location.state?.parentRoute) {
routeLinks.push(location.state.parentRoute);
if (!enableVideos) {
return <NotFoundPage />;
}

// Comprehensive error handling will be implemented upon receiving specific error use cases from the UX team
// and corresponding Figma designs.
if (!videoData) {
Expand All @@ -76,14 +75,7 @@ const VideoDetailPage = () => {
}
const levelType = courseMetadata?.activeCourseRun?.levelType ? getLevelType(intl, courseMetadata.activeCourseRun.levelType) : null;
return (
<Container size="lg" className="pt-3 video-detail-page-wrapper">
<div className="small">
<Breadcrumb
links={routeLinks}
activeLabel={videoData?.courseTitle}
linkAs={Link}
/>
</div>
<Container size="lg" className="mt-4 video-detail-page-wrapper">
<Row>
<article className="col-12 col-lg-9">
<div className="d-flex flex-column align-items-start flex-grow-1 video-container">
Expand Down Expand Up @@ -154,7 +146,6 @@ const VideoDetailPage = () => {
<div className="x-small">
<Hyperlink
destination={`/${enterpriseCustomer.slug}/course/${courseMetadata?.key}`}
target="_blank"
>
{courseMetadata?.title}
</Hyperlink>
Expand Down Expand Up @@ -242,7 +233,6 @@ const VideoDetailPage = () => {
a: (chunks) => (
<Hyperlink
destination={`/${enterpriseCustomer.slug}/course/${courseMetadata?.key}`}
target="_blank"
>
{chunks}
</Hyperlink>
Expand All @@ -255,7 +245,6 @@ const VideoDetailPage = () => {
variant="primary"
as={Hyperlink}
destination={`/${enterpriseCustomer.slug}/course/${courseMetadata?.key}`}
target="_blank"
className="mt-4.5 w-100"
>
<FormattedMessage
Expand Down
31 changes: 31 additions & 0 deletions src/components/microlearning/tests/VideoDetailPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import VideoDetailPage from '../VideoDetailPage';
import {
useVideoDetails, useEnterpriseCustomer, useVideoCourseMetadata,
useVideoCourseReviews,
useSubscriptions,
} from '../../app/data';
import { COURSE_PACING_MAP } from '../../course/data';
import { LICENSE_STATUS } from '../../enterprise-user-subsidy/data/constants';
import { features } from '../../../config';

const APP_CONFIG = {
USE_API_CACHE: true,
Expand Down Expand Up @@ -44,6 +47,7 @@ jest.mock('../../app/data', () => ({
useRedeemablePolicies: jest.fn(() => ({ data: { redeemablePolicies: [] } })),
useVideoCourseMetadata: jest.fn(() => ({ data: { courseKey: 'test-course-key' } })),
useVideoCourseReviews: jest.fn(() => ({ data: { courseKey: 'test-course-key' } })),
useSubscriptions: jest.fn(),
}));

jest.mock('react-router-dom', () => ({
Expand Down Expand Up @@ -97,6 +101,18 @@ describe('VideoDetailPage Tests', () => {
useEnterpriseCustomer.mockReturnValue({ data: mockEnterpriseCustomer });
useVideoDetails.mockReturnValue({ data: VIDEO_MOCK_DATA });
useVideoCourseReviews.mockReturnValue({ data: mockCourseReviews });
useSubscriptions.mockReturnValue({
data: {
subscriptionLicense: {
status: LICENSE_STATUS.ACTIVATED,
subscriptionPlan: {
enterpriseCatalogUuid: 'test-catalog-uuid',
isCurrent: true,
},
},
},
});
features.FEATURE_ENABLE_VIDEO_CATALOG = true;
});

it('Renders video details when data is available', () => {
Expand Down Expand Up @@ -135,4 +151,19 @@ describe('VideoDetailPage Tests', () => {
renderWithRouter(<VideoDetailPageWrapper />);
expect(screen.getByTestId('not-found-page')).toBeInTheDocument();
});
it('renders a not found page when user do not have active subscription', () => {
useSubscriptions.mockReturnValue({
data: {
subscriptionLicense: {
status: LICENSE_STATUS.ACTIVATED,
subscriptionPlan: {
enterpriseCatalogUuid: 'test-catalog-uuid',
isCurrent: false,
},
},
},
});
renderWithRouter(<VideoDetailPageWrapper />);
expect(screen.getByTestId('not-found-page')).toBeInTheDocument();
});
});

0 comments on commit fa8a2dc

Please sign in to comment.