Skip to content

Commit

Permalink
fix: extract subscription uuid correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammad-ammar committed Apr 1, 2024
1 parent 7e36288 commit 60aaa9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/components/Admin/SubscriptionDetailPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import { useParams } from 'react-router-dom';
import SubscriptionExpirationModals from '../subscriptions/expiration/SubscriptionExpirationModals';
import SubscriptionDetails from './SubscriptionDetails';
import LicenseAllocationDetails from './licenses/LicenseAllocationDetails';
Expand All @@ -12,8 +11,8 @@ import SubscriptionDetailsSkeleton from '../subscriptions/SubscriptionDetailsSke
import { LPR_SUBSCRIPTION_PAGE_SIZE } from '../subscriptions/data/constants';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const SubscriptionDetailPage = ({ enterpriseSlug }) => {
const { subscriptionUUID } = useParams();
export const SubscriptionDetailPage = ({ enterpriseSlug, match }) => {
const { params: { subscriptionUUID } } = match;
const [subscription, loadingSubscription] = useSubscriptionFromParams({ subscriptionUUID });

if (!subscription && !loadingSubscription) {
Expand Down Expand Up @@ -43,6 +42,11 @@ export const SubscriptionDetailPage = ({ enterpriseSlug }) => {

SubscriptionDetailPage.propTypes = {
enterpriseSlug: PropTypes.string.isRequired,
match: PropTypes.shape({
params: PropTypes.shape({
subscriptionUUID: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
};

const mapStateToProps = state => ({
Expand Down
18 changes: 17 additions & 1 deletion src/components/Admin/SubscriptionDetailPage.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable react/jsx-no-constructed-context-values */
import React from 'react';
import PropTypes from 'prop-types';
import { render } from '@testing-library/react';
import { render, 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 { SubscriptionDetailPage } from './SubscriptionDetailPage';
Expand All @@ -11,6 +12,7 @@ import {
mockSubscriptionHooks,
MockSubscriptionContext,
} from '../subscriptions/tests/TestUtilities';
import * as hooks from '../subscriptions/data/contextHooks';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Expand All @@ -35,6 +37,11 @@ const defaultAppContext = {
enterpriseConfig: {
slug: 'test-enterprise',
},
match: {
params: {
subscriptionUUID: '28d4dcdc-c026-4c02-a263-82dd9c0d8b43',
},
},
};

const initialSubsidyRequestContextValue = {
Expand Down Expand Up @@ -78,4 +85,13 @@ describe('SubscriptionDetailPage', () => {
'Get Started',
);
});

it('renders correct message if no subscriptions', () => {
jest.spyOn(hooks, 'useSubscriptionFromParams').mockImplementation(
() => [false, false],
);
render(<SubscriptionDetailPageWrapper />);

expect(screen.getByText('No subscription available')).toBeInTheDocument();
});
});

0 comments on commit 60aaa9c

Please sign in to comment.