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: ensure budget_id query param is passed to analytics api #1049

Merged
merged 2 commits into from
Oct 5, 2023
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
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