diff --git a/src/containers/CourseCard/components/Banners/CertificateBanner.jsx b/src/containers/CourseCard/components/Banners/CertificateBanner.jsx index 6e19b69..6054512 100644 --- a/src/containers/CourseCard/components/Banners/CertificateBanner.jsx +++ b/src/containers/CourseCard/components/Banners/CertificateBanner.jsx @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; import { Hyperlink } from '@edx/paragon'; import { CheckCircle } from '@edx/paragon/icons'; +// import { useIntl } from '@edx/frontend-platform/i18n'; import { selectors } from 'data/redux'; import Banner from 'components/Banner'; @@ -27,6 +28,9 @@ export const CertificateBanner = ({ courseNumber }) => { isVerified: cardData.isVerified, minPassingGrade: cardData.minPassingGrade, }); + + // const { formatMessage } = useIntl(); + if (data.isRestricted) { return ( diff --git a/src/containers/CourseCard/components/Banners/CourseBanner.jsx b/src/containers/CourseCard/components/Banners/CourseBanner.jsx index 8e54804..b34f283 100644 --- a/src/containers/CourseCard/components/Banners/CourseBanner.jsx +++ b/src/containers/CourseCard/components/Banners/CourseBanner.jsx @@ -2,13 +2,24 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Hyperlink } from '@edx/paragon'; +import { useIntl } from '@edx/frontend-platform/i18n'; +import { useCardValues } from 'hooks'; +import { selectors } from 'data/redux'; import Banner from 'components/Banner'; -import { useCourseBannerData } from './hooks'; import messages from './messages'; +const { cardData } = selectors; + export const CourseBanner = ({ courseNumber }) => { - const { courseData, formatMessage } = useCourseBannerData({ courseNumber }); + const courseData = useCardValues(courseNumber, { + isVerified: cardData.isVerified, + isCourseRunActive: cardData.isCourseRunActive, + canUpgrade: cardData.canUpgrade, + isAuditAccessExpired: cardData.isAuditAccessExpired, + courseWebsite: cardData.courseWebsite, + }); + const { formatMessage } = useIntl(); if (courseData.isVerified) { return null; } diff --git a/src/containers/CourseCard/components/Banners/CourseBanner.test.jsx b/src/containers/CourseCard/components/Banners/CourseBanner.test.jsx index f35e7da..3740718 100644 --- a/src/containers/CourseCard/components/Banners/CourseBanner.test.jsx +++ b/src/containers/CourseCard/components/Banners/CourseBanner.test.jsx @@ -2,20 +2,20 @@ import React from 'react'; import { shallow } from 'enzyme'; import { Hyperlink } from '@edx/paragon'; -import { formatMessage } from 'testUtils'; +import * as appHooks from 'hooks'; +import { testCardValues } from 'testUtils'; +import { selectors } from 'data/redux'; import { CourseBanner } from './CourseBanner'; -import * as hooks from './hooks'; import messages from './messages'; jest.mock('components/Banner', () => 'Banner'); -jest.mock('./hooks', () => ({ - useCourseBannerData: jest.fn(), -})); - +const { fieldKeys } = selectors.cardData; const courseNumber = 'my-test-course-number'; +let el; + const courseData = { isVerified: false, isCourseRunActive: false, @@ -24,20 +24,22 @@ const courseData = { courseWebsite: 'test-course-website', }; -let el; - -const render = (overrides) => { - hooks.useCourseBannerData.mockReturnValueOnce({ - courseData: { - ...courseData, - ...overrides, - }, - formatMessage, +const render = (overrides = {}) => { + appHooks.useCardValues.mockReturnValueOnce({ + ...courseData, + ...overrides, }); el = shallow(); }; describe('CourseBanner', () => { + testCardValues(courseNumber, { + isVerified: fieldKeys.isVerified, + isCourseRunActive: fieldKeys.isCourseRunActive, + canUpgrade: fieldKeys.canUpgrade, + isAuditAccessExpired: fieldKeys.isAuditAccessExpired, + courseWebsite: fieldKeys.courseWebsite, + }, render); test('no display if learner is verified', () => { render({ isVerified: true }); expect(el.isEmptyRender()).toEqual(true); diff --git a/src/containers/CourseCard/components/Banners/hooks.js b/src/containers/CourseCard/components/Banners/hooks.js deleted file mode 100644 index 413bc76..0000000 --- a/src/containers/CourseCard/components/Banners/hooks.js +++ /dev/null @@ -1,20 +0,0 @@ -import { useIntl } from '@edx/frontend-platform/i18n'; -import { useCardValues } from 'hooks'; -import { selectors } from 'data/redux'; - -const { cardData } = selectors; - -export const useCourseBannerData = ({ courseNumber }) => ({ - courseData: useCardValues(courseNumber, { - isVerified: cardData.isVerified, - isCourseRunActive: cardData.isCourseRunActive, - canUpgrade: cardData.canUpgrade, - isAuditAccessExpired: cardData.isAuditAccessExpired, - courseWebsite: cardData.courseWebsite, - }), - formatMessage: useIntl().formatMessage, -}); - -export default { - useCourseBannerData, -}; diff --git a/src/containers/CourseCard/components/Banners/hooks.test.js b/src/containers/CourseCard/components/Banners/hooks.test.js deleted file mode 100644 index 60c3ea1..0000000 --- a/src/containers/CourseCard/components/Banners/hooks.test.js +++ /dev/null @@ -1,39 +0,0 @@ -import { useIntl } from '@edx/frontend-platform/i18n'; - -import { selectors } from 'data/redux'; -import { testCardValues } from 'testUtils'; -import * as appHooks from 'hooks'; - -import * as hooks from './hooks'; - -const { fieldKeys } = selectors.cardData; - -const courseNumber = 'my-test-course-number'; - -describe('CourseCard banner hooks', () => { - let out; - const { formatMessage } = useIntl(); - describe('useCourseBannerData', () => { - const courseData = { - isVerified: false, - isCourseRunActive: false, - canUpgrade: false, - isAuditAcessExpired: false, - courseWebsite: 'test-course-website', - }; - beforeEach(() => { - appHooks.useCardValues.mockReturnValueOnce(courseData); - out = hooks.useCourseBannerData({ courseNumber }); - }); - testCardValues(courseNumber, { - isVerified: fieldKeys.isVerified, - isCourseRunActive: fieldKeys.isCourseRunActive, - canUpgrade: fieldKeys.canUpgrade, - isAuditAccessExpired: fieldKeys.isAuditAccessExpired, - courseWebsite: fieldKeys.courseWebsite, - }); - it('forwards formatMessage from useIntl', () => { - expect(out.formatMessage).toEqual(formatMessage); - }); - }); -}); diff --git a/src/containers/CourseCard/components/CourseCardActions/hooks.js b/src/containers/CourseCard/components/CourseCardActions/hooks.js index 2661f5a..df95e77 100644 --- a/src/containers/CourseCard/components/CourseCardActions/hooks.js +++ b/src/containers/CourseCard/components/CourseCardActions/hooks.js @@ -1,7 +1,8 @@ import { Locked } from '@edx/paragon/icons'; +import { useIntl } from '@edx/frontend-platform/i18n'; import { selectors } from 'data/redux'; -import { useIntl, useCardValues } from 'hooks'; +import { useCardValues } from 'hooks'; import messages from './messages'; const { cardData } = selectors; diff --git a/src/containers/CourseCard/components/CourseCardActions/hooks.test.js b/src/containers/CourseCard/components/CourseCardActions/hooks.test.js index 8b14c0c..17d7f6c 100644 --- a/src/containers/CourseCard/components/CourseCardActions/hooks.test.js +++ b/src/containers/CourseCard/components/CourseCardActions/hooks.test.js @@ -1,4 +1,5 @@ import { Locked } from '@edx/paragon/icons'; +import { useIntl } from '@edx/frontend-platform/i18n'; import { selectors } from 'data/redux'; @@ -22,7 +23,7 @@ const props = { describe('CourseCardActions hooks', () => { let out; - const { formatMessage } = appHooks.useIntl(); + const { formatMessage } = useIntl(); describe('data connection', () => { beforeEach(() => { out = hooks.useCardActionData({ courseNumber }); diff --git a/src/containers/CourseCard/hooks.js b/src/containers/CourseCard/hooks.js index 94344c5..42d9591 100644 --- a/src/containers/CourseCard/hooks.js +++ b/src/containers/CourseCard/hooks.js @@ -1,6 +1,7 @@ +import { useIntl } from '@edx/frontend-platform/i18n'; import { selectors } from 'data/redux'; -import { useIntl, useCardValues } from 'hooks'; +import { useCardValues } from 'hooks'; import * as module from './hooks'; import messages from './messages'; diff --git a/src/containers/CourseCard/hooks.test.js b/src/containers/CourseCard/hooks.test.js index 86345ad..f367018 100644 --- a/src/containers/CourseCard/hooks.test.js +++ b/src/containers/CourseCard/hooks.test.js @@ -1,3 +1,5 @@ +import { useIntl } from '@edx/frontend-platform/i18n'; + import { keyStore } from 'utils'; import { selectors } from 'data/redux'; import * as appHooks from 'hooks'; @@ -15,7 +17,7 @@ const hookKeys = keyStore(hooks); describe('CourseCard hooks', () => { let out; - const { formatMessage, formatDate } = appHooks.useIntl(); + const { formatMessage, formatDate } = useIntl(); describe('useCardData', () => { beforeEach(() => { jest.spyOn(hooks, hookKeys.useAccessMessage).mockImplementationOnce(mockAccessMessage); diff --git a/src/containers/EmailSettingsModal/__snapshots__/index.test.jsx.snap b/src/containers/EmailSettingsModal/__snapshots__/index.test.jsx.snap index e9b5224..d3ee4d0 100644 --- a/src/containers/EmailSettingsModal/__snapshots__/index.test.jsx.snap +++ b/src/containers/EmailSettingsModal/__snapshots__/index.test.jsx.snap @@ -16,38 +16,28 @@ exports[`EmailSettingsModal render snapshot: emails disabled, show: false 1`] = } >

