+
Your trial ends today!
Upgrade for full access to Xpert.
);
@@ -109,7 +108,7 @@ const Sidebar = ({
- {isUpgradeEligible
+ {upgradeable
&& (
{getDaysRemainingMessage()}
@@ -162,7 +161,6 @@ Sidebar.propTypes = {
isOpen: PropTypes.bool.isRequired,
setIsOpen: PropTypes.func.isRequired,
unitId: PropTypes.string.isRequired,
- isUpgradeEligible: PropTypes.bool.isRequired,
};
export default Sidebar;
diff --git a/src/components/Sidebar/index.test.jsx b/src/components/Sidebar/index.test.jsx
index f7a0cb04..8d18a4ad 100644
--- a/src/components/Sidebar/index.test.jsx
+++ b/src/components/Sidebar/index.test.jsx
@@ -1,10 +1,8 @@
import React from 'react';
import { screen, act } from '@testing-library/react';
-import { Factory } from 'rosie';
-import { setModel } from '@src/generic/model-store'; // eslint-disable-line import/no-unresolved
-
import { usePromptExperimentDecision } from '../../experiments';
+import { useCourseUpgrade } from '../../hooks';
import { render as renderComponent } from '../../utils/utils.test';
import { initialState } from '../../data/slice';
import showSurvey from '../../utils/surveyMonkey';
@@ -36,6 +34,10 @@ jest.mock('../../experiments', () => ({
usePromptExperimentDecision: jest.fn(),
}));
+jest.mock('../../hooks', () => ({
+ useCourseUpgrade: jest.fn(),
+}));
+
const defaultProps = {
courseId: 'some-course-id',
isOpen: true,
@@ -65,11 +67,9 @@ const render = async (props = {}, sliceState = {}) => {
describe('', () => {
beforeEach(async () => {
- setModel('courseHomeMeta', Factory.build('courseHomeMeta'));
- setModel('coursewareMeta', Factory.build('coursewareMeta'));
-
jest.resetAllMocks();
usePromptExperimentDecision.mockReturnValue([]);
+ useCourseUpgrade.mockReturnValue([]);
});
describe('when it\'s open', () => {
@@ -87,6 +87,48 @@ describe('', () => {
render(undefined, { disclosureAcknowledged: true });
expect(screen.queryByTestId('sidebar-xpert')).toBeInTheDocument();
});
+
+ // TODO: Write out these tests.
+ it('If auditTrialDaysRemaining > 1, show days remaining', () => {
+ useCourseUpgrade.mockReturnValue({
+ upgradeable: true,
+ upgradeUrl: 'https://mockurl.com',
+ auditTrialDaysRemaining: 2,
+ });
+ render(undefined, { disclosureAcknowledged: true });
+ expect(screen.queryByTestId('sidebar-xpert')).toBeInTheDocument();
+
+ const daysRemainingMessage = screen.queryByTestId('x-days-remaining-message');
+ expect(daysRemainingMessage).toBeInTheDocument();
+ });
+
+ it('If auditTrialDaysRemaining === 1, say final day', () => {
+ useCourseUpgrade.mockReturnValue({
+ upgradeable: true,
+ upgradeUrl: 'https://mockurl.com',
+ auditTrialDaysRemaining: 1,
+ });
+ render(undefined, { disclosureAcknowledged: true });
+ expect(screen.queryByTestId('sidebar-xpert')).toBeInTheDocument();
+
+ const trialEndsTodayMessage = screen.queryByTestId('trial-ends-today');
+ expect(trialEndsTodayMessage).toBeInTheDocument();
+ });
+
+ it('If auditTrialDaysRemaining < 1, do not show either of those', () => {
+ useCourseUpgrade.mockReturnValue({
+ upgradeable: true,
+ upgradeUrl: 'https://mockurl.com',
+ auditTrialDaysRemaining: 0,
+ });
+ 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();
+ });
});
describe('when it\'s not open', () => {
diff --git a/src/hooks/use-course-upgrade.js b/src/hooks/use-course-upgrade.js
index b78cbe4a..1c1a2b57 100644
--- a/src/hooks/use-course-upgrade.js
+++ b/src/hooks/use-course-upgrade.js
@@ -25,6 +25,7 @@ export default function useCourseUpgrade() {
auditTrialDaysRemaining = Math.ceil((auditTrialExpirationDate - Date.now()) / millisecondsInOneDay);
auditTrialExpired = auditTrialDaysRemaining < 0;
+ console.log({ upgradeUrl }, { auditTrialDaysRemaining });
}
return {