From 9b34321f59ae70b3c9f78aaccf4a35e294f92b7c Mon Sep 17 00:00:00 2001 From: Muhammad Arslan Abdul Rauf Date: Thu, 4 Jun 2026 14:15:11 +0500 Subject: [PATCH] fix: update release date for sidebar on updating it from outline side --- .../sharedSettings/ReleaseSection.test.tsx | 42 ++++++++++++++++--- .../sharedSettings/ReleaseSection.tsx | 9 ++++ .../sharedSettings/VisibilitySection.test.tsx | 34 +++++++++++++++ .../sharedSettings/VisibilitySection.tsx | 15 +++++++ 4 files changed, 95 insertions(+), 5 deletions(-) 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) => (