@@ -2304,4 +2304,59 @@ describe('<CourseUnit />', () => {
23042304 // Does not render the "Add Components" section
23052305 expect ( screen . queryByText ( addComponentMessages . title . defaultMessage ) ) . not . toBeInTheDocument ( ) ;
23062306 } ) ;
2307+
2308+ it ( 'resets XBlock publish state after discarding changes' , async ( ) => {
2309+ render ( < RootWrapper /> ) ;
2310+ let courseUnitSidebar ;
2311+ let discardChangesBtn ;
2312+
2313+ await waitFor ( ( ) => {
2314+ courseUnitSidebar = screen . getByTestId ( 'course-unit-sidebar' ) ;
2315+ // Ensure we are in the draft/unpublished state
2316+ expect ( within ( courseUnitSidebar )
2317+ . getByText ( sidebarMessages . sidebarTitleDraftUnpublishedChanges . defaultMessage ) ) . toBeInTheDocument ( ) ;
2318+ discardChangesBtn = within ( courseUnitSidebar )
2319+ . queryByRole ( 'button' , { name : sidebarMessages . actionButtonDiscardChangesTitle . defaultMessage } ) ;
2320+ expect ( discardChangesBtn ) . toBeInTheDocument ( ) ;
2321+ userEvent . click ( discardChangesBtn ) ;
2322+ } ) ;
2323+
2324+ // Confirm discard in modal
2325+ const modalNotification = await screen . findByRole ( 'dialog' ) ;
2326+ const actionBtn = within ( modalNotification )
2327+ . getByRole ( 'button' , { name : sidebarMessages . modalDiscardUnitChangesActionButtonText . defaultMessage } ) ;
2328+ userEvent . click ( actionBtn ) ;
2329+
2330+ // Mock API responses for discard
2331+ axiosMock
2332+ . onPost ( getXBlockBaseApiUrl ( blockId ) , {
2333+ publish : PUBLISH_TYPES . discardChanges ,
2334+ } )
2335+ . reply ( 200 , { dummy : 'value' } ) ;
2336+ axiosMock
2337+ . onGet ( getCourseSectionVerticalApiUrl ( blockId ) )
2338+ . reply ( 200 , {
2339+ ...courseSectionVerticalMock ,
2340+ xblock_info : {
2341+ ...courseSectionVerticalMock . xblock_info ,
2342+ published : true ,
2343+ has_changes : false ,
2344+ } ,
2345+ } ) ;
2346+
2347+ await executeThunk ( editCourseUnitVisibilityAndData (
2348+ blockId ,
2349+ PUBLISH_TYPES . discardChanges ,
2350+ true ,
2351+ ) , store . dispatch ) ;
2352+
2353+ // Now the sidebar should reflect the published state (no draft/unpublished changes)
2354+ await waitFor ( ( ) => {
2355+ expect ( within ( courseUnitSidebar )
2356+ . getByText ( sidebarMessages . sidebarTitlePublishedNotYetReleased . defaultMessage ) ) . toBeInTheDocument ( ) ;
2357+ expect (
2358+ within ( courseUnitSidebar ) . queryByRole ( 'button' , { name : sidebarMessages . actionButtonDiscardChangesTitle . defaultMessage } ) ,
2359+ ) . not . toBeInTheDocument ( ) ;
2360+ } ) ;
2361+ } ) ;
23072362} ) ;
0 commit comments