From 8ce07c8315c01ff825291bd2fd73f659cb5711b7 Mon Sep 17 00:00:00 2001 From: Hamzah Ullah Date: Fri, 17 May 2024 11:27:14 -0400 Subject: [PATCH] chore: more tests --- .../data/index.test.jsx | 90 +++++++++++++++++++ .../tests/ContentHighlights.test.jsx | 1 - 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/components/BudgetExpiryAlertAndModal/data/index.test.jsx diff --git a/src/components/BudgetExpiryAlertAndModal/data/index.test.jsx b/src/components/BudgetExpiryAlertAndModal/data/index.test.jsx new file mode 100644 index 0000000000..4a0577ac89 --- /dev/null +++ b/src/components/BudgetExpiryAlertAndModal/data/index.test.jsx @@ -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 ( + + + + + + + + ); +}; + +describe('BudgetExpiryAlertAndModal', () => { + beforeEach(() => { + jest.clearAllMocks(); + useEnterpriseBudgets.mockReturnValue({ data: mockEnterpriseBudget }); + }); + it('renders without crashing', () => { + renderWithRouter(); + 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(); + expect(screen.queryByTestId('expiry-notification-alert')).toBeFalsy(); + expect(screen.queryByText(`Your Learner Credit plan expires ${mockEndDateText}.`, { exact: false })).toBeFalsy(); + }); +}); diff --git a/src/components/ContentHighlights/tests/ContentHighlights.test.jsx b/src/components/ContentHighlights/tests/ContentHighlights.test.jsx index 75483d3fd3..2b2118f826 100644 --- a/src/components/ContentHighlights/tests/ContentHighlights.test.jsx +++ b/src/components/ContentHighlights/tests/ContentHighlights.test.jsx @@ -89,6 +89,5 @@ describe('', () => { data: { results: [{ applies_to_all_contexts: true }] }, })); renderWithRouter(); - screen.debug(); }); });