@@ -34,6 +34,7 @@ const {
3434 languageWithoutTagsId,
3535 largeTagsId,
3636 emptyTagsId,
37+ containerTagsId,
3738} = mockContentTaxonomyTagsData ;
3839
3940jest . mock ( 'react-router-dom' , ( ) => ( {
@@ -46,14 +47,15 @@ jest.mock('../library-authoring/common/context/SidebarContext', () => ({
4647 useSidebarContext : ( ) => ( { sidebarAction : mockSidebarAction ( ) } ) ,
4748} ) ) ;
4849
49- const renderDrawer = ( contentId , drawerParams = { } ) => (
50- render (
50+ const renderDrawer = ( contentId , drawerParams = { } , renderPath = path , containerId = '' ) => {
51+ const params = { contentId, containerId } ;
52+ return render (
5153 < ContentTagsDrawerSheetContext . Provider value = { drawerParams } >
5254 < ContentTagsDrawer { ...drawerParams } />
5355 </ ContentTagsDrawerSheetContext . Provider > ,
54- { path, params : { contentId } } ,
55- )
56- ) ;
56+ { path : renderPath , params } ,
57+ ) ;
58+ } ;
5759
5860describe ( '<ContentTagsDrawer />' , ( ) => {
5961 beforeEach ( async ( ) => {
@@ -692,6 +694,42 @@ describe('<ContentTagsDrawer />', () => {
692694 await waitFor ( ( ) => expect ( axiosMock . history . put [ 0 ] . url ) . toEqual ( url ) ) ;
693695 } ) ;
694696
697+ [
698+ 'lct:org:lib:unit:1' ,
699+ 'lib-collection:org:lib:1' ,
700+ 'lb:org:lib:html:1' ,
701+ ] . forEach ( ( containerId ) => {
702+ it ( `should invalidate children query when update child tag when containerId is ${ containerId } ` , async ( ) => {
703+ const newPath = '/container/:containerId/' ;
704+ const { axiosMock, queryClient } = initializeMocks ( ) ;
705+ const mockInvalidateQueries = jest . spyOn ( queryClient , 'invalidateQueries' ) ;
706+ const url = getContentTaxonomyTagsApiUrl ( containerTagsId ) ;
707+ axiosMock . onPut ( url ) . reply ( 200 ) ;
708+ renderDrawer ( containerTagsId , { id : containerTagsId } , newPath , containerId ) ;
709+ expect ( await screen . findByText ( 'Taxonomy 1' ) ) . toBeInTheDocument ( ) ;
710+ const editTagsButton = screen . getByRole ( 'button' , {
711+ name : / e d i t t a g s / i,
712+ } ) ;
713+ fireEvent . click ( editTagsButton ) ;
714+
715+ const saveButton = screen . getByRole ( 'button' , {
716+ name : / s a v e / i,
717+ } ) ;
718+ fireEvent . click ( saveButton ) ;
719+
720+ await waitFor ( ( ) => expect ( axiosMock . history . put [ 0 ] . url ) . toEqual ( url ) ) ;
721+ expect ( mockInvalidateQueries ) . toHaveBeenCalledTimes ( 5 ) ;
722+ expect ( mockInvalidateQueries ) . toHaveBeenNthCalledWith ( 5 , [
723+ 'contentLibrary' ,
724+ 'lib:org:lib' ,
725+ 'content' ,
726+ 'container' ,
727+ containerId ,
728+ 'children' ,
729+ ] ) ;
730+ } ) ;
731+ } ) ;
732+
695733 it ( 'should taxonomies must be ordered' , async ( ) => {
696734 renderDrawer ( largeTagsId ) ;
697735 expect ( await screen . findByText ( 'Taxonomy 1' ) ) . toBeInTheDocument ( ) ;
0 commit comments