11// Copyright (C) 2022-2025 Intel Corporation
22// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
33
4- import { QueryClient } from '@tanstack/react-query' ;
4+ import { QueryClient , useQueryClient } from '@tanstack/react-query' ;
55import { waitFor } from '@testing-library/react' ;
66
77import { MEDIA_TYPE } from '../../../../core/media/base-media.interface' ;
88import { createInMemoryMediaService } from '../../../../core/media/services/in-memory-media-service/in-memory-media-service' ;
99import { MediaService } from '../../../../core/media/services/media-service.interface' ;
10- import { NOTIFICATION_TYPE } from '../../../../notification/notification-toast/notification-type.enum' ;
1110import { getMockedProjectIdentifier } from '../../../../test-utils/mocked-items-factory/mocked-identifiers' ;
1211import { getMockedImageMediaItem } from '../../../../test-utils/mocked-items-factory/mocked-media' ;
1312import { renderHookWithProviders } from '../../../../test-utils/render-hook-with-providers' ;
@@ -16,18 +15,12 @@ import { filterPageMedias } from '../../utils';
1615import { useDeleteMediaMutation } from './media-delete.hook' ;
1716
1817const mockSetQueriesData = jest . fn ( ) ;
19- const mockAddNotification = jest . fn ( ) ;
2018
2119jest . mock ( '../../utils' , ( ) => ( {
2220 ...jest . requireActual ( '../../utils' ) ,
2321 filterPageMedias : jest . fn ( ) ,
2422} ) ) ;
2523
26- jest . mock ( '../../../../notification/notification.component' , ( ) => ( {
27- ...jest . requireActual ( '../../../../notification/notification.component' ) ,
28- useNotification : ( ) => ( { addNotification : mockAddNotification } ) ,
29- } ) ) ;
30-
3124const mockedImageMedia = getMockedImageMediaItem ( {
3225 name : 'image-1' ,
3326 identifier : { type : MEDIA_TYPE . IMAGE , imageId : '1111' } ,
@@ -42,15 +35,22 @@ const renderDeleteMediaMutationHook = ({
4235} : {
4336 mediaService ?: MediaService ;
4437} = { } ) => {
45- const queryClient = new QueryClient ( ) ;
46- queryClient . setQueriesData = mockSetQueriesData ;
47-
48- return renderHookWithProviders ( useDeleteMediaMutation , {
49- wrapper : ( { children } ) => (
50- < ProjectProvider projectIdentifier = { getMockedProjectIdentifier ( ) } > { children } </ ProjectProvider >
51- ) ,
52- providerProps : { mediaService, queryClient } ,
53- } ) ;
38+ let queryClient : QueryClient ;
39+
40+ return renderHookWithProviders (
41+ ( ) => {
42+ queryClient = useQueryClient ( ) ;
43+ queryClient . setQueriesData = mockSetQueriesData ;
44+
45+ return useDeleteMediaMutation ( ) ;
46+ } ,
47+ {
48+ wrapper : ( { children } ) => (
49+ < ProjectProvider projectIdentifier = { getMockedProjectIdentifier ( ) } > { children } </ ProjectProvider >
50+ ) ,
51+ providerProps : { mediaService } ,
52+ }
53+ ) ;
5454} ;
5555
5656const mockedResponse = {
@@ -85,7 +85,6 @@ describe('useDeleteMediaMutation', () => {
8585 await waitFor ( ( ) => {
8686 expect ( filterPageMedias ) . toHaveBeenCalled ( ) ;
8787 expect ( mockSetQueriesData ) . toHaveBeenCalledTimes ( 1 ) ;
88- expect ( mockAddNotification ) . not . toHaveBeenCalled ( ) ;
8988 } ) ;
9089 } ) ;
9190
@@ -106,10 +105,6 @@ describe('useDeleteMediaMutation', () => {
106105 await waitFor ( ( ) => {
107106 expect ( filterPageMedias ) . toHaveBeenCalled ( ) ;
108107 expect ( mockSetQueriesData ) . toHaveBeenCalledTimes ( 2 ) ;
109- expect ( mockAddNotification ) . toHaveBeenCalledWith ( {
110- message : `Media cannot be deleted. ${ errorMessage } ` ,
111- type : NOTIFICATION_TYPE . ERROR ,
112- } ) ;
113108 } ) ;
114109 } ) ;
115110} ) ;
0 commit comments