@openedx/frontend-app-learner-dashboard 1.0.0-alpha.4 → 1.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/package.json +4 -5
  2. package/src/app.scss +2 -5
  3. package/src/components/Banner.test.jsx +21 -21
  4. package/src/containers/CourseCard/CourseCard.scss +4 -6
  5. package/src/containers/CourseCard/components/CourseCardActions/ActionButton/hooks.test.js +27 -0
  6. package/src/containers/CourseCard/components/CourseCardActions/ActionButton/index.test.jsx +17 -14
  7. package/src/containers/CourseCard/components/CourseCardActions/BeginCourseButton.test.jsx +37 -34
  8. package/src/containers/CourseCard/components/CourseCardActions/ResumeButton.test.jsx +28 -28
  9. package/src/containers/CourseCard/components/CourseCardActions/SelectSessionButton.test.jsx +26 -17
  10. package/src/containers/CourseCard/components/CourseCardActions/ViewCourseButton.test.jsx +29 -19
  11. package/src/containers/CourseCard/components/CourseCardActions/index.test.jsx +32 -34
  12. package/src/containers/CourseCard/components/CourseCardBanners/CertificateBanner.test.jsx +205 -190
  13. package/src/containers/CourseCard/components/CourseCardBanners/CourseBanner.test.jsx +35 -62
  14. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/hooks.test.js +3 -3
  15. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/index.test.jsx +49 -79
  16. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/ApprovedContent.jsx +1 -2
  17. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/ApprovedContent.test.jsx +51 -34
  18. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/EligibleContent.test.jsx +36 -44
  19. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/MustRequestContent.jsx +1 -2
  20. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/MustRequestContent.test.jsx +74 -44
  21. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/PendingContent.jsx +1 -2
  22. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/PendingContent.test.jsx +40 -34
  23. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/RejectedContent.test.jsx +16 -26
  24. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/components/CreditContent.test.jsx +38 -28
  25. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/components/CreditRequestForm/hooks.test.js +6 -0
  26. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/components/CreditRequestForm/index.test.jsx +25 -24
  27. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/components/CreditRequestForm/ref.test.jsx +0 -3
  28. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/components/ProviderLink.test.jsx +15 -13
  29. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/hooks.test.js +3 -3
  30. package/src/containers/CourseCard/components/CourseCardBanners/EntitlementBanner.test.jsx +33 -24
  31. package/src/containers/CourseCard/components/CourseCardBanners/RelatedProgramsBanner/ProgramsList.test.jsx +13 -5
  32. package/src/containers/CourseCard/components/CourseCardBanners/RelatedProgramsBanner/index.test.jsx +34 -27
  33. package/src/containers/CourseCard/components/CourseCardBanners/index.test.jsx +44 -15
  34. package/src/containers/CourseCard/components/CourseCardDetails/hooks.test.js +19 -9
  35. package/src/containers/CourseCard/components/CourseCardDetails/index.scss +1 -5
  36. package/src/containers/CourseCard/components/CourseCardDetails/index.test.jsx +20 -8
  37. package/src/containers/CourseCard/components/CourseCardImage.test.jsx +48 -41
  38. package/src/containers/CourseCard/components/CourseCardMenu/SocialShareMenu.jsx +3 -4
  39. package/src/containers/CourseCard/components/CourseCardMenu/SocialShareMenu.test.jsx +62 -92
  40. package/src/containers/CourseCard/components/CourseCardMenu/hooks.js +8 -7
  41. package/src/containers/CourseCard/components/CourseCardMenu/hooks.test.js +8 -15
  42. package/src/containers/CourseCard/components/CourseCardMenu/index.jsx +2 -3
  43. package/src/containers/CourseCard/components/CourseCardMenu/index.test.jsx +78 -112
  44. package/src/containers/CourseCard/components/CourseCardTitle.test.jsx +51 -45
  45. package/src/containers/CourseCard/components/RelatedProgramsBadge/hooks.jsx +2 -2
  46. package/src/containers/CourseCard/components/RelatedProgramsBadge/hooks.test.js +18 -4
  47. package/src/containers/CourseCard/components/RelatedProgramsBadge/index.jsx +1 -1
  48. package/src/containers/CourseCard/components/RelatedProgramsBadge/index.test.jsx +17 -13
  49. package/src/containers/CourseCard/components/hooks.test.js +19 -8
  50. package/src/containers/CourseCard/hooks.test.js +12 -2
  51. package/src/containers/CourseCard/index.test.jsx +33 -12
  52. package/src/containers/CourseFilterControls/ActiveCourseFilters.test.jsx +19 -8
  53. package/src/containers/CourseFilterControls/CourseFilterControls.test.jsx +51 -36
  54. package/src/containers/CourseFilterControls/components/Checkbox.test.jsx +8 -5
  55. package/src/containers/CourseFilterControls/components/FilterForm.test.jsx +45 -20
  56. package/src/containers/CourseFilterControls/components/SortForm.test.jsx +19 -9
  57. package/src/containers/CourseFilterControls/hooks.test.js +25 -13
  58. package/src/containers/CoursesPanel/CourseList/index.test.jsx +39 -22
  59. package/src/containers/CoursesPanel/NoCoursesView/index.scss +5 -7
  60. package/src/containers/CoursesPanel/NoCoursesView/index.test.jsx +26 -6
  61. package/src/containers/CoursesPanel/hooks.test.js +4 -4
  62. package/src/containers/CoursesPanel/index.scss +5 -7
  63. package/src/containers/CoursesPanel/index.test.jsx +55 -21
  64. package/src/containers/Dashboard/DashboardLayout.test.jsx +43 -52
  65. package/src/containers/Dashboard/LoadingView.test.jsx +5 -10
  66. package/src/containers/Dashboard/hooks.test.js +21 -19
  67. package/src/containers/Dashboard/index.scss +8 -10
  68. package/src/containers/Dashboard/index.test.jsx +51 -92
  69. package/src/containers/EmailSettingsModal/hooks.test.js +3 -3
  70. package/src/containers/EmailSettingsModal/index.test.jsx +27 -10
  71. package/src/containers/RelatedProgramsModal/components/ProgramCard.test.jsx +31 -11
  72. package/src/containers/RelatedProgramsModal/index.test.jsx +27 -15
  73. package/src/containers/SelectSessionModal/constants.js +0 -1
  74. package/src/containers/SelectSessionModal/hooks.test.js +15 -5
  75. package/src/containers/SelectSessionModal/index.test.jsx +24 -11
  76. package/src/containers/UnenrollConfirmModal/components/ConfirmPane.test.jsx +24 -8
  77. package/src/containers/UnenrollConfirmModal/components/FinishedPane.test.jsx +39 -14
  78. package/src/containers/UnenrollConfirmModal/components/ReasonPane.test.jsx +23 -6
  79. package/src/containers/UnenrollConfirmModal/hooks/index.test.js +74 -26
  80. package/src/containers/UnenrollConfirmModal/hooks/reasons.test.js +4 -4
  81. package/src/containers/UnenrollConfirmModal/index.test.jsx +34 -17
  82. package/src/data/constants/app.js +0 -3
  83. package/src/data/constants/app.test.js +0 -12
  84. package/src/data/redux/app/selectors/courseCard.test.js +4 -4
  85. package/src/data/redux/app/selectors/currentList.test.js +5 -3
  86. package/src/data/redux/app/selectors/simpleSelectors.test.js +1 -1
  87. package/src/data/redux/requests/reducer.test.js +1 -1
  88. package/src/data/redux/requests/selectors.js +1 -2
  89. package/src/data/redux/requests/selectors.test.js +1 -29
  90. package/src/data/services/lms/api.test.js +6 -6
  91. package/src/data/services/lms/urls.test.js +1 -1
  92. package/src/data/services/segment/utils.test.js +1 -1
  93. package/src/data/store.test.js +2 -2
  94. package/src/hooks/api.test.js +59 -64
  95. package/src/hooks/utils.test.js +4 -0
  96. package/src/segment.js +1 -2
  97. package/src/setupTest.jsx +0 -206
  98. package/src/slots/WidgetSidebarSlot/index.test.jsx +21 -11
  99. package/src/test/app.test.jsx +65 -75
  100. package/src/test/inspector.js +0 -6
  101. package/src/test/messages.js +1 -1
  102. package/src/testUtils.js +1 -1
  103. package/src/tracking/trackers/course.test.js +4 -4
  104. package/src/tracking/trackers/credit.test.js +5 -5
  105. package/src/tracking/trackers/engagement.test.js +3 -3
  106. package/src/tracking/trackers/entitlements.test.js +3 -3
  107. package/src/tracking/trackers/filter.test.js +3 -3
  108. package/src/tracking/trackers/findCourses.test.js +3 -3
  109. package/src/tracking/trackers/socialShare.test.js +2 -2
  110. package/src/utils/StrictDict.test.js +4 -12
  111. package/src/widgets/LearnerDashboardHeader/ConfirmEmailBanner/messages.js +1 -1
  112. package/src/widgets/LearnerDashboardHeader/MasqueradeBar/index.scss +10 -12
  113. package/src/widgets/LearnerDashboardHeader/hooks.js +1 -1
  114. package/src/widgets/LookingForChallengeWidget/index.test.jsx +22 -8
  115. package/src/__snapshots__/App.test.jsx.snap +0 -83
  116. package/src/__snapshots__/index.test.jsx.snap +0 -43
  117. package/src/components/__snapshots__/Banner.test.jsx.snap +0 -31
  118. package/src/containers/CourseCard/__snapshots__/index.test.jsx.snap +0 -111
  119. package/src/containers/CourseCard/components/CourseCardActions/ActionButton/__snapshots__/index.test.jsx.snap +0 -14
  120. package/src/containers/CourseCard/components/CourseCardActions/__snapshots__/BeginCourseButton.test.jsx.snap +0 -39
  121. package/src/containers/CourseCard/components/CourseCardActions/__snapshots__/ResumeButton.test.jsx.snap +0 -39
  122. package/src/containers/CourseCard/components/CourseCardActions/__snapshots__/SelectSessionButton.test.jsx.snap +0 -19
  123. package/src/containers/CourseCard/components/CourseCardActions/__snapshots__/ViewCourseButton.test.jsx.snap +0 -39
  124. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/__snapshots__/index.test.jsx.snap +0 -58
  125. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/components/CreditRequestForm/__snapshots__/index.test.jsx.snap +0 -32
  126. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/components/__snapshots__/CreditContent.test.jsx.snap +0 -60
  127. package/src/containers/CourseCard/components/CourseCardBanners/CreditBanner/views/components/__snapshots__/ProviderLink.test.jsx.snap +0 -11
  128. package/src/containers/CourseCard/components/CourseCardBanners/RelatedProgramsBanner/__snapshots__/ProgramsList.test.jsx.snap +0 -28
  129. package/src/containers/CourseCard/components/CourseCardBanners/RelatedProgramsBanner/__snapshots__/index.test.jsx.snap +0 -29
  130. package/src/containers/CourseCard/components/CourseCardBanners/__snapshots__/CertificateBanner.test.jsx.snap +0 -205
  131. package/src/containers/CourseCard/components/CourseCardBanners/__snapshots__/CourseBanner.test.jsx.snap +0 -38
  132. package/src/containers/CourseCard/components/CourseCardBanners/__snapshots__/EntitlementBanner.test.jsx.snap +0 -53
  133. package/src/containers/CourseCard/components/CourseCardBanners/__snapshots__/index.test.jsx.snap +0 -41
  134. package/src/containers/CourseCard/components/CourseCardDetails/__snapshots__/index.test.jsx.snap +0 -56
  135. package/src/containers/CourseCard/components/CourseCardMenu/__snapshots__/index.test.jsx.snap +0 -81
  136. package/src/containers/CourseCard/components/RelatedProgramsBadge/__snapshots__/index.test.jsx.snap +0 -25
  137. package/src/containers/CourseCard/components/__snapshots__/CourseCardImage.test.jsx.snap +0 -72
  138. package/src/containers/CourseCard/components/__snapshots__/CourseCardTitle.test.jsx.snap +0 -33
  139. package/src/containers/CourseFilterControls/__snapshots__/ActiveCourseFilters.test.jsx.snap +0 -39
  140. package/src/containers/CourseFilterControls/__snapshots__/CourseFilterControls.test.jsx.snap +0 -169
  141. package/src/containers/CourseFilterControls/components/__snapshots__/Checkbox.test.jsx.snap +0 -46
  142. package/src/containers/CourseFilterControls/components/__snapshots__/FilterForm.test.jsx.snap +0 -41
  143. package/src/containers/CourseFilterControls/components/__snapshots__/SortForm.test.jsx.snap +0 -29
  144. package/src/containers/CoursesPanel/CourseList/__snapshots__/index.test.jsx.snap +0 -70
  145. package/src/containers/CoursesPanel/NoCoursesView/__snapshots__/index.test.jsx.snap +0 -29
  146. package/src/containers/CoursesPanel/__snapshots__/index.test.jsx.snap +0 -55
  147. package/src/containers/Dashboard/__snapshots__/DashboardLayout.test.jsx.snap +0 -197
  148. package/src/containers/Dashboard/__snapshots__/LoadingView.test.jsx.snap +0 -13
  149. package/src/containers/Dashboard/__snapshots__/index.test.jsx.snap +0 -69
  150. package/src/containers/EmailSettingsModal/__snapshots__/index.test.jsx.snap +0 -133
  151. package/src/containers/RelatedProgramsModal/__snapshots__/index.test.jsx.snap +0 -169
  152. package/src/containers/RelatedProgramsModal/components/__snapshots__/ProgramCard.test.jsx.snap +0 -60
  153. package/src/containers/SelectSessionModal/__snapshots__/index.test.jsx.snap +0 -176
  154. package/src/containers/UnenrollConfirmModal/__snapshots__/index.test.jsx.snap +0 -101
  155. package/src/containers/UnenrollConfirmModal/components/__snapshots__/ConfirmPane.test.jsx.snap +0 -22
  156. package/src/containers/UnenrollConfirmModal/components/__snapshots__/FinishedPane.test.jsx.snap +0 -38
  157. package/src/containers/UnenrollConfirmModal/components/__snapshots__/ReasonPane.test.jsx.snap +0 -183
  158. package/src/slots/WidgetSidebarSlot/__snapshots__/index.test.jsx.snap +0 -14
  159. package/src/widgets/LookingForChallengeWidget/__snapshots__/index.test.jsx.snap +0 -45
@@ -1,16 +1,9 @@
1
- import { shallow } from '@edx/react-unit-test-utils';
2
-
3
- import { reduxHooks } from 'hooks';
4
-
5
- import CourseCardActionSlot from 'slots/CourseCardActionSlot';
6
- import SelectSessionButton from './SelectSessionButton';
7
- import BeginCourseButton from './BeginCourseButton';
8
- import ResumeButton from './ResumeButton';
9
- import ViewCourseButton from './ViewCourseButton';
1
+ import { render, screen } from '@testing-library/react';
2
+ import { reduxHooks } from '@src/hooks';
10
3
 
11
4
  import CourseCardActions from '.';
12
5
 
13
- jest.mock('hooks', () => ({
6
+ jest.mock('@src/hooks', () => ({
14
7
  reduxHooks: {
15
8
  useCardCourseRunData: jest.fn(),
16
9
  useCardEnrollmentData: jest.fn(),
@@ -19,16 +12,15 @@ jest.mock('hooks', () => ({
19
12
  },
20
13
  }));
21
14
 
22
- jest.mock('slots/CourseCardActionSlot', () => 'CustomActionButton');
23
- jest.mock('./SelectSessionButton', () => 'SelectSessionButton');
24
- jest.mock('./ViewCourseButton', () => 'ViewCourseButton');
25
- jest.mock('./BeginCourseButton', () => 'BeginCourseButton');
26
- jest.mock('./ResumeButton', () => 'ResumeButton');
15
+ jest.mock('@src/slots/CourseCardActionSlot', () => jest.fn(() => <div>CourseCardActionSlot</div>));
16
+ jest.mock('./SelectSessionButton', () => jest.fn(() => <div>SelectSessionButton</div>));
17
+ jest.mock('./ViewCourseButton', () => jest.fn(() => <div>ViewCourseButton</div>));
18
+ jest.mock('./BeginCourseButton', () => jest.fn(() => <div>BeginCourseButton</div>));
19
+ jest.mock('./ResumeButton', () => jest.fn(() => <div>ResumeButton</div>));
27
20
 
28
21
  const cardId = 'test-card-id';
29
22
  const props = { cardId };
30
23
 
31
- let el;
32
24
  describe('CourseCardActions', () => {
33
25
  const mockHooks = ({
34
26
  isEntitlement = false,
@@ -44,13 +36,11 @@ describe('CourseCardActions', () => {
44
36
  reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ isExecEd2UCourse, isVerified, hasStarted });
45
37
  reduxHooks.useMasqueradeData.mockReturnValueOnce({ isMasquerading });
46
38
  };
47
- const render = () => {
48
- el = shallow(<CourseCardActions {...props} />);
49
- };
50
- describe('behavior', () => {
39
+ const renderComponent = () => render(<CourseCardActions {...props} />);
40
+ describe('hooks', () => {
51
41
  it('initializes redux hooks', () => {
52
42
  mockHooks();
53
- render();
43
+ renderComponent();
54
44
  expect(reduxHooks.useCardEntitlementData).toHaveBeenCalledWith(cardId);
55
45
  expect(reduxHooks.useCardEnrollmentData).toHaveBeenCalledWith(cardId);
56
46
  expect(reduxHooks.useCardCourseRunData).toHaveBeenCalledWith(cardId);
@@ -60,36 +50,44 @@ describe('CourseCardActions', () => {
60
50
  describe('entitlement course', () => {
61
51
  it('renders ViewCourseButton if fulfilled', () => {
62
52
  mockHooks({ isEntitlement: true, isFulfilled: true });
63
- render();
64
- expect(el.instance.findByType(ViewCourseButton)[0].props.cardId).toEqual(cardId);
53
+ renderComponent();
54
+ const ViewCourseButton = screen.getByText('ViewCourseButton');
55
+ expect(ViewCourseButton).toBeInTheDocument();
65
56
  });
66
57
  it('renders SelectSessionButton if not fulfilled', () => {
67
58
  mockHooks({ isEntitlement: true });
68
- render();
69
- expect(el.instance.findByType(SelectSessionButton)[0].props.cardId).toEqual(cardId);
59
+ renderComponent();
60
+ const SelectSessionButton = screen.getByText('SelectSessionButton');
61
+ expect(SelectSessionButton).toBeInTheDocument();
70
62
  });
71
63
  });
72
64
  describe('not entitlement, verified, or exec ed', () => {
73
65
  it('renders CourseCardActionSlot and ViewCourseButton for archived courses', () => {
74
66
  mockHooks({ isArchived: true });
75
- render();
76
- expect(el.instance.findByType(CourseCardActionSlot)[0].props.cardId).toEqual(cardId);
77
- expect(el.instance.findByType(ViewCourseButton)[0].props.cardId).toEqual(cardId);
67
+ renderComponent();
68
+ const CourseCardActionSlot = screen.getByText('CourseCardActionSlot');
69
+ expect(CourseCardActionSlot).toBeInTheDocument();
70
+ const ViewCourseButton = screen.getByText('ViewCourseButton');
71
+ expect(ViewCourseButton).toBeInTheDocument();
78
72
  });
79
73
  describe('unstarted courses', () => {
80
74
  it('renders CourseCardActionSlot and BeginCourseButton', () => {
81
75
  mockHooks();
82
- render();
83
- expect(el.instance.findByType(CourseCardActionSlot)[0].props.cardId).toEqual(cardId);
84
- expect(el.instance.findByType(BeginCourseButton)[0].props.cardId).toEqual(cardId);
76
+ renderComponent();
77
+ const CourseCardActionSlot = screen.getByText('CourseCardActionSlot');
78
+ expect(CourseCardActionSlot).toBeInTheDocument();
79
+ const BeginCourseButton = screen.getByText('BeginCourseButton');
80
+ expect(BeginCourseButton).toBeInTheDocument();
85
81
  });
86
82
  });
87
83
  describe('active courses (started, and not archived)', () => {
88
84
  it('renders CourseCardActionSlot and ResumeButton', () => {
89
85
  mockHooks({ hasStarted: true });
90
- render();
91
- expect(el.instance.findByType(CourseCardActionSlot)[0].props.cardId).toEqual(cardId);
92
- expect(el.instance.findByType(ResumeButton)[0].props.cardId).toEqual(cardId);
86
+ renderComponent();
87
+ const CourseCardActionSlot = screen.getByText('CourseCardActionSlot');
88
+ expect(CourseCardActionSlot).toBeInTheDocument();
89
+ const ResumeButton = screen.getByText('ResumeButton');
90
+ expect(ResumeButton).toBeInTheDocument();
93
91
  });
94
92
  });
95
93
  });
@@ -1,10 +1,10 @@
1
- import { shallow } from '@edx/react-unit-test-utils';
1
+ import { render, screen } from '@testing-library/react';
2
+ import { IntlProvider } from '@openedx/frontend-base';
2
3
 
3
- import { reduxHooks } from 'hooks';
4
+ import { reduxHooks } from '@src/hooks';
4
5
  import CertificateBanner from './CertificateBanner';
5
- import messages from './messages';
6
6
 
7
- jest.mock('hooks', () => ({
7
+ jest.mock('@src/hooks', () => ({
8
8
  utilHooks: {
9
9
  useFormatDate: jest.fn(() => date => date),
10
10
  },
@@ -17,28 +17,28 @@ jest.mock('hooks', () => ({
17
17
  },
18
18
  }));
19
19
 
20
- jest.mock('components/Banner', () => 'Banner');
20
+ const defaultCertificate = {
21
+ availableDate: '10/20/3030',
22
+ isRestricted: false,
23
+ isDownloadable: false,
24
+ isEarnedButUnavailable: false,
25
+ };
26
+ const defaultEnrollment = {
27
+ isAudit: false,
28
+ isVerified: false,
29
+ };
30
+ const defaultCourseRun = { isArchived: false };
31
+ const defaultGrade = { isPassing: false };
32
+ const defaultPlatformSettings = {};
33
+ const props = { cardId: 'cardId' };
34
+ const supportEmail = 'suport@email.com';
35
+ const billingEmail = 'billing@email.com';
21
36
 
22
37
  describe('CertificateBanner', () => {
23
- const props = { cardId: 'cardId' };
24
38
  reduxHooks.useCardCourseRunData.mockReturnValue({
25
39
  minPassingGrade: 0.8,
26
40
  progressUrl: 'progressUrl',
27
41
  });
28
-
29
- const defaultCertificate = {
30
- availableDate: '10/20/3030',
31
- isRestricted: false,
32
- isDownloadable: false,
33
- isEarnedButUnavailable: false,
34
- };
35
- const defaultEnrollment = {
36
- isAudit: false,
37
- isVerified: false,
38
- };
39
- const defaultCourseRun = { isArchived: false };
40
- const defaultGrade = { isPassing: false };
41
- const defaultPlatformSettings = {};
42
42
  const createWrapper = ({
43
43
  certificate = {},
44
44
  enrollment = {},
@@ -51,177 +51,192 @@ describe('CertificateBanner', () => {
51
51
  reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ ...defaultEnrollment, ...enrollment });
52
52
  reduxHooks.useCardCourseRunData.mockReturnValueOnce({ ...defaultCourseRun, ...courseRun });
53
53
  reduxHooks.usePlatformSettingsData.mockReturnValueOnce({ ...defaultPlatformSettings, ...platformSettings });
54
- return shallow(<CertificateBanner {...props} />);
54
+ return render(<IntlProvider locale="en"><CertificateBanner {...props} /></IntlProvider>);
55
55
  };
56
- /** TODO: Update tests to validate snapshots **/
57
- describe('snapshot', () => {
58
- test('is restricted', () => {
59
- const wrapper = createWrapper({
60
- certificate: {
61
- isRestricted: true,
62
- },
63
- });
64
- expect(wrapper.snapshot).toMatchSnapshot();
65
- });
66
- test('is restricted with support email', () => {
67
- const wrapper = createWrapper({
68
- certificate: {
69
- isRestricted: true,
70
- },
71
- platformSettings: {
72
- supportEmail: 'suport@email',
73
- },
74
- });
75
- expect(wrapper.snapshot).toMatchSnapshot();
76
- });
77
- test('is restricted with billing email', () => {
78
- const wrapper = createWrapper({
79
- certificate: {
80
- isRestricted: true,
81
- },
82
- platformSettings: {
83
- billingEmail: 'billing@email',
84
- },
85
- });
86
- expect(wrapper.snapshot).toMatchSnapshot();
87
- });
88
- test('is restricted and verified', () => {
89
- const wrapper = createWrapper({
90
- certificate: {
91
- isRestricted: true,
92
- },
93
- enrollment: {
94
- isVerified: true,
95
- },
96
- });
97
- expect(wrapper.snapshot).toMatchSnapshot();
98
- });
99
- test('is restricted and verified with support email', () => {
100
- const wrapper = createWrapper({
101
- certificate: {
102
- isRestricted: true,
103
- },
104
- enrollment: {
105
- isVerified: true,
106
- },
107
- platformSettings: {
108
- supportEmail: 'suport@email',
109
- },
110
- });
111
- expect(wrapper.snapshot).toMatchSnapshot();
112
- });
113
- test('is restricted and verified with billing email', () => {
114
- const wrapper = createWrapper({
115
- certificate: {
116
- isRestricted: true,
117
- },
118
- enrollment: {
119
- isVerified: true,
120
- },
121
- platformSettings: {
122
- billingEmail: 'billing@email',
123
- },
124
- });
125
- expect(wrapper.snapshot).toMatchSnapshot();
126
- });
127
- test('is restricted and verified with support and billing email', () => {
128
- const wrapper = createWrapper({
129
- certificate: {
130
- isRestricted: true,
131
- },
132
- enrollment: {
133
- isVerified: true,
134
- },
135
- platformSettings: {
136
- supportEmail: 'suport@email',
137
- billingEmail: 'billing@email',
138
- },
139
- });
140
- expect(wrapper.snapshot).toMatchSnapshot();
141
- });
142
- test('is passing and is downloadable', () => {
143
- const wrapper = createWrapper({
144
- grade: { isPassing: true },
145
- certificate: { isDownloadable: true },
146
- });
147
- expect(wrapper.snapshot).toMatchSnapshot();
148
- });
149
- test('not passing and is downloadable', () => {
150
- const wrapper = createWrapper({
151
- grade: { isPassing: false },
152
- certificate: { isDownloadable: true },
153
- });
154
- expect(wrapper.snapshot).toMatchSnapshot();
155
- });
156
- test('not passing and audit', () => {
157
- const wrapper = createWrapper({
158
- enrollment: {
159
- isAudit: true,
160
- },
161
- });
162
- expect(wrapper.snapshot).toMatchSnapshot();
163
- });
164
- test('not passing and has finished', () => {
165
- const wrapper = createWrapper({
166
- courseRun: { isArchived: true },
167
- });
168
- expect(wrapper.snapshot).toMatchSnapshot();
169
- });
170
- test('not passing and not audit and not finished', () => {
171
- const wrapper = createWrapper({});
172
- expect(wrapper.snapshot).toMatchSnapshot();
173
- });
174
- test('is passing and is earned but unavailable', () => {
175
- const wrapper = createWrapper({
176
- grade: {
177
- isPassing: true,
178
- },
179
- certificate: {
180
- isEarnedButUnavailable: true,
181
- },
182
- });
183
- expect(wrapper.snapshot).toMatchSnapshot();
184
- });
185
- test('is passing and not downloadable render empty', () => {
186
- const wrapper = createWrapper({
187
- grade: {
188
- isPassing: true,
189
- },
190
- });
191
- expect(wrapper.snapshot).toMatchSnapshot();
192
- });
56
+ beforeEach(() => {
57
+ jest.clearAllMocks();
193
58
  });
194
- describe('behavior', () => {
195
- it('is restricted', () => {
196
- const wrapper = createWrapper({
197
- certificate: {
198
- isRestricted: true,
199
- },
200
- platformSettings: {
201
- supportEmail: 'suport@email',
202
- billingEmail: 'billing@email',
203
- },
204
- });
205
- const bannerMessage = wrapper.instance.findByType('format-message-function').map(el => el.props.message.defaultMessage).join('\n');
206
- expect(bannerMessage).toEqual(messages.certRestricted.defaultMessage);
207
- expect(bannerMessage).toContain(messages.certRestricted.defaultMessage);
208
- });
209
- it('is restricted and verified', () => {
210
- const wrapper = createWrapper({
211
- certificate: {
212
- isRestricted: true,
213
- },
214
- enrollment: {
215
- isVerified: true,
216
- },
217
- platformSettings: {
218
- supportEmail: 'suport@email',
219
- billingEmail: 'billing@email',
220
- },
221
- });
222
- const bannerMessage = wrapper.instance.findByType('format-message-function').map(el => el.props.message.defaultMessage).join('\n');
223
- expect(bannerMessage).toContain(messages.certRestricted.defaultMessage);
224
- expect(bannerMessage).toContain(messages.certRefundContactBilling.defaultMessage);
225
- });
59
+ it('is restricted', () => {
60
+ createWrapper({
61
+ certificate: {
62
+ isRestricted: true,
63
+ },
64
+ });
65
+ const banner = screen.getByRole('alert');
66
+ expect(banner).toBeInTheDocument();
67
+ const msg = screen.getByText((text) => text.includes('please let us know.'));
68
+ expect(msg).toBeInTheDocument();
69
+ expect(msg).not.toContain(supportEmail);
70
+ });
71
+ it('is restricted with support email', () => {
72
+ createWrapper({
73
+ certificate: {
74
+ isRestricted: true,
75
+ },
76
+ platformSettings: {
77
+ supportEmail,
78
+ },
79
+ });
80
+ const banner = screen.getByRole('alert');
81
+ expect(banner).toBeInTheDocument();
82
+ const msg = screen.getByText((text) => text.includes(supportEmail));
83
+ expect(msg).toBeInTheDocument();
84
+ });
85
+ it('is restricted with billing email but not verified', () => {
86
+ createWrapper({
87
+ certificate: {
88
+ isRestricted: true,
89
+ },
90
+ platformSettings: {
91
+ billingEmail,
92
+ },
93
+ });
94
+ const banner = screen.getByRole('alert');
95
+ expect(banner).toBeInTheDocument();
96
+ expect(banner).toHaveClass('alert-danger');
97
+ const msg = screen.queryByText((text) => text.includes(billingEmail));
98
+ expect(msg).not.toBeInTheDocument();
99
+ });
100
+ it('is restricted and verified', () => {
101
+ createWrapper({
102
+ certificate: {
103
+ isRestricted: true,
104
+ },
105
+ enrollment: {
106
+ isVerified: true,
107
+ },
108
+ });
109
+ const banner = screen.getByRole('alert');
110
+ expect(banner).toBeInTheDocument();
111
+ const restrictedMsg = screen.getByText((text) => text.includes('please let us know.'));
112
+ expect(restrictedMsg).toBeInTheDocument();
113
+ const refundMsg = screen.getByText((text) => text.includes('If you would like a refund'));
114
+ expect(refundMsg).toBeInTheDocument();
115
+ });
116
+ it('is restricted and verified with support email', () => {
117
+ createWrapper({
118
+ certificate: {
119
+ isRestricted: true,
120
+ },
121
+ enrollment: {
122
+ isVerified: true,
123
+ },
124
+ platformSettings: {
125
+ supportEmail,
126
+ },
127
+ });
128
+ const restrictedMsg = screen.getByText((text) => text.includes(supportEmail));
129
+ expect(restrictedMsg).toBeInTheDocument();
130
+ const refundMsg = screen.getByText((text) => text.includes('If you would like a refund'));
131
+ expect(refundMsg).toBeInTheDocument();
132
+ expect(refundMsg.innerHTML).not.toContain(billingEmail);
133
+ });
134
+ it('is restricted and verified with billing email', () => {
135
+ createWrapper({
136
+ certificate: {
137
+ isRestricted: true,
138
+ },
139
+ enrollment: {
140
+ isVerified: true,
141
+ },
142
+ platformSettings: {
143
+ billingEmail,
144
+ },
145
+ });
146
+ const restrictedMsg = screen.queryByText((text) => text.includes('please let us know.'));
147
+ expect(restrictedMsg).toBeInTheDocument();
148
+ expect(restrictedMsg.innerHTML).not.toContain(supportEmail);
149
+ const refundMsg = screen.getByText((text) => text.includes(billingEmail));
150
+ expect(refundMsg).toBeInTheDocument();
151
+ });
152
+ it('is restricted and verified with support and billing email', () => {
153
+ createWrapper({
154
+ certificate: {
155
+ isRestricted: true,
156
+ },
157
+ enrollment: {
158
+ isVerified: true,
159
+ },
160
+ platformSettings: {
161
+ supportEmail,
162
+ billingEmail,
163
+ },
164
+ });
165
+ const restrictedMsg = screen.getByText((text) => text.includes(supportEmail));
166
+ expect(restrictedMsg).toBeInTheDocument();
167
+ const refundMsg = screen.getByText((text) => text.includes(billingEmail));
168
+ expect(refundMsg).toBeInTheDocument();
169
+ });
170
+ it('is passing and is downloadable', () => {
171
+ createWrapper({
172
+ grade: { isPassing: true },
173
+ certificate: { isDownloadable: true },
174
+ });
175
+ const banner = screen.getByRole('alert');
176
+ expect(banner).toBeInTheDocument();
177
+ expect(banner).toHaveClass('alert-success');
178
+ const readyMsg = screen.getByText((text) => text.includes('Congratulations.'));
179
+ expect(readyMsg).toBeInTheDocument();
180
+ });
181
+ it('not passing and is downloadable', () => {
182
+ createWrapper({
183
+ grade: { isPassing: false },
184
+ certificate: { isDownloadable: true },
185
+ });
186
+ const banner = screen.getByRole('alert');
187
+ expect(banner).toBeInTheDocument();
188
+ expect(banner).toHaveClass('alert-success');
189
+ const readyMsg = screen.getByText((text) => text.includes('Congratulations.'));
190
+ expect(readyMsg).toBeInTheDocument();
191
+ });
192
+ it('not passing and audit', () => {
193
+ createWrapper({
194
+ enrollment: {
195
+ isAudit: true,
196
+ },
197
+ });
198
+ const banner = screen.getByRole('alert');
199
+ expect(banner).toHaveClass('alert-info');
200
+ const auditMsg = screen.getByText((text) => text.includes('Grade required to pass the course:'));
201
+ expect(auditMsg).toBeInTheDocument();
202
+ });
203
+ it('not passing and has finished', () => {
204
+ createWrapper({
205
+ courseRun: { isArchived: true },
206
+ });
207
+ const banner = screen.getByRole('alert');
208
+ expect(banner).toHaveClass('alert-warning');
209
+ const archivedMsg = screen.getByText('You are not eligible for a certificate.');
210
+ expect(archivedMsg).toBeInTheDocument();
211
+ });
212
+ it('not passing and not audit and not finished', () => {
213
+ createWrapper({});
214
+ const banner = screen.getByRole('alert');
215
+ expect(banner).toHaveClass('alert-warning');
216
+ const msg = screen.getByText((text) => text.includes('Grade required for a certificate'));
217
+ expect(msg).toBeInTheDocument();
218
+ });
219
+ it('is passing and is earned but unavailable', () => {
220
+ createWrapper({
221
+ grade: {
222
+ isPassing: true,
223
+ },
224
+ certificate: {
225
+ isEarnedButUnavailable: true,
226
+ },
227
+ });
228
+ const banner = screen.getByRole('alert');
229
+ expect(banner).toHaveClass('alert-info');
230
+ const earnedMsg = screen.getByText((text) => text.includes('Your grade and certificate will be ready after'));
231
+ expect(earnedMsg).toBeInTheDocument();
232
+ });
233
+ it('is passing and not downloadable render empty', () => {
234
+ createWrapper({
235
+ grade: {
236
+ isPassing: true,
237
+ },
238
+ });
239
+ const banner = screen.queryByRole('alert');
240
+ expect(banner).toBeNull();
226
241
  });
227
242
  });