Skip to content

Commit

Permalink
chore: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed May 17, 2024
1 parent 7323f32 commit 1cfd14d
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/components/BudgetExpiryAlertAndModal/data/index.test.jsx
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();
});
});

0 comments on commit 1cfd14d

Please sign in to comment.