Skip to content

Commit

Permalink
feat: show video section to learners with active subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Maham Akif authored and Maham Akif committed Aug 7, 2024
1 parent beeacc8 commit 815b872
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"@edx/brand": "npm:@openedx/[email protected]",
"@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",
Expand Down
15 changes: 14 additions & 1 deletion src/components/search/SearchPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<SearchData searchFacetFilters={getSearchFacetFilters(intl)} trackingName={SEARCH_TRACKING_NAME}>
<SearchData
searchFacetFilters={getSearchFacetFilters(intl)}
trackingName={SEARCH_TRACKING_NAME}
enableVideos={features.FEATURE_ENABLE_VIDEO_CATALOG && hasActivatedAndCurrentSubscription}
>
<Search />
</SearchData>
);
Expand Down
55 changes: 55 additions & 0 deletions src/components/search/tests/SearchPage.test.jsx
Original file line number Diff line number Diff line change
@@ -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 () {

Check warning on line 20 in src/components/search/tests/SearchPage.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected unnamed function
return <div>Mock Search Component</div>;
});

const initialAppState = {
authenticatedUser: { userId: 'test-user-id', username: 'test-username' },
};

const renderSearchPage = () => renderWithRouter(
<IntlProvider locale="en">
<AppContext.Provider value={initialAppState}>
<SearchPage />
</AppContext.Provider>
</IntlProvider>,
);

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();
});
});

0 comments on commit 815b872

Please sign in to comment.