Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENT-9290: Show the videos section only to the learners who have an active subscription #1140

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
Loading