Skip to content

Commit

Permalink
feat: show expiration modal on dashboard and search page
Browse files Browse the repository at this point in the history
  • Loading branch information
Maham Akif authored and Maham Akif committed Oct 14, 2024
1 parent 5a1e7a6 commit 11f94a7
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/course/routes/CourseAbout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useIsAssignmentsOnlyLearner,
usePassLearnerCsodParams,
} from '../../app/data';
import ExpiredSubscriptionModal from '../ExpiredSubscriptionModal';
import ExpiredSubscriptionModal from '../../expired-subscription-modal';

const CourseAbout = () => {
const { data: canOnlyViewHighlightSets } = useCanOnlyViewHighlights();
Expand Down
2 changes: 2 additions & 0 deletions src/components/dashboard/DashboardPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
useSubscriptions,
} from '../app/data';
import BudgetExpiryNotification from '../budget-expiry-notification';
import ExpiredSubscriptionModal from '../expired-subscription-modal';

const DashboardPage = () => {
const intl = useIntl();
Expand Down Expand Up @@ -57,6 +58,7 @@ const DashboardPage = () => {
<Container size="lg" className="py-4">
<Helmet title={PAGE_TITLE} />
<BudgetExpiryNotification />
<ExpiredSubscriptionModal />
<h2 className="h1 mb-4">
{userFirstName
? intl.formatMessage(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import ExpiredSubscriptionModal from '../index';
import { useSubscriptions } from '../../app/data';
import { renderWithRouter } from '../../../utils/tests';

jest.mock('../../app/data', () => ({
...jest.requireActual('../../app/data'),
useSubscriptions: jest.fn(),
}));

describe('<ExpiredSubscriptionModal />', () => {
beforeEach(() => {
useSubscriptions.mockReturnValue({
data: {
customerAgreement: {
hasCustomLicenseExpirationMessaging: false,
expiredSubscriptionModalMessaging: null,
urlForExpiredModal: null,
hyperLinkTextForExpiredModal: null,
},
},
});
});

test('does not renderwithrouter if `hasCustomLicenseExpirationMessaging` is false', () => {
const { container } = renderWithRouter(<ExpiredSubscriptionModal />);
expect(container).toBeEmptyDOMElement();
});

test('renderwithrouters modal with messaging when `hasCustomLicenseExpirationMessaging` is true', () => {
useSubscriptions.mockReturnValue({
data: {
customerAgreement: {
hasCustomLicenseExpirationMessaging: true,
expiredSubscriptionModalMessaging: 'Your subscription has expired.',
urlForExpiredModal: '/renew',
hyperLinkTextForExpiredModal: 'Click here to renew',
},
},
});

renderWithRouter(<ExpiredSubscriptionModal />);

expect(screen.getByText('Your subscription has expired.')).toBeInTheDocument();
expect(screen.getByText('Click here to renew')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Click here to renew' })).toHaveAttribute('href', '/renew');
});

test('does not renderwithrouter modal if no customer agreement data is present', () => {
useSubscriptions.mockReturnValue({ data: { customerAgreement: null } });
const { container } = renderWithRouter(<ExpiredSubscriptionModal />);
expect(container).toBeEmptyDOMElement();
});

test('renderwithrouters close button in modal', () => {
useSubscriptions.mockReturnValue({
data: {
customerAgreement: {
hasCustomLicenseExpirationMessaging: true,
expiredSubscriptionModalMessaging: 'Subscription expired',
urlForExpiredModal: '/renew',
hyperLinkTextForExpiredModal: 'Renew',
},
},
});

renderWithRouter(<ExpiredSubscriptionModal />);
expect(screen.getByRole('button', { name: /close/i })).toBeInTheDocument();
});
});
2 changes: 2 additions & 0 deletions src/components/search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import ContentTypeSearchResultsContainer from './ContentTypeSearchResultsContain
import SearchVideo from './SearchVideo';
import { hasActivatedAndCurrentSubscription } from './utils';
import VideoBanner from '../microlearning/VideoBanner';
import ExpiredSubscriptionModal from '../expired-subscription-modal';

function useSearchPathwayModal() {
const [isLearnerPathwayModalOpen, openLearnerPathwayModal, close] = useToggle(false);
Expand Down Expand Up @@ -113,6 +114,7 @@ const Search = () => {

return (
<>
<ExpiredSubscriptionModal />
<Helmet title={PAGE_TITLE} />
<InstantSearch
indexName={config.ALGOLIA_INDEX_NAME}
Expand Down

0 comments on commit 11f94a7

Please sign in to comment.