diff --git a/src/components/BudgetExpiryAlertAndModal/data/hooks/useExpiry.test.jsx b/src/components/BudgetExpiryAlertAndModal/data/hooks/useExpiry.test.jsx index eeca281568..0dd2481486 100644 --- a/src/components/BudgetExpiryAlertAndModal/data/hooks/useExpiry.test.jsx +++ b/src/components/BudgetExpiryAlertAndModal/data/hooks/useExpiry.test.jsx @@ -12,47 +12,66 @@ const modalClose = jest.fn(); const alertOpen = jest.fn(); const alertClose = jest.fn(); +const offsetDays = { + 120: dayjs().add(120, 'day'), + 90: dayjs().add(90, 'day'), + 60: dayjs().add(60, 'day'), + 30: dayjs().add(30, 'day'), + 10: dayjs().add(10, 'day'), + 1: dayjs().subtract(1, 'day'), +}; + describe('useExpiry', () => { beforeEach(() => { jest.clearAllMocks(); }); it.each([ - (() => { - const endDate = dayjs().add(120, 'day'); - return { endDate, expected: expiryThresholds[120]({ date: formatDate(endDate.toString()) }) }; - })(), - (() => { - const endDate = dayjs().add(90, 'day'); - return { endDate, expected: expiryThresholds[90]({ date: formatDate(endDate.toString()) }) }; - })(), - (() => { - const endDate = dayjs().add(60, 'day'); - return { endDate, expected: expiryThresholds[60]({ date: formatDate(endDate.toString()) }) }; - })(), - (() => { - const endDate = dayjs().add(30, 'day'); - return { endDate, expected: expiryThresholds[30]({ date: formatDate(endDate.toString()) }) }; - })(), - (() => { - const endDate = dayjs().add(10, 'day'); - const today = dayjs().add(1, 'minutes'); - const durationDiff = dayjs.duration(endDate.diff(today)); - - return { - endDate, - expected: expiryThresholds[10]({ - date: formatDate(endDate.toString()), - days: durationDiff.days(), - hours: durationDiff.hours(), - }), - }; - })(), - (() => { - const endDate = dayjs().subtract(1, 'day'); - return { endDate, expected: expiryThresholds[0]({ date: formatDate(endDate.toString()) }) }; - })(), - ])('displays correct notification and modal when plan is expiring in %s days', ({ endDate, expected }) => { + { + endDate: offsetDays['120'], + expected: expiryThresholds[120]({ + date: formatDate(offsetDays['120'].toString()), + }), + isNonExpiredBudget: true, + }, + { + endDate: offsetDays['90'], + expected: expiryThresholds[90]({ + date: formatDate(offsetDays['90'].toString()), + }), + isNonExpiredBudget: true, + }, + { + endDate: offsetDays['60'], + expected: expiryThresholds[60]({ + date: formatDate(offsetDays['60'].toString()), + }), + isNonExpiredBudget: true, + }, + { + endDate: offsetDays['30'], + expected: expiryThresholds[30]({ + date: formatDate(offsetDays['30'].toString()), + }), + isNonExpiredBudget: true, + }, + { + endDate: offsetDays['10'], + expected: expiryThresholds[10]({ + date: formatDate(offsetDays['10'].toString()), + days: dayjs.duration(offsetDays['10'].diff(dayjs())).days(), + hours: dayjs.duration(offsetDays['10'].diff(dayjs())).hours(), + }), + isNonExpiredBudget: true, + }, + { + endDate: offsetDays['1'], + expected: expiryThresholds[0]({ + date: formatDate(offsetDays['1'].toString()), + }), + isNonExpiredBudget: false, + }, + ])('displays correct notification and modal when plan is expiring in %s days', ({ endDate, expected, isNonExpiredBudget }) => { const budgets = [{ end: endDate }]; // Mock data with an expiring budget const { result } = renderHook(() => useExpiry('enterpriseId', budgets, modalOpen, modalClose, alertOpen, alertClose)); @@ -60,6 +79,7 @@ describe('useExpiry', () => { expect(result.current.notification).toEqual(expected.notificationTemplate); expect(result.current.modal).toEqual(expected.modalTemplate); expect(result.current.status).toEqual(expected.status); + expect(result.current.isNonExpiredBudget).toEqual(isNonExpiredBudget); }); it('displays no notification with both an expired and non-expired budget', () => { diff --git a/src/components/BudgetExpiryAlertAndModal/index.jsx b/src/components/BudgetExpiryAlertAndModal/index.jsx index 9eb1429f92..102c3e9969 100644 --- a/src/components/BudgetExpiryAlertAndModal/index.jsx +++ b/src/components/BudgetExpiryAlertAndModal/index.jsx @@ -20,7 +20,6 @@ import useExpiry from './data/hooks/useExpiry'; const BudgetExpiryAlertAndModal = ({ enterpriseUUID, enterpriseFeatures, disableExpiryMessagingForLearnerCredit }) => { const [modalIsOpen, modalOpen, modalClose] = useToggle(false); const [alertIsOpen, alertOpen, alertClose] = useToggle(false); - const location = useLocation(); const budgetDetailRouteMatch = matchPath( diff --git a/src/data/reducers/portalConfiguration.js b/src/data/reducers/portalConfiguration.js index cfae1ee448..abc5b554b0 100644 --- a/src/data/reducers/portalConfiguration.js +++ b/src/data/reducers/portalConfiguration.js @@ -103,7 +103,7 @@ const portalConfiguration = (state = initialState, action) => { enterpriseSlug: null, enterpriseBranding: null, identityProvider: null, - disableExpiryMessagingForLearnerCredit: null, + disableExpiryMessagingForLearnerCredit: false, enableCodeManagementScreen: false, enableReportingConfigScreen: false, enableSubscriptionManagementScreen: false, diff --git a/src/data/reducers/portalConfiguration.test.js b/src/data/reducers/portalConfiguration.test.js index 897d1212eb..5baf895707 100644 --- a/src/data/reducers/portalConfiguration.test.js +++ b/src/data/reducers/portalConfiguration.test.js @@ -14,6 +14,7 @@ const initialState = { enterpriseSlug: null, enterpriseBranding: null, identityProvider: null, + disableExpiryMessagingForLearnerCredit: false, enableCodeManagementScreen: false, enableReportingConfigScreen: false, enableSubscriptionManagementScreen: false, @@ -43,6 +44,7 @@ const enterpriseData = { identity_provider: { uuid: 'test-identity-provider-uuid', }, + disable_expiry_messaging_for_learner_credit: true, enable_portal_code_management_screen: true, enable_portal_reporting_config_screen: true, enable_portal_subscription_management_screen: true, @@ -77,6 +79,7 @@ describe('portalConfiguration reducer', () => { enterpriseSlug: enterpriseData.slug, enterpriseBranding: enterpriseData.branding_configuration, identityProvider: enterpriseData.identity_provider, + disableExpiryMessagingForLearnerCredit: enterpriseData.disable_expiry_messaging_for_learner_credit, enableCodeManagementScreen: enterpriseData.enable_portal_code_management_screen, enableReportingConfigScreen: enterpriseData.enable_portal_reporting_config_screen, enableSubscriptionManagementScreen: enterpriseData.enable_portal_subscription_management_screen, // eslint-disable-line max-len