88} ;
99
1010import { createAlertsQuery , fetchDataForIncidentsAndAlerts } from './api' ;
11- import { PrometheusResponse } from '@openshift-console/dynamic-plugin-sdk' ;
11+ import { PrometheusResponse , consoleFetchJSON } from '@openshift-console/dynamic-plugin-sdk' ;
1212import { buildPrometheusUrl } from '../utils' ;
1313
1414// Mock the SDK
1515jest . mock ( '@openshift-console/dynamic-plugin-sdk' , ( ) => ( {
1616 PrometheusEndpoint : {
1717 QUERY_RANGE : 'api/v1/query_range' ,
1818 } ,
19+ consoleFetchJSON : jest . fn ( ) ,
1920} ) ) ;
2021
2122// Mock the global utils to avoid window access side effects
@@ -126,8 +127,8 @@ describe('fetchDataForIncidentsAndAlerts', () => {
126127 } ,
127128 } ;
128129
129- const fetch = jest
130- . fn ( )
130+ const mockConsoleFetchJSON = consoleFetchJSON as jest . MockedFunction < typeof consoleFetchJSON > ;
131+ mockConsoleFetchJSON
131132 . mockResolvedValueOnce ( mockPrometheusResponse1 )
132133 . mockResolvedValueOnce ( mockPrometheusResponse2 ) ;
133134
@@ -136,14 +137,14 @@ describe('fetchDataForIncidentsAndAlerts', () => {
136137 'ALERTS{alertname="test", severity="critical", namespace="test"}' ,
137138 'ALERTS{alertname="test2", severity="warning", namespace="test2"}' ,
138139 ] ;
139- const result = await fetchDataForIncidentsAndAlerts ( fetch , range , customQuery ) ;
140+ const result = await fetchDataForIncidentsAndAlerts ( mockConsoleFetchJSON , range , customQuery ) ;
140141 expect ( result ) . toEqual ( {
141142 status : 'success' ,
142143 data : {
143144 resultType : 'matrix' ,
144145 result : [ result1 , result2 ] ,
145146 } ,
146147 } ) ;
147- expect ( fetch ) . toHaveBeenCalledTimes ( 2 ) ;
148+ expect ( mockConsoleFetchJSON ) . toHaveBeenCalledTimes ( 2 ) ;
148149 } ) ;
149150} ) ;
0 commit comments