- + Receive course emails?

- + Course emails are on

- + Course emailsi include important information about your course.

@@ -70,38 +60,28 @@ exports[`EmailSettingsModal render snapshot: emails disabled, show: true 1`] = ` } >

- + Receive course emails?

- + Course emails are on

- + Course emailsi include important information about your course.

@@ -124,38 +104,28 @@ exports[`EmailSettingsModal render snapshot: emails enabled, show: true 1`] = ` } >

- + Receive course emails?

- + Course emails are off

- + Course emailsi include important information about your course.

diff --git a/src/containers/RelatedProgramsModal/__snapshots__/index.test.jsx.snap b/src/containers/RelatedProgramsModal/__snapshots__/index.test.jsx.snap index afaae12..fbe554c 100644 --- a/src/containers/RelatedProgramsModal/__snapshots__/index.test.jsx.snap +++ b/src/containers/RelatedProgramsModal/__snapshots__/index.test.jsx.snap @@ -9,19 +9,13 @@ exports[`RelatedProgramsModal snapshot: closed 1`] = ` isOpen={false} onClose={[MockFunction props.closeModal]} size="lg" - title={ - - } + title="Related Programs" > - + Related Programs

- + Are you looking to expand your knowledge? Enrolling in a Program lets you take a series of courses in the subject that you're interested in

- } + title="Related Programs" > - + Related Programs

- + Are you looking to expand your knowledge? Enrolling in a Program lets you take a series of courses in the subject that you're interested in

- } + logoAlt="Provider logo" logoSrc="props.data.logoUrl" src="props.data.bannerUrl" - srcAlt={ - - } + srcAlt="Programm banner" /> - + 2 Courses • - + 1 Weeks diff --git a/src/containers/UnenrollConfirmModal/components/__snapshots__/ConfirmPane.test.jsx.snap b/src/containers/UnenrollConfirmModal/components/__snapshots__/ConfirmPane.test.jsx.snap index 4706b8d..35cd180 100644 --- a/src/containers/UnenrollConfirmModal/components/__snapshots__/ConfirmPane.test.jsx.snap +++ b/src/containers/UnenrollConfirmModal/components/__snapshots__/ConfirmPane.test.jsx.snap @@ -3,30 +3,22 @@ exports[`UnenrollConfirmModal ConfirmPane snapshot 1`] = `

