From 815b872be00fd080150c7d234361ebb262e126b4 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 --- package-lock.json | 8 +-- package.json | 2 +- src/components/search/SearchPage.jsx | 15 ++++- .../search/tests/SearchPage.test.jsx | 55 +++++++++++++++++++ 4 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 src/components/search/tests/SearchPage.test.jsx diff --git a/package-lock.json b/package-lock.json index 7619a04bb..f9eb7511a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@edx/brand": "npm:@openedx/brand-openedx@1.2.3", "@edx/frontend-component-footer": "13.0.2", - "@edx/frontend-enterprise-catalog-search": "10.5.0", + "@edx/frontend-enterprise-catalog-search": "10.6.0", "@edx/frontend-enterprise-hotjar": "6.0.0", "@edx/frontend-enterprise-logistration": "8.0.0", "@edx/frontend-enterprise-utils": "8.0.0", @@ -2330,9 +2330,9 @@ } }, "node_modules/@edx/frontend-enterprise-catalog-search": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/@edx/frontend-enterprise-catalog-search/-/frontend-enterprise-catalog-search-10.5.0.tgz", - "integrity": "sha512-okvigALMRd6DPxEsGHX4x6b/Rm/0tD3GGLIGOPMO2aippegTj/7Fp1STaRorZQF1iWJmtHRsawd5PNh8qrB39w==", + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/@edx/frontend-enterprise-catalog-search/-/frontend-enterprise-catalog-search-10.6.0.tgz", + "integrity": "sha512-ECnNRzq4Vnh2lvlG+8HdHYRpp/1iDYjEuHA6syvbKZMpz6oU0ccb3SL2K4tGVzfQhBUEHduVZHet4d3odlIeKg==", "dependencies": { "@edx/frontend-enterprise-utils": "^9.1.0", "classnames": "2.2.5", diff --git a/package.json b/package.json index f4693fc61..fb55e46aa 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "dependencies": { "@edx/brand": "npm:@openedx/brand-openedx@1.2.3", "@edx/frontend-component-footer": "13.0.2", - "@edx/frontend-enterprise-catalog-search": "10.5.0", + "@edx/frontend-enterprise-catalog-search": "10.6.0", "@edx/frontend-enterprise-hotjar": "6.0.0", "@edx/frontend-enterprise-logistration": "8.0.0", "@edx/frontend-enterprise-utils": "8.0.0", diff --git a/src/components/search/SearchPage.jsx b/src/components/search/SearchPage.jsx index 03eb12337..568e271a2 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 000000000..f8695da19 --- /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(); + }); +});