@@ -41,7 +41,8 @@ jest.mock('../../services', () => ({
41
41
} ,
42
42
} ) ,
43
43
getAssistantClient : jest . fn ( ) . mockReturnValue ( {
44
- executeAgentByName : jest . fn ( ) ,
44
+ agentConfigExists : jest . fn ( ) ,
45
+ executeAgentByConfigName : jest . fn ( ) ,
45
46
} ) ,
46
47
getUsageCollection : jest . fn ( ) ,
47
48
} ) ) ;
@@ -127,11 +128,13 @@ describe('GenerateAnomalyDetector spec', () => {
127
128
timeFieldName : '@timestamp' ,
128
129
} ,
129
130
} ) ;
130
-
131
+ ( getAssistantClient ( ) . agentConfigExists as jest . Mock ) . mockResolvedValueOnce ( {
132
+ exists : true
133
+ } ) ;
131
134
} ) ;
132
135
133
136
it ( 'renders with empty generated parameters' , async ( ) => {
134
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
137
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
135
138
body : {
136
139
inference_results : [
137
140
{
@@ -155,7 +158,7 @@ describe('GenerateAnomalyDetector spec', () => {
155
158
} ) ;
156
159
157
160
it ( 'renders with empty parameter' , async ( ) => {
158
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
161
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
159
162
body : {
160
163
inference_results : [
161
164
{
@@ -179,7 +182,7 @@ describe('GenerateAnomalyDetector spec', () => {
179
182
} ) ;
180
183
181
184
it ( 'renders with empty aggregation field or empty aggregation method' , async ( ) => {
182
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
185
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
183
186
body : {
184
187
inference_results : [
185
188
{
@@ -203,7 +206,7 @@ describe('GenerateAnomalyDetector spec', () => {
203
206
} ) ;
204
207
205
208
it ( 'renders with different number of aggregation methods and fields' , async ( ) => {
206
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
209
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
207
210
body : {
208
211
inference_results : [
209
212
{
@@ -227,7 +230,7 @@ describe('GenerateAnomalyDetector spec', () => {
227
230
} ) ;
228
231
229
232
it ( 'renders component completely' , async ( ) => {
230
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
233
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
231
234
body : {
232
235
inference_results : [
233
236
{
@@ -252,6 +255,37 @@ describe('GenerateAnomalyDetector spec', () => {
252
255
} ) ;
253
256
} ) ;
254
257
258
+ describe ( 'Test agent not configured' , ( ) => {
259
+ beforeEach ( ( ) => {
260
+ jest . clearAllMocks ( ) ;
261
+ const queryService = getQueryService ( ) ;
262
+ queryService . queryString . getQuery . mockReturnValue ( {
263
+ dataset : {
264
+ id : 'test-pattern' ,
265
+ title : 'test-pattern' ,
266
+ type : 'INDEX_PATTERN' ,
267
+ timeFieldName : '@timestamp' ,
268
+ } ,
269
+ } ) ;
270
+ } ) ;
271
+
272
+ it ( 'renders with empty generated parameters' , async ( ) => {
273
+ ( getAssistantClient ( ) . agentConfigExists as jest . Mock ) . mockResolvedValueOnce ( {
274
+ exists : false
275
+ } ) ;
276
+
277
+ const { queryByText } = renderWithRouter ( ) ;
278
+ expect ( queryByText ( 'Suggested anomaly detector' ) ) . not . toBeNull ( ) ;
279
+
280
+ await waitFor ( ( ) => {
281
+ expect ( getNotifications ( ) . toasts . addDanger ) . toHaveBeenCalledTimes ( 1 ) ;
282
+ expect ( getNotifications ( ) . toasts . addDanger ) . toHaveBeenCalledWith (
283
+ 'Generate parameters for creating anomaly detector failed, reason: Error: Agent for suggest anomaly detector not found, please configure an agent firstly!'
284
+ ) ;
285
+ } ) ;
286
+ } ) ;
287
+ } ) ;
288
+
255
289
describe ( 'Test feedback' , ( ) => {
256
290
let reportUiStatsMock : any ;
257
291
@@ -273,14 +307,18 @@ describe('GenerateAnomalyDetector spec', () => {
273
307
CLICK : 'click' ,
274
308
} ,
275
309
} ) ;
310
+
311
+ ( getAssistantClient ( ) . agentConfigExists as jest . Mock ) . mockResolvedValueOnce ( {
312
+ exists : true
313
+ } ) ;
276
314
} ) ;
277
315
278
316
afterEach ( ( ) => {
279
317
jest . clearAllMocks ( ) ;
280
318
} ) ;
281
319
282
320
it ( 'should call reportMetric with thumbup when thumbs up is clicked' , async ( ) => {
283
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
321
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
284
322
body : {
285
323
inference_results : [
286
324
{
@@ -316,7 +354,7 @@ describe('GenerateAnomalyDetector spec', () => {
316
354
317
355
318
356
it ( 'should call reportMetric with thumbdown when thumbs down is clicked' , async ( ) => {
319
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
357
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
320
358
body : {
321
359
inference_results : [
322
360
{
@@ -363,6 +401,9 @@ describe('GenerateAnomalyDetector spec', () => {
363
401
timeFieldName : '@timestamp' ,
364
402
} ,
365
403
} ) ;
404
+ ( getAssistantClient ( ) . agentConfigExists as jest . Mock ) . mockResolvedValueOnce ( {
405
+ exists : true
406
+ } ) ;
366
407
} ) ;
367
408
368
409
it ( 'All API calls execute successfully' , async ( ) => {
@@ -382,7 +423,7 @@ describe('GenerateAnomalyDetector spec', () => {
382
423
} ) ;
383
424
}
384
425
} ) ;
385
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
426
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
386
427
body : {
387
428
inference_results : [
388
429
{
@@ -414,7 +455,7 @@ describe('GenerateAnomalyDetector spec', () => {
414
455
} ) ;
415
456
416
457
it ( 'Generate parameters failed' , async ( ) => {
417
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockRejectedValueOnce ( 'Generate parameters failed' ) ;
458
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockRejectedValueOnce ( 'Generate parameters failed' ) ;
418
459
419
460
const { queryByText } = renderWithRouter ( ) ;
420
461
expect ( queryByText ( 'Suggested anomaly detector' ) ) . not . toBeNull ( ) ;
@@ -441,7 +482,7 @@ describe('GenerateAnomalyDetector spec', () => {
441
482
} ) ;
442
483
}
443
484
} ) ;
444
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
485
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
445
486
body : {
446
487
inference_results : [
447
488
{
@@ -512,7 +553,7 @@ describe('GenerateAnomalyDetector spec', () => {
512
553
} ,
513
554
} ) ;
514
555
515
- ( getAssistantClient ( ) . executeAgentByName as jest . Mock ) . mockResolvedValueOnce ( {
556
+ ( getAssistantClient ( ) . executeAgentByConfigName as jest . Mock ) . mockResolvedValueOnce ( {
516
557
body : {
517
558
inference_results : [
518
559
{
0 commit comments