@@ -689,6 +689,84 @@ describeWithEnvironment('FreestylerPanel', () => {
689689 assert . deepEqual ( mockView . lastCall . args [ 0 ] . agentType , AiAssistance . AgentType . STYLING ) ;
690690 } ) ;
691691
692+ it ( 'should select the performance insights agent if it is enabled' , async ( ) => {
693+ Object . assign ( Root . Runtime . hostConfig , {
694+ devToolsAiAssistancePerformanceAgent : {
695+ enabled : true ,
696+ insightsEnabled : true ,
697+ } ,
698+ } ) ;
699+ panel = new AiAssistance . AiAssistancePanel ( mockView , {
700+ aidaClient : mockAidaClient ( [ [ { explanation : 'test' } ] ] ) ,
701+ aidaAvailability : Host . AidaClient . AidaAccessPreconditions . AVAILABLE ,
702+ syncInfo : getTestSyncInfo ( ) ,
703+ } ) ;
704+ panel . handleAction ( 'freestyler.elements-floating-button' ) ;
705+ mockView . lastCall . args [ 0 ] . onTextSubmit ( 'test' ) ;
706+ await drainMicroTasks ( ) ;
707+ UI . Context . Context . instance ( ) . setFlavor (
708+ TimelinePanel . TimelinePanel . TimelinePanel ,
709+ sinon . createStubInstance ( TimelinePanel . TimelinePanel . TimelinePanel ) ) ;
710+
711+ assert . deepEqual ( mockView . lastCall . args [ 0 ] . messages , [
712+ {
713+ entity : AiAssistance . ChatMessageEntity . USER ,
714+ text : 'test' ,
715+ } ,
716+ {
717+ answer : 'test' ,
718+ entity : AiAssistance . ChatMessageEntity . MODEL ,
719+ rpcId : undefined ,
720+ suggestions : undefined ,
721+ steps : [ ] ,
722+ } ,
723+ ] ) ;
724+ const button = panel . contentElement . querySelector ( 'devtools-button[aria-label=\'New chat\']' ) ;
725+ assert . instanceOf ( button , HTMLElement ) ;
726+ dispatchClickEvent ( button ) ;
727+ assert . deepEqual ( mockView . lastCall . args [ 0 ] . messages , [ ] ) ;
728+ assert . deepEqual ( mockView . lastCall . args [ 0 ] . agentType , AiAssistance . AgentType . PERFORMANCE_INSIGHT ) ;
729+ } ) ;
730+
731+ it ( 'should select the Dr Jones performance agent if insights are not enabled' , async ( ) => {
732+ Object . assign ( Root . Runtime . hostConfig , {
733+ devToolsAiAssistancePerformanceAgent : {
734+ enabled : true ,
735+ insightsEnabled : false ,
736+ } ,
737+ } ) ;
738+ panel = new AiAssistance . AiAssistancePanel ( mockView , {
739+ aidaClient : mockAidaClient ( [ [ { explanation : 'test' } ] ] ) ,
740+ aidaAvailability : Host . AidaClient . AidaAccessPreconditions . AVAILABLE ,
741+ syncInfo : getTestSyncInfo ( ) ,
742+ } ) ;
743+ panel . handleAction ( 'freestyler.elements-floating-button' ) ;
744+ mockView . lastCall . args [ 0 ] . onTextSubmit ( 'test' ) ;
745+ await drainMicroTasks ( ) ;
746+ UI . Context . Context . instance ( ) . setFlavor (
747+ TimelinePanel . TimelinePanel . TimelinePanel ,
748+ sinon . createStubInstance ( TimelinePanel . TimelinePanel . TimelinePanel ) ) ;
749+
750+ assert . deepEqual ( mockView . lastCall . args [ 0 ] . messages , [
751+ {
752+ entity : AiAssistance . ChatMessageEntity . USER ,
753+ text : 'test' ,
754+ } ,
755+ {
756+ answer : 'test' ,
757+ entity : AiAssistance . ChatMessageEntity . MODEL ,
758+ rpcId : undefined ,
759+ suggestions : undefined ,
760+ steps : [ ] ,
761+ } ,
762+ ] ) ;
763+ const button = panel . contentElement . querySelector ( 'devtools-button[aria-label=\'New chat\']' ) ;
764+ assert . instanceOf ( button , HTMLElement ) ;
765+ dispatchClickEvent ( button ) ;
766+ assert . deepEqual ( mockView . lastCall . args [ 0 ] . messages , [ ] ) ;
767+ assert . deepEqual ( mockView . lastCall . args [ 0 ] . agentType , AiAssistance . AgentType . PERFORMANCE ) ;
768+ } ) ;
769+
692770 it ( 'should switch agents and restore history' , async ( ) => {
693771 panel = new AiAssistance . AiAssistancePanel ( mockView , {
694772 aidaClient : mockAidaClient ( [ [ { explanation : 'test' } ] , [ { explanation : 'test2' } ] ] ) ,
0 commit comments