@@ -23,6 +23,7 @@ import * as UI from '../../ui/legacy/legacy.js';
2323import * as Elements from '../elements/elements.js' ;
2424import * as Network from '../network/network.js' ;
2525import * as Sources from '../sources/sources.js' ;
26+ import type * as TimelineComponents from '../timeline/components/components.js' ;
2627import * as Timeline from '../timeline/timeline.js' ;
2728import * as TimelineUtils from '../timeline/utils/utils.js' ;
2829
@@ -448,49 +449,54 @@ describeWithMockConnection('AI Assistance Panel', () => {
448449 assert . deepEqual ( updatedViewInputAfterNewChat . conversationType , AiAssistance . ConversationType . STYLING ) ;
449450 } ) ;
450451
451- it ( 'should select the performance insights agent if it is enabled' , async ( ) => {
452- updateHostConfig ( {
453- devToolsAiAssistancePerformanceAgent : {
454- enabled : true ,
455- insightsEnabled : true ,
456- } ,
457- } ) ;
458- const { panel, expectViewUpdate} =
459- await createAiAssistancePanel ( { aidaClient : mockAidaClient ( [ [ { explanation : 'test' } ] ] ) } ) ;
460-
461- const updatedViewInput = await expectViewUpdate ( ( ) => {
462- panel . handleAction ( 'freestyler.elements-floating-button' ) ;
463- } ) ;
452+ it ( 'should select the performance insights agent if it is enabled and the user has expanded an insight' ,
453+ async ( ) => {
454+ updateHostConfig ( {
455+ devToolsAiAssistancePerformanceAgent : {
456+ enabled : true ,
457+ insightsEnabled : true ,
458+ } ,
459+ } ) ;
460+ const { panel, expectViewUpdate} =
461+ await createAiAssistancePanel ( { aidaClient : mockAidaClient ( [ [ { explanation : 'test' } ] ] ) } ) ;
464462
465- const updatedViewInputAfterMessage = await expectViewUpdate ( ( ) => {
466- updatedViewInput . onTextSubmit ( 'test ') ;
467- } ) ;
463+ const updatedViewInput = await expectViewUpdate ( ( ) => {
464+ panel . handleAction ( 'freestyler.elements-floating-button ') ;
465+ } ) ;
468466
469- UI . Context . Context . instance ( ) . setFlavor (
470- Timeline . TimelinePanel . TimelinePanel , sinon . createStubInstance ( Timeline . TimelinePanel . TimelinePanel ) ) ;
467+ const updatedViewInputAfterMessage = await expectViewUpdate ( ( ) => {
468+ updatedViewInput . onTextSubmit ( 'test' ) ;
469+ } ) ;
471470
472- assert . deepEqual ( updatedViewInputAfterMessage . messages , [
473- {
474- entity : AiAssistance . ChatMessageEntity . USER ,
475- text : 'test' ,
476- imageInput : undefined ,
477- } ,
478- {
479- answer : 'test' ,
480- entity : AiAssistance . ChatMessageEntity . MODEL ,
481- rpcId : undefined ,
482- suggestions : undefined ,
483- steps : [ ] ,
484- } ,
485- ] ) ;
486- const updatedViewInputAfterNewChat = await expectViewUpdate ( ( ) => {
487- updatedViewInputAfterMessage . onNewChatClick ( ) ;
488- } ) ;
471+ UI . Context . Context . instance ( ) . setFlavor (
472+ Timeline . TimelinePanel . TimelinePanel , sinon . createStubInstance ( Timeline . TimelinePanel . TimelinePanel ) ) ;
473+
474+ UI . Context . Context . instance ( ) . setFlavor (
475+ Timeline . TimelinePanel . SelectedInsight ,
476+ new Timeline . TimelinePanel . SelectedInsight ( { } as unknown as TimelineComponents . Sidebar . ActiveInsight ) ) ;
477+
478+ assert . deepEqual ( updatedViewInputAfterMessage . messages , [
479+ {
480+ entity : AiAssistance . ChatMessageEntity . USER ,
481+ text : 'test' ,
482+ imageInput : undefined ,
483+ } ,
484+ {
485+ answer : 'test' ,
486+ entity : AiAssistance . ChatMessageEntity . MODEL ,
487+ rpcId : undefined ,
488+ suggestions : undefined ,
489+ steps : [ ] ,
490+ } ,
491+ ] ) ;
492+ const updatedViewInputAfterNewChat = await expectViewUpdate ( ( ) => {
493+ updatedViewInputAfterMessage . onNewChatClick ( ) ;
494+ } ) ;
489495
490- assert . deepEqual ( updatedViewInputAfterNewChat . messages , [ ] ) ;
491- assert . deepEqual (
492- updatedViewInputAfterNewChat . conversationType , AiAssistance . ConversationType . PERFORMANCE_INSIGHT ) ;
493- } ) ;
496+ assert . deepEqual ( updatedViewInputAfterNewChat . messages , [ ] ) ;
497+ assert . deepEqual (
498+ updatedViewInputAfterNewChat . conversationType , AiAssistance . ConversationType . PERFORMANCE_INSIGHT ) ;
499+ } ) ;
494500
495501 it ( 'should select the Dr Jones performance agent if insights are not enabled' , async ( ) => {
496502 updateHostConfig ( {
@@ -1068,7 +1074,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
10681074 }
10691075
10701076 describe ( 'Performance Insight agent' , ( ) => {
1071- it ( 'should select the PERFORMANCE_INSIGHT agent when the performance panel is open and insights are enabled' ,
1077+ it ( 'should select the PERFORMANCE_INSIGHT agent when the performance panel is open and insights are enabled and an insight is expanded ' ,
10721078 async ( ) => {
10731079 updateHostConfig ( {
10741080 devToolsAiAssistancePerformanceAgent : {
@@ -1078,10 +1084,29 @@ describeWithMockConnection('AI Assistance Panel', () => {
10781084 } ) ;
10791085 UI . Context . Context . instance ( ) . setFlavor (
10801086 Timeline . TimelinePanel . TimelinePanel , sinon . createStubInstance ( Timeline . TimelinePanel . TimelinePanel ) ) ;
1087+ UI . Context . Context . instance ( ) . setFlavor (
1088+ Timeline . TimelinePanel . SelectedInsight ,
1089+ new Timeline . TimelinePanel . SelectedInsight ( { } as unknown as TimelineComponents . Sidebar . ActiveInsight ) ) ;
10811090 const { initialViewInput} = await createAiAssistancePanel ( ) ;
10821091
10831092 assert . strictEqual ( initialViewInput . conversationType , AiAssistance . ConversationType . PERFORMANCE_INSIGHT ) ;
10841093 } ) ;
1094+
1095+ it ( 'should select the PERFORMANCE agent when the performance panel is open and insights are enabled but the user has not selected an insight' ,
1096+ async ( ) => {
1097+ updateHostConfig ( {
1098+ devToolsAiAssistancePerformanceAgent : {
1099+ enabled : true ,
1100+ insightsEnabled : true ,
1101+ } ,
1102+ } ) ;
1103+ UI . Context . Context . instance ( ) . setFlavor (
1104+ Timeline . TimelinePanel . TimelinePanel , sinon . createStubInstance ( Timeline . TimelinePanel . TimelinePanel ) ) ;
1105+ UI . Context . Context . instance ( ) . setFlavor ( Timeline . TimelinePanel . SelectedInsight , null ) ;
1106+
1107+ const { initialViewInput} = await createAiAssistancePanel ( ) ;
1108+ assert . strictEqual ( initialViewInput . conversationType , AiAssistance . ConversationType . PERFORMANCE ) ;
1109+ } ) ;
10851110 } ) ;
10861111 } ) ;
10871112
0 commit comments