-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1042 from openedx/eahmadjaved/ENT-7660
feat: show all enterprise budgets regardless of plan and route correctly
- Loading branch information
Showing
17 changed files
with
769 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/components/EnterpriseSubsidiesContext/data/tests/BudgetDetailPage.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* eslint-disable react/prop-types */ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import thunk from 'redux-thunk'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { | ||
screen, | ||
render, | ||
} from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import BudgetDetailPage from '../../../learner-credit-management/BudgetDetailPage'; | ||
import { useOfferSummary, useOfferRedemptions } from '../../../learner-credit-management/data/hooks'; | ||
import { EXEC_ED_OFFER_TYPE } from '../../../learner-credit-management/data/constants'; | ||
import { EnterpriseSubsidiesContext } from '../..'; | ||
|
||
jest.mock('../../../learner-credit-management/data/hooks'); | ||
|
||
useOfferSummary.mockReturnValue({ | ||
isLoading: false, | ||
offerSummary: null, | ||
}); | ||
useOfferRedemptions.mockReturnValue({ | ||
isLoading: false, | ||
offerRedemptions: { | ||
itemCount: 0, | ||
pageCount: 0, | ||
results: [], | ||
}, | ||
fetchOfferRedemptions: jest.fn(), | ||
}); | ||
|
||
const mockStore = configureMockStore([thunk]); | ||
const getMockStore = store => mockStore(store); | ||
const enterpriseId = 'test-enterprise'; | ||
const enterpriseUUID = '1234'; | ||
const initialStore = { | ||
portalConfiguration: { | ||
enterpriseId, | ||
enterpriseSlug: enterpriseId, | ||
|
||
}, | ||
}; | ||
const store = getMockStore({ ...initialStore }); | ||
|
||
const mockEnterpriseOfferId = '123'; | ||
|
||
const mockOfferDisplayName = 'Test Enterprise Offer'; | ||
const mockOfferSummary = { | ||
totalFunds: 5000, | ||
redeemedFunds: 200, | ||
remainingFunds: 4800, | ||
percentUtilized: 0.04, | ||
offerType: EXEC_ED_OFFER_TYPE, | ||
}; | ||
|
||
const defaultEnterpriseSubsidiesContextValue = { | ||
isLoading: false, | ||
}; | ||
|
||
const BudgetDetailPageWrapper = ({ | ||
enterpriseSubsidiesContextValue = defaultEnterpriseSubsidiesContextValue, | ||
...rest | ||
}) => ( | ||
<MemoryRouter initialEntries={['/test-enterprise/admin/learner-credit/1234']}> | ||
|
||
<Provider store={store}> | ||
<IntlProvider locale="en"> | ||
<EnterpriseSubsidiesContext.Provider value={enterpriseSubsidiesContextValue}> | ||
<BudgetDetailPage {...rest} /> | ||
</EnterpriseSubsidiesContext.Provider> | ||
</IntlProvider> | ||
</Provider> | ||
</MemoryRouter> | ||
); | ||
|
||
describe('<BudgetDetailPage />', () => { | ||
describe('with enterprise offer', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('displays table on clicking view budget', async () => { | ||
const mockOffer = { | ||
id: mockEnterpriseOfferId, | ||
name: mockOfferDisplayName, | ||
start: '2022-01-01', | ||
end: '2023-01-01', | ||
}; | ||
useOfferSummary.mockReturnValue({ | ||
isLoading: false, | ||
offerSummary: mockOfferSummary, | ||
}); | ||
useOfferRedemptions.mockReturnValue({ | ||
isLoading: false, | ||
offerRedemptions: { | ||
itemCount: 0, | ||
pageCount: 0, | ||
results: [], | ||
}, | ||
fetchOfferRedemptions: jest.fn(), | ||
}); | ||
render(<BudgetDetailPageWrapper | ||
enterpriseUUID={enterpriseUUID} | ||
enterpriseSlug={enterpriseId} | ||
offer={mockOffer} | ||
/>); | ||
expect(screen.getByText('Learner Credit Management')); | ||
expect(screen.getByText('Overview')); | ||
expect(screen.getByText('No results found')); | ||
}); | ||
|
||
it('displays loading message while loading data', async () => { | ||
useOfferSummary.mockReturnValue({ | ||
isLoading: true, | ||
offerSummary: null, | ||
}); | ||
useOfferRedemptions.mockReturnValue({ | ||
isLoading: true, | ||
offerRedemptions: { | ||
itemCount: 0, | ||
pageCount: 0, | ||
results: [], | ||
}, | ||
fetchOfferRedemptions: jest.fn(), | ||
}); | ||
|
||
render(<BudgetDetailPageWrapper | ||
enterpriseUUID={enterpriseUUID} | ||
enterpriseSlug={enterpriseId} | ||
/>); | ||
|
||
expect(screen.getByText('loading')); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.