fix: ensure we don't update goals while users are masquerading (#697)
This commit is contained in:
committed by
GitHub
parent
eabbb440f0
commit
67ea30a45a
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
@@ -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);
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user