From df8242ef47a619d3220adf43cd28d83c8554b28e Mon Sep 17 00:00:00 2001 From: Maham Akif Date: Mon, 5 Aug 2024 13:59:42 +0500 Subject: [PATCH] feat: show video section to learners with active subscription --- src/components/search/SearchPage.jsx | 15 ++++- .../search/tests/SearchPage.test.jsx | 55 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/components/search/tests/SearchPage.test.jsx diff --git a/src/components/search/SearchPage.jsx b/src/components/search/SearchPage.jsx index 03eb12337d..568e271a22 100644 --- a/src/components/search/SearchPage.jsx +++ b/src/components/search/SearchPage.jsx @@ -2,15 +2,28 @@ import React from 'react'; import { SearchData } from '@edx/frontend-enterprise-catalog-search'; import { useIntl } from '@edx/frontend-platform/i18n'; +import { useSubscriptions } from '../app/data'; +import { LICENSE_STATUS } from '../enterprise-user-subsidy/data/constants'; import Search from './Search'; import { SEARCH_TRACKING_NAME } from './constants'; import { getSearchFacetFilters } from './utils'; +import { features } from '../../config'; const SearchPage = () => { const intl = useIntl(); + const { data: { subscriptionLicense } } = useSubscriptions(); + const hasActivatedAndCurrentSubscription = ( + subscriptionLicense?.status === LICENSE_STATUS.ACTIVATED + && subscriptionLicense?.subscriptionPlan?.isCurrent + ); + return ( - + ); diff --git a/src/components/search/tests/SearchPage.test.jsx b/src/components/search/tests/SearchPage.test.jsx new file mode 100644 index 0000000000..f8695da199 --- /dev/null +++ b/src/components/search/tests/SearchPage.test.jsx @@ -0,0 +1,55 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; +import { AppContext } from '@edx/frontend-platform/react'; +import { IntlProvider } from '@edx/frontend-platform/i18n'; +import { useSubscriptions } from '../../app/data'; +import { LICENSE_STATUS } from '../../enterprise-user-subsidy/data/constants'; +import SearchPage from '../SearchPage'; +import { features } from '../../../config'; +import { renderWithRouter } from '../../../utils/tests'; + +jest.mock('../../app/data', () => ({ + useSubscriptions: jest.fn(), +})); + +jest.mock('../utils', () => ({ + getSearchFacetFilters: jest.fn().mockReturnValue([]), +})); + +jest.mock('../Search', () => function () { + return
Mock Search Component
; +}); + +const initialAppState = { + authenticatedUser: { userId: 'test-user-id', username: 'test-username' }, +}; + +const renderSearchPage = () => renderWithRouter( + + + + + , +); + +describe('SearchPage', () => { + beforeEach(() => { + jest.clearAllMocks(); + features.FEATURE_ENABLE_VIDEO_CATALOG = true; + }); + + it('renders SearchPage component', () => { + useSubscriptions.mockReturnValue({ + data: { + subscriptionLicense: { + status: LICENSE_STATUS.ACTIVATED, + subscriptionPlan: { isCurrent: true }, + }, + }, + }); + + renderSearchPage(); + expect(screen.queryByText('Mock Search Component')).toBeInTheDocument(); + }); +});