diff --git a/src/course-home/outline-tab/OutlineTab.jsx b/src/course-home/outline-tab/OutlineTab.jsx index 6b386893..a2c6dadf 100644 --- a/src/course-home/outline-tab/OutlineTab.jsx +++ b/src/course-home/outline-tab/OutlineTab.jsx @@ -32,7 +32,7 @@ import AccountActivationAlert from '../../alerts/logistration-alert/AccountActiv /** [MM-P2P] Experiment */ import { initHomeMMP2P, MMP2PFlyover } from '../../experiments/mm-p2p'; -import WeeklyLearningGoal from './widgets/WeeklyLearningGoalCard'; +import WeeklyLearningGoalCard from './widgets/WeeklyLearningGoalCard'; function OutlineTab({ intl }) { const { @@ -211,7 +211,7 @@ function OutlineTab({ intl }) { /> )} {weeklyLearningGoalEnabled && ( - { }); }); + describe('Weekly Learning Goals', () => { + it('does not render weekly learning goal if weeklyLearningGoalEnabled is false', async () => { + await fetchAndRender(); + expect(screen.queryByTestId('weekly-learning-goal-card')).not.toBeInTheDocument(); + }); + + describe('weekly learning goal is not set', () => { + beforeEach(async () => { + setTabData({ + course_goals: { + weekly_learning_goal_enabled: true, + }, + }); + await fetchAndRender(); + }); + + it('renders weekly learning goal card', async () => { + expect(screen.queryByTestId('weekly-learning-goal-card')).toBeInTheDocument(); + }); + + it('renders startOrResumeCourseCard', async () => { + expect(screen.queryByTestId('start-resume-card')).toBeInTheDocument(); + }); + + it('disables the subscribe button if no goal is set', async () => { + expect(screen.getByLabelText(messages.setGoalReminder.defaultMessage)).toBeDisabled(); + }); + + // Does this need more setup to test frontend backend mismatch? + it('does not show the previous goal setting card', async () => { + expect(screen.getByTestId('course-goal-card')).not.toBeInTheDocument(); + }); + + it('calls the API when a button is clicked', async () => { + expect(screen.queryByText(messages.casualGoalButtonText.defaultMessage)).toBeInTheDocument(); + expect(screen.getByText(messages.casualGoalButtonText.defaultMessage).closest('button')).toBeInTheDocument(); + + const button = await screen.getByText(messages.casualGoalButtonText.defaultMessage).closest('button'); + fireEvent.click(button); + // Verify the request was made + await waitFor(() => { + expect(axiosMock.history.post[0].url).toMatch(goalUrl); + expect(axiosMock.history.post[0].data).toMatch(`{"course_id":"${courseId}","days_per_week":3,"subscribed_to_reminders":false}`); + }); + expect(screen.getByLabelText(messages.setGoalReminder.defaultMessage)).toBeEnabled(); + }); + }); + }); + describe('Course Handouts', () => { it('renders title when handouts are available', async () => { await fetchAndRender(); diff --git a/src/course-home/outline-tab/widgets/FlagButton.jsx b/src/course-home/outline-tab/widgets/FlagButton.jsx index 7db7a321..89d9434e 100644 --- a/src/course-home/outline-tab/widgets/FlagButton.jsx +++ b/src/course-home/outline-tab/widgets/FlagButton.jsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import PropTypes from 'prop-types'; function FlagButton({ - icon, + ButtonIcon, srText, title, text, @@ -22,7 +22,7 @@ function FlagButton({ onClick={() => handleSelect()} >
- {icon} + {ButtonIcon}
{srText}
@@ -36,7 +36,7 @@ function FlagButton({ } FlagButton.propTypes = { - icon: PropTypes.node.isRequired, + ButtonIcon: PropTypes.element.isRequired, srText: PropTypes.string.isRequired, title: PropTypes.string.isRequired, text: PropTypes.string, diff --git a/src/course-home/outline-tab/widgets/StartOrResumeCourseCard.jsx b/src/course-home/outline-tab/widgets/StartOrResumeCourseCard.jsx index 439d289f..c15c7b65 100644 --- a/src/course-home/outline-tab/widgets/StartOrResumeCourseCard.jsx +++ b/src/course-home/outline-tab/widgets/StartOrResumeCourseCard.jsx @@ -38,7 +38,7 @@ function StartOrResumeCourseCard({ intl }) { }; return ( - +

{intl.formatMessage(messages.startBlurb)}

diff --git a/src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx b/src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx index c4a33422..d5dafcf1 100644 --- a/src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx +++ b/src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx @@ -42,7 +42,7 @@ function WeeklyLearningGoalCard({ return (
- +

{intl.formatMessage(messages.setWeeklyGoal)}

@@ -53,7 +53,7 @@ function WeeklyLearningGoalCard({
} + ButtonIcon={} srText={intl.formatMessage(messages.setLearningGoalButtonScreenReaderText)} title={intl.formatMessage(messages.casualGoalButtonTitle)} text={intl.formatMessage(messages.casualGoalButtonText)} @@ -63,7 +63,7 @@ function WeeklyLearningGoalCard({
} + ButtonIcon={} srText={intl.formatMessage(messages.setLearningGoalButtonScreenReaderText)} title={intl.formatMessage(messages.regularGoalButtonTitle)} text={intl.formatMessage(messages.regularGoalButtonText)} @@ -73,7 +73,7 @@ function WeeklyLearningGoalCard({
} + ButtonIcon={} srText={intl.formatMessage(messages.setLearningGoalButtonScreenReaderText)} title={intl.formatMessage(messages.intenseGoalButtonTitle)} text={intl.formatMessage(messages.intenseGoalButtonText)}