Skip to content

Commit

Permalink
fix: ensure we don't update goals while users are masquerading (opene…
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewPiatetsky authored Oct 20, 2021
1 parent eabbb44 commit 67ea30a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/course-home/outline-tab/OutlineTab.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,21 @@ describe('Outline Tab', () => {
expect(screen.queryByTestId('weekly-learning-goal-card')).not.toBeInTheDocument();
});

it('does not post goals while masquerading', async () => {
setMetadata({ is_enrolled: true, original_user_is_staff: true });
setTabData({
course_goals: {
weekly_learning_goal_enabled: true,
},
});
const spy = jest.spyOn(thunks, 'saveWeeklyLearningGoal');

await fetchAndRender();
const button = await screen.getByTestId('weekly-learning-goal-input-regular');
fireEvent.click(button);
expect(spy).toHaveBeenCalledTimes(0);
});

describe('weekly learning goal is not set', () => {
beforeEach(async () => {
setTabData({
Expand Down
13 changes: 11 additions & 2 deletions src/course-home/outline-tab/widgets/WeeklyLearningGoalCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useSelector } from 'react-redux';
import messages from '../messages';
import LearningGoalButton from './LearningGoalButton';
import { saveWeeklyLearningGoal } from '../../data';
import { useModel } from '../../../generic/model-store';

function WeeklyLearningGoalCard({
daysPerWeek,
Expand All @@ -18,6 +19,10 @@ function WeeklyLearningGoalCard({
courseId,
} = useSelector(state => state.courseHome);

const {
isMasquerading,
} = useModel('courseHomeMeta', courseId);

const [daysPerWeekGoal, setDaysPerWeekGoal] = useState(daysPerWeek);
// eslint-disable-next-line react/prop-types
const [isGetReminderSelected, setGetReminderSelected] = useState(subscribedToReminders);
Expand All @@ -27,13 +32,17 @@ function WeeklyLearningGoalCard({
const selectReminders = daysPerWeekGoal === null ? true : isGetReminderSelected;
setGetReminderSelected(selectReminders);
setDaysPerWeekGoal(days);
saveWeeklyLearningGoal(courseId, days, selectReminders);
if (!isMasquerading) { // don't save goal updates while masquerading
saveWeeklyLearningGoal(courseId, days, selectReminders);
}
}

function handleSubscribeToReminders(event) {
const isGetReminderChecked = event.target.checked;
setGetReminderSelected(isGetReminderChecked);
saveWeeklyLearningGoal(courseId, daysPerWeekGoal, isGetReminderChecked);
if (!isMasquerading) { // don't save goal updates while masquerading
saveWeeklyLearningGoal(courseId, daysPerWeekGoal, isGetReminderChecked);
}
}

return (
Expand Down

0 comments on commit 67ea30a

Please sign in to comment.