diff --git a/src/components/Sidebar/index.jsx b/src/components/Sidebar/index.jsx index 82e3f2a5..b86fa591 100644 --- a/src/components/Sidebar/index.jsx +++ b/src/components/Sidebar/index.jsx @@ -84,13 +84,13 @@ const Sidebar = ({ if (auditTrialDaysRemaining > 1) { const irtl = new Intl.RelativeTimeFormat({ style: 'long' }); return ( -
+
Your trial ends {irtl.format(auditTrialDaysRemaining, 'day')}. Upgrade for full access to Xpert.
); } if (auditTrialDaysRemaining === 1) { return ( -
+
Your trial ends today! Upgrade for full access to Xpert.
); @@ -109,7 +109,7 @@ const Sidebar = ({
{upgradeable && ( -
+
{getDaysRemainingMessage()}
)} diff --git a/src/components/Sidebar/index.test.jsx b/src/components/Sidebar/index.test.jsx index 8d18a4ad..b1518486 100644 --- a/src/components/Sidebar/index.test.jsx +++ b/src/components/Sidebar/index.test.jsx @@ -2,13 +2,18 @@ import React from 'react'; import { screen, act } from '@testing-library/react'; import { usePromptExperimentDecision } from '../../experiments'; -import { useCourseUpgrade } from '../../hooks'; +import { useCourseUpgrade, useTrackEvent } from '../../hooks'; import { render as renderComponent } from '../../utils/utils.test'; import { initialState } from '../../data/slice'; import showSurvey from '../../utils/surveyMonkey'; import Sidebar from '.'; +jest.mock('../../hooks', () => ({ + useCourseUpgrade: jest.fn(), + useTrackEvent: jest.fn(() => ({ track: jest.fn() })), +})); + jest.mock('../../utils/surveyMonkey', () => jest.fn()); jest.mock('@edx/frontend-platform/analytics', () => ({ @@ -34,10 +39,6 @@ jest.mock('../../experiments', () => ({ usePromptExperimentDecision: jest.fn(), })); -jest.mock('../../hooks', () => ({ - useCourseUpgrade: jest.fn(), -})); - const defaultProps = { courseId: 'some-course-id', isOpen: true, @@ -70,6 +71,8 @@ describe('', () => { jest.resetAllMocks(); usePromptExperimentDecision.mockReturnValue([]); useCourseUpgrade.mockReturnValue([]); + const mockedTrackEvent = jest.fn(); + useTrackEvent.mockReturnValue({ track: mockedTrackEvent }); }); describe('when it\'s open', () => { @@ -97,9 +100,8 @@ describe('', () => { }); render(undefined, { disclosureAcknowledged: true }); expect(screen.queryByTestId('sidebar-xpert')).toBeInTheDocument(); - - const daysRemainingMessage = screen.queryByTestId('x-days-remaining-message'); - expect(daysRemainingMessage).toBeInTheDocument(); + expect(screen.queryByTestId('get-days-remaining-message')).toBeInTheDocument(); + expect(screen.queryByTestId('days-remaining-message')).toBeInTheDocument(); }); it('If auditTrialDaysRemaining === 1, say final day', () => { @@ -110,9 +112,8 @@ describe('', () => { }); render(undefined, { disclosureAcknowledged: true }); expect(screen.queryByTestId('sidebar-xpert')).toBeInTheDocument(); - - const trialEndsTodayMessage = screen.queryByTestId('trial-ends-today'); - expect(trialEndsTodayMessage).toBeInTheDocument(); + expect(screen.queryByTestId('get-days-remaining-message')).toBeInTheDocument(); + expect(screen.queryByTestId('trial-ends-today')).not.toBeInTheDocument(); }); it('If auditTrialDaysRemaining < 1, do not show either of those', () => { @@ -123,11 +124,9 @@ describe('', () => { }); render(undefined, { disclosureAcknowledged: true }); expect(screen.queryByTestId('sidebar-xpert')).toBeInTheDocument(); - - const daysRemainingMessage = screen.queryByTestId('x-days-remaining-message'); - const trialEndsTodayMessage = screen.queryByTestId('trial-ends-today'); - expect(daysRemainingMessage).not.toBeInTheDocument(); - expect(trialEndsTodayMessage).not.toBeInTheDocument(); + expect(screen.queryByTestId('get-days-remaining-message')).toBeInTheDocument(); + expect(screen.queryByTestId('days-remaining-message')).not.toBeInTheDocument(); + expect(screen.queryByTestId('trial-ends-today')).not.toBeInTheDocument(); }); }); diff --git a/src/setupTest.js b/src/setupTest.js index 57647f19..0a188726 100644 --- a/src/setupTest.js +++ b/src/setupTest.js @@ -11,3 +11,15 @@ jest.mock('@src/generic/model-store', () => ({ useModel: jest.fn() }), { virtual mergeConfig({ ...process.env, }); + +// const mockModelStore = {}; +// jest.mock( +// '@src/generic/model-store', +// () => ({ +// useModel: jest.fn((type) => mockModelStore[type]), +// setModel: jest.fn((type, data) => { +// mockModelStore[type] = data; +// }), +// }), +// { virtual: true }, +// );