- + Unenroll from course?

- + Progress that you've made so far will not be saved

diff --git a/src/containers/UnenrollConfirmModal/components/__snapshots__/FinishedPane.test.jsx.snap b/src/containers/UnenrollConfirmModal/components/__snapshots__/FinishedPane.test.jsx.snap index 8015b6a..88a0dd1 100644 --- a/src/containers/UnenrollConfirmModal/components/__snapshots__/FinishedPane.test.jsx.snap +++ b/src/containers/UnenrollConfirmModal/components/__snapshots__/FinishedPane.test.jsx.snap @@ -3,22 +3,16 @@ exports[`UnenrollConfirmModal FinishedPane snapshot: did not give reason 1`] = `

- + You are unenrolled

- + This course will be removed from your dashboard.

@@ -27,25 +21,17 @@ exports[`UnenrollConfirmModal FinishedPane snapshot: did not give reason 1`] = ` exports[`UnenrollConfirmModal FinishedPane snapshot: gave reason 1`] = `

- + You are unenrolled

- - + Thank you for sharing your reason for unenrolling. + This course will be removed from your dashboard.

diff --git a/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap b/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap index 2490718..87a1821 100644 --- a/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap +++ b/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap @@ -3,9 +3,7 @@ exports[`UnenrollConfirmModal ReasonPane snapshot 1`] = `

- + What's your main reason for unenrolling?

- + I don't have the academic or language prerequisites - + The course material was too hard - + This won't help me reach my goals - + Something was broken - + I don't have the time - + I just wanted to browse the material - + I don't have enough support - + I am not happy with the quality of the content - + The course material was too easy - } + placeholder="Other" value="props.reason.customOption.value" /> @@ -103,16 +79,12 @@ exports[`UnenrollConfirmModal ReasonPane snapshot 1`] = ` onClick={[MockFunction props.reason.skip]} variant="tertiary" > - + Skip
diff --git a/src/setupTest.jsx b/src/setupTest.jsx index da0b932..e88ac35 100755 --- a/src/setupTest.jsx +++ b/src/setupTest.jsx @@ -18,12 +18,7 @@ jest.mock('react', () => ({ jest.mock('@edx/frontend-platform/i18n', () => { const i18n = jest.requireActual('@edx/frontend-platform/i18n'); const PropTypes = jest.requireActual('prop-types'); - const formatMessage = jest.fn((msg) => ( - - )); + const { formatMessage } = jest.requireActual('./testUtils'); const formatDate = jest.fn().mockName('useIntl.formatDate'); return { ...i18n, diff --git a/src/testUtils.js b/src/testUtils.js index d2863fc..04a6237 100644 --- a/src/testUtils.js +++ b/src/testUtils.js @@ -200,9 +200,13 @@ export class MockUseState { * Test that useCardValues was called with the given courseNumber and selector mapping. * @param {string} courseNumber - course run identifier * @param {obj} mapping - value mapping { : } + * @param {[func]} beforeEachFn - optional beforeEach method */ -export const testCardValues = (courseNumber, mapping) => { +export const testCardValues = (courseNumber, mapping, beforeEachFn) => { describe('cardData values', () => { + if (beforeEachFn) { + beforeEach(beforeEachFn); + } let mapped; test('passess correct courseNumber', () => { expect(appHooks.useCardValues.mock.calls[0][0]).toEqual(courseNumber);