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

fix: extract subscription uuid correctly #1193

Merged
merged 1 commit into from
Apr 1, 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
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();
});
});
Loading