diff --git a/src/course-outline/outline-sidebar/info-sidebar/sharedSettings/ReleaseSection.test.tsx b/src/course-outline/outline-sidebar/info-sidebar/sharedSettings/ReleaseSection.test.tsx index e520619218..1a44f9c830 100644 --- a/src/course-outline/outline-sidebar/info-sidebar/sharedSettings/ReleaseSection.test.tsx +++ b/src/course-outline/outline-sidebar/info-sidebar/sharedSettings/ReleaseSection.test.tsx @@ -4,26 +4,36 @@ import userEvent from '@testing-library/user-event'; import { useCourseItemData } from '@src/course-outline/data/apiHooks'; import { ReleaseSection } from './ReleaseSection'; -// Make useStateWithCallback synchronous so callbacks call onChange immediately +// Make useStateWithCallback synchronous so callbacks call onChange immediately. +// Also handles the { value, skipCallback } object form used by the external-sync useEffect. jest.mock('@src/hooks', () => ({ useStateWithCallback: (defaultValue: any, cb?: any) => { const { useState } = jest.requireActual('react'); const [state, setState] = useState(defaultValue); const wrappedSetState = (val: any) => { - const newVal = typeof val === 'function' ? val(state) : val; + let newVal; + let skip = false; + if (typeof val === 'object' && val !== null && 'value' in val && 'skipCallback' in val) { + newVal = val.value; + skip = val.skipCallback; + } else { + newVal = typeof val === 'function' ? val(state) : val; + } setState(newVal); - if (cb) { cb(newVal); } + if (cb && !skip) { cb(newVal); } }; return [state, wrappedSetState]; }, })); -// Mock DatepickerControl so we can trigger onChange easily +// Mock DatepickerControl so we can trigger onChange and inspect the current value. jest.mock('@src/generic/datepicker-control', () => ({ DATEPICKER_TYPES: { date: 'date', time: 'time' }, - DatepickerControl: ({ onChange, type }: any) => ( + DatepickerControl: ({ onChange, type, value }: any) => (