-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: Conditionally render expiring learner credit alerts and modals #1224
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
21b3935
feat: Conditionally render expiring learner credit alerts and modals
brobro10000 7323f32
chore: tests
brobro10000 1cfd14d
chore: more tests
brobro10000 8ce07c8
chore: more tests
brobro10000 98495d7
Merge branch 'hu/ent-8917' of https://github.com/openedx/frontend-app…
brobro10000 563051b
chore: PR feedback
brobro10000 ea284c1
Merge branch 'master' into hu/ent-8917
brobro10000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
90 changes: 90 additions & 0 deletions
90
src/components/BudgetExpiryAlertAndModal/data/index.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,90 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { QueryClientProvider } from '@tanstack/react-query'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { Provider } from 'react-redux'; | ||
import { renderWithRouter } from '@edx/frontend-enterprise-utils'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import dayjs from 'dayjs'; | ||
import BudgetExpiryAlertAndModal from '../index'; | ||
import { queryClient } from '../../test/testUtils'; | ||
import { useEnterpriseBudgets } from '../../EnterpriseSubsidiesContext/data/hooks'; | ||
|
||
jest.mock('../../EnterpriseSubsidiesContext/data/hooks', () => ({ | ||
...jest.requireActual('../../EnterpriseSubsidiesContext/data/hooks'), | ||
useEnterpriseBudgets: jest.fn(), | ||
})); | ||
|
||
const mockStore = configureMockStore([thunk]); | ||
const getMockStore = store => mockStore(store); | ||
const enterpriseSlug = 'test-enterprise'; | ||
const enterpriseUUID = '1234'; | ||
const initialStoreState = { | ||
portalConfiguration: { | ||
enterpriseId: enterpriseUUID, | ||
enterpriseSlug, | ||
disableExpiryMessagingForLearnerCredit: false, | ||
enterpriseFeatures: { | ||
topDownAssignmentRealTimeLcm: true, | ||
}, | ||
}, | ||
}; | ||
const mockEnterpriseBudgetUuid = uuidv4(); | ||
const mockEnterpriseBudget = [ | ||
{ | ||
source: 'policy', | ||
id: mockEnterpriseBudgetUuid, | ||
name: 'test expiration plan 2 --- Everything', | ||
start: '2024-04-15T00:00:00Z', | ||
end: dayjs().add(11, 'days'), | ||
isCurrent: true, | ||
aggregates: { | ||
available: 20000, | ||
spent: 0, | ||
pending: 0, | ||
}, | ||
isAssignable: true, | ||
isRetired: false, | ||
}, | ||
]; | ||
|
||
const mockEndDateText = mockEnterpriseBudget[0].end.format('MMM D, YYYY'); | ||
|
||
const BudgetExpiryAlertAndModalWrapper = ({ | ||
initialState = initialStoreState, | ||
}) => { | ||
const store = getMockStore(initialState); | ||
return ( | ||
<QueryClientProvider client={queryClient()}> | ||
<IntlProvider locale="en"> | ||
<Provider store={store}> | ||
<BudgetExpiryAlertAndModal /> | ||
</Provider> | ||
</IntlProvider> | ||
</QueryClientProvider> | ||
); | ||
}; | ||
|
||
describe('BudgetExpiryAlertAndModal', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
useEnterpriseBudgets.mockReturnValue({ data: mockEnterpriseBudget }); | ||
}); | ||
it('renders without crashing', () => { | ||
renderWithRouter(<BudgetExpiryAlertAndModalWrapper />); | ||
expect(screen.getByTestId('expiry-notification-alert')).toBeTruthy(); | ||
expect(screen.getByText(`Your Learner Credit plan expires ${mockEndDateText}.`, { exact: false })).toBeTruthy(); | ||
}); | ||
it('does not render when budget is non expired and disableExpiryMessagingForLearnerCredit is true', () => { | ||
const updatedInitialStoreState = { | ||
portalConfiguration: { | ||
...initialStoreState.portalConfiguration, | ||
disableExpiryMessagingForLearnerCredit: true, | ||
}, | ||
}; | ||
renderWithRouter(<BudgetExpiryAlertAndModalWrapper initialState={updatedInitialStoreState} />); | ||
expect(screen.queryByTestId('expiry-notification-alert')).toBeFalsy(); | ||
expect(screen.queryByText(`Your Learner Credit plan expires ${mockEndDateText}.`, { exact: false })).toBeFalsy(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,5 @@ describe('<ContentHighlights>', () => { | |
data: { results: [{ applies_to_all_contexts: true }] }, | ||
})); | ||
renderWithRouter(<ContentHighlightsWrapper location={{ state: {} }} />); | ||
screen.debug(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol d'oh |
||
}); | ||
}); |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[kudos] Nice clean up on the
it.each
syntax :)