Skip to content

Commit

Permalink
fix: ensure budget_id query param is passed to analytics api (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz authored Oct 5, 2023
1 parent 5f1cb88 commit 6a47c98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import { connect } from 'react-redux';
import { useParams } from 'react-router-dom';

import LearnerCreditAllocationTable from './LearnerCreditAllocationTable';
import { useOfferRedemptions } from './data';
import { useOfferRedemptions, isUUID } from './data';

const BudgetDetailActivityTabContents = ({
enterpriseUUID,
enterpriseSlug,
enableLearnerPortal,
}) => {
const { budgetId } = useParams();
const enterpriseOfferId = isUUID(budgetId) ? null : budgetId;
const subsidyAccessPolicyId = isUUID(budgetId) ? budgetId : null;
const {
isLoading: isLoadingOfferRedemptions,
offerRedemptions,
fetchOfferRedemptions,
} = useOfferRedemptions(enterpriseUUID, budgetId);
} = useOfferRedemptions(enterpriseUUID, enterpriseOfferId, subsidyAccessPolicyId);

return (
<LearnerCreditAllocationTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ useOfferRedemptions.mockReturnValue({

const mockStore = configureMockStore([thunk]);
const getMockStore = store => mockStore(store);
const enterpriseId = 'test-enterprise';
const enterpriseSlug = 'test-enterprise';
const enterpriseUUID = '1234';
const initialStoreState = {
portalConfiguration: {
enterpriseId,
enterpriseSlug: enterpriseId,
enterpriseId: enterpriseUUID,
enterpriseSlug,
enableLearnerPortal: true,
enterpriseFeatures: {
topDownAssignmentRealTimeLcm: true,
Expand All @@ -59,6 +59,7 @@ const initialStoreState = {
};

const mockEnterpriseOfferId = '123';
const mockSubsidyAccessPolicyUUID = 'c17de32e-b80b-468f-b994-85e68fd32751';

const mockOfferDisplayName = 'Test Enterprise Offer';
const mockOfferSummary = {
Expand Down Expand Up @@ -102,13 +103,29 @@ describe('<BudgetDetailPage />', () => {
});
});

it('displays spend table in "Activity" tab with empty results', async () => {
it.each([
{
budgetId: mockEnterpriseOfferId,
expectedUseOfferRedemptionsArgs: [enterpriseUUID, mockEnterpriseOfferId, null],
},
{
budgetId: mockSubsidyAccessPolicyUUID,
expectedUseOfferRedemptionsArgs: [enterpriseUUID, null, mockSubsidyAccessPolicyUUID],
},
])('displays spend table in "Activity" tab with empty results (%s)', async ({
budgetId,
expectedUseOfferRedemptionsArgs,
}) => {
const mockOffer = {
id: mockEnterpriseOfferId,
id: budgetId,
name: mockOfferDisplayName,
start: '2022-01-01',
end: '2023-01-01',
};
useParams.mockReturnValue({
budgetId,
activeTabKey: 'activity',
});
useOfferSummary.mockReturnValue({
isLoading: false,
offerSummary: mockOfferSummary,
Expand All @@ -125,10 +142,14 @@ describe('<BudgetDetailPage />', () => {
renderWithRouter(
<BudgetDetailPageWrapper
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseId}
enterpriseSlug={enterpriseSlug}
offer={mockOffer}
/>,
);

expect(useOfferRedemptions).toHaveBeenCalledTimes(1);
expect(useOfferRedemptions).toHaveBeenCalledWith(...expectedUseOfferRedemptionsArgs);

// Hero
expect(screen.getByText('Learner Credit Management'));
// Breadcrumb
Expand All @@ -149,7 +170,7 @@ describe('<BudgetDetailPage />', () => {
renderWithRouter(
<BudgetDetailPageWrapper
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseId}
enterpriseSlug={enterpriseSlug}
/>,
);
// Catalog tab exists and is active
Expand All @@ -169,7 +190,7 @@ describe('<BudgetDetailPage />', () => {
<BudgetDetailPageWrapper
initialState={initialState}
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseId}
enterpriseSlug={enterpriseSlug}
/>,
);
// Catalog tab does NOT exist
Expand All @@ -184,7 +205,7 @@ describe('<BudgetDetailPage />', () => {
renderWithRouter(
<BudgetDetailPageWrapper
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseId}
enterpriseSlug={enterpriseSlug}
/>,
);
// Activity tab exists and is active
Expand All @@ -199,7 +220,7 @@ describe('<BudgetDetailPage />', () => {
renderWithRouter(
<BudgetDetailPageWrapper
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseId}
enterpriseSlug={enterpriseSlug}
/>,
);
expect(screen.getByText('404')).toBeInTheDocument();
Expand All @@ -210,7 +231,7 @@ describe('<BudgetDetailPage />', () => {
renderWithRouter(
<BudgetDetailPageWrapper
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseId}
enterpriseSlug={enterpriseSlug}
/>,
);
const catalogTab = screen.getByText('Catalog');
Expand All @@ -228,7 +249,7 @@ describe('<BudgetDetailPage />', () => {
renderWithRouter(
<BudgetDetailPageWrapper
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseId}
enterpriseSlug={enterpriseSlug}
enterpriseSubsidiesContextValue={{
...defaultEnterpriseSubsidiesContextValue,
isLoading: true,
Expand Down

0 comments on commit 6a47c98

Please sign in to comment.