@@ -917,159 +917,88 @@ describeWithMockConnection('AI Assistance Panel', () => {
917917 } ) ;
918918
919919 describe ( 'auto agent selection for panels' , ( ) => {
920- describe ( 'Elements panel' , ( ) => {
921- it ( 'should select FREESTYLER agent when the Elements panel is open in initial render' , async ( ) => {
922- updateHostConfig ( {
923- devToolsFreestyler : {
924- enabled : true ,
920+ const tests : Array < {
921+ panel : { new ( ...args : any [ ] ) : UI . Panel . Panel } ,
922+ expectedAgentType : AiAssistance . AgentType ,
923+ featureFlagName : string ,
924+ } > =
925+ [
926+ {
927+ panel : Elements . ElementsPanel . ElementsPanel ,
928+ expectedAgentType : AiAssistance . AgentType . STYLING ,
929+ featureFlagName : 'devToolsFreestyler' ,
925930 } ,
926- } ) ;
927- UI . Context . Context . instance ( ) . setFlavor (
928- Elements . ElementsPanel . ElementsPanel , sinon . createStubInstance ( Elements . ElementsPanel . ElementsPanel ) ) ;
929-
930- const { view} = await createAiAssistancePanel ( {
931- aidaClient : mockAidaClient ( [ [ { explanation : 'test' } ] ] ) ,
932- } ) ;
933-
934- sinon . assert . calledWith ( view , sinon . match ( {
935- agentType : AiAssistance . AgentType . STYLING ,
936- } ) ) ;
937- } ) ;
938-
939- it ( 'should update to no agent state when the Elements panel is closed and no other panels are open' , async ( ) => {
940- updateHostConfig ( {
941- devToolsFreestyler : {
942- enabled : true ,
931+ {
932+ panel : Network . NetworkPanel . NetworkPanel ,
933+ expectedAgentType : AiAssistance . AgentType . NETWORK ,
934+ featureFlagName : 'devToolsAiAssistanceNetworkAgent' ,
943935 } ,
944- } ) ;
945- UI . Context . Context . instance ( ) . setFlavor (
946- Elements . ElementsPanel . ElementsPanel , sinon . createStubInstance ( Elements . ElementsPanel . ElementsPanel ) ) ;
947- const { view, expectViewUpdate} = await createAiAssistancePanel ( ) ;
948-
949- sinon . assert . calledWith ( view , sinon . match ( {
950- agentType : AiAssistance . AgentType . STYLING ,
951- } ) ) ;
952-
953- await expectViewUpdate ( ( ) => {
954- UI . Context . Context . instance ( ) . setFlavor ( Elements . ElementsPanel . ElementsPanel , null ) ;
955- } ) ;
956- assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
957- } ) ;
958-
959- it ( 'should render no agent state when Elements panel is open but Freestyler is not enabled' , async ( ) => {
960- updateHostConfig ( {
961- devToolsFreestyler : {
962- enabled : false ,
936+ {
937+ panel : Sources . SourcesPanel . SourcesPanel ,
938+ expectedAgentType : AiAssistance . AgentType . FILE ,
939+ featureFlagName : 'devToolsAiAssistanceFileAgent' ,
963940 } ,
964- } ) ;
965- UI . Context . Context . instance ( ) . setFlavor (
966- Elements . ElementsPanel . ElementsPanel , sinon . createStubInstance ( Elements . ElementsPanel . ElementsPanel ) ) ;
967- const { view} = await createAiAssistancePanel ( ) ;
941+ {
942+ panel : Timeline . TimelinePanel . TimelinePanel ,
943+ expectedAgentType : AiAssistance . AgentType . PERFORMANCE ,
944+ featureFlagName : 'devToolsAiAssistancePerformanceAgent' ,
945+ }
946+ ] ;
968947
969- assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
970- } ) ;
971- } ) ;
948+ for ( const test of tests ) {
949+ it ( `should select ${ test . expectedAgentType } conversation when the panel ${ test . panel . name } is opened` ,
950+ async ( ) => {
951+ updateHostConfig ( {
952+ [ test . featureFlagName ] : {
953+ enabled : true ,
954+ } ,
955+ } ) ;
956+ UI . Context . Context . instance ( ) . setFlavor ( test . panel , sinon . createStubInstance ( test . panel ) ) ;
957+
958+ const { view} = await createAiAssistancePanel ( {
959+ aidaClient : mockAidaClient ( [ [ { explanation : 'test' } ] ] ) ,
960+ } ) ;
961+
962+ sinon . assert . calledWith ( view . lastCall , sinon . match ( {
963+ agentType : test . expectedAgentType ,
964+ } ) ) ;
965+ } ) ;
972966
973- describe ( 'Network panel' , ( ) => {
974- it ( 'should select DRJONES_NETWORK agent when the Network panel is open in initial render' , async ( ) => {
967+ it ( `should reset the conversation when ${ test . panel . name } is closed and no other panels are open` , async ( ) => {
975968 updateHostConfig ( {
976- devToolsAiAssistanceNetworkAgent : {
969+ [ test . featureFlagName ] : {
977970 enabled : true ,
978971 } ,
979972 } ) ;
980- UI . Context . Context . instance ( ) . setFlavor (
981- Network . NetworkPanel . NetworkPanel , sinon . createStubInstance ( Network . NetworkPanel . NetworkPanel ) ) ;
982- const { view} = await createAiAssistancePanel ( ) ;
983973
984- sinon . assert . calledWith ( view , sinon . match ( {
985- agentType : AiAssistance . AgentType . NETWORK ,
986- } ) ) ;
987- } ) ;
974+ UI . Context . Context . instance ( ) . setFlavor ( test . panel , sinon . createStubInstance ( test . panel ) ) ;
988975
989- it ( 'should update to no agent state when the Network panel is closed and no other panels are open' , async ( ) => {
990- updateHostConfig ( {
991- devToolsAiAssistanceNetworkAgent : {
992- enabled : true ,
993- } ,
994- } ) ;
995- UI . Context . Context . instance ( ) . setFlavor (
996- Network . NetworkPanel . NetworkPanel , sinon . createStubInstance ( Network . NetworkPanel . NetworkPanel ) ) ;
997976 const { view, expectViewUpdate} = await createAiAssistancePanel ( ) ;
998977
999978 sinon . assert . calledWith ( view , sinon . match ( {
1000- agentType : AiAssistance . AgentType . NETWORK ,
1001- } ) ) ;
1002-
1003- await expectViewUpdate ( ( ) => {
1004- UI . Context . Context . instance ( ) . setFlavor ( Network . NetworkPanel . NetworkPanel , null ) ;
1005- } ) ;
1006- assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
1007- } ) ;
1008-
1009- it ( 'should render no agent state when Network panel is open but devToolsAiAssistanceNetworkAgent is not enabled' ,
1010- async ( ) => {
1011- updateHostConfig ( {
1012- devToolsAiAssistanceNetworkAgent : {
1013- enabled : false ,
1014- } ,
1015- } ) ;
1016- UI . Context . Context . instance ( ) . setFlavor (
1017- Network . NetworkPanel . NetworkPanel , sinon . createStubInstance ( Network . NetworkPanel . NetworkPanel ) ) ;
1018- const { view} = await createAiAssistancePanel ( ) ;
1019-
1020- assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
1021- } ) ;
1022- } ) ;
1023-
1024- describe ( 'Sources panel' , ( ) => {
1025- it ( 'should select DRJONES_FILE agent when the Sources panel is open in initial render' , async ( ) => {
1026- updateHostConfig ( {
1027- devToolsAiAssistanceFileAgent : {
1028- enabled : true ,
1029- } ,
1030- } ) ;
1031- UI . Context . Context . instance ( ) . setFlavor (
1032- Sources . SourcesPanel . SourcesPanel , sinon . createStubInstance ( Sources . SourcesPanel . SourcesPanel ) ) ;
1033- const { view} = await createAiAssistancePanel ( ) ;
1034-
1035- sinon . assert . calledWith ( view , sinon . match ( {
1036- agentType : AiAssistance . AgentType . FILE ,
1037- } ) ) ;
1038- } ) ;
1039-
1040- it ( 'should update to no agent state when the Sources panel is closed and no other panels are open' , async ( ) => {
1041- updateHostConfig ( {
1042- devToolsAiAssistanceFileAgent : {
1043- enabled : true ,
1044- } ,
1045- } ) ;
1046- UI . Context . Context . instance ( ) . setFlavor (
1047- Sources . SourcesPanel . SourcesPanel , sinon . createStubInstance ( Sources . SourcesPanel . SourcesPanel ) ) ;
1048- const { view, expectViewUpdate} = await createAiAssistancePanel ( ) ;
1049- sinon . assert . calledWith ( view , sinon . match ( {
1050- agentType : AiAssistance . AgentType . FILE ,
979+ agentType : test . expectedAgentType ,
1051980 } ) ) ;
1052981
1053- await expectViewUpdate ( ( ) => {
1054- UI . Context . Context . instance ( ) . setFlavor ( Sources . SourcesPanel . SourcesPanel , null ) ;
982+ const [ { agentType } ] = await expectViewUpdate ( ( ) => {
983+ UI . Context . Context . instance ( ) . setFlavor ( test . panel , null ) ;
1055984 } ) ;
1056- assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
985+ assert . isUndefined ( agentType ) ;
1057986 } ) ;
1058987
1059- it ( ' should render no agent state when Sources panel is open but devToolsAiAssistanceFileAgent is not enabled' ,
1060- async ( ) => {
1061- updateHostConfig ( {
1062- devToolsAiAssistanceFileAgent : {
1063- enabled : false ,
1064- } ,
1065- } ) ;
1066- UI . Context . Context . instance ( ) . setFlavor (
1067- Sources . SourcesPanel . SourcesPanel , sinon . createStubInstance ( Sources . SourcesPanel . SourcesPanel ) ) ;
1068- const { view} = await createAiAssistancePanel ( ) ;
1069-
1070- assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
1071- } ) ;
1072- } ) ;
988+ it ( ` should render no conversation state if the ${
989+ test . panel . name } panel is changed and the feature is not enabled` ,
990+ async ( ) => {
991+ updateHostConfig ( {
992+ [ test . featureFlagName ] : {
993+ enabled : false ,
994+ } ,
995+ } ) ;
996+ UI . Context . Context . instance ( ) . setFlavor ( test . panel , sinon . createStubInstance ( test . panel ) ) ;
997+ const { view} = await createAiAssistancePanel ( ) ;
998+
999+ assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
1000+ } ) ;
1001+ }
10731002
10741003 describe ( 'Performance Insight agent' , ( ) => {
10751004 it ( 'should select the PERFORMANCE_INSIGHT agent when the performance panel is open and insights are enabled' ,
@@ -1088,57 +1017,6 @@ describeWithMockConnection('AI Assistance Panel', () => {
10881017 } ) ) ;
10891018 } ) ;
10901019 } ) ;
1091-
1092- describe ( 'Performance panel' , ( ) => {
1093- it ( 'should select DRJONES_PERFORMANCE agent when the Performance panel is open in initial render' , async ( ) => {
1094- updateHostConfig ( {
1095- devToolsAiAssistancePerformanceAgent : {
1096- enabled : true ,
1097- } ,
1098- } ) ;
1099- UI . Context . Context . instance ( ) . setFlavor (
1100- Timeline . TimelinePanel . TimelinePanel , sinon . createStubInstance ( Timeline . TimelinePanel . TimelinePanel ) ) ;
1101- const { view} = await createAiAssistancePanel ( ) ;
1102-
1103- sinon . assert . calledWith ( view , sinon . match ( {
1104- agentType : AiAssistance . AgentType . PERFORMANCE ,
1105- } ) ) ;
1106- } ) ;
1107-
1108- it ( 'should update to no agent state when the Performance panel is closed and no other panels are open' ,
1109- async ( ) => {
1110- updateHostConfig ( {
1111- devToolsAiAssistancePerformanceAgent : {
1112- enabled : true ,
1113- } ,
1114- } ) ;
1115- UI . Context . Context . instance ( ) . setFlavor (
1116- Timeline . TimelinePanel . TimelinePanel , sinon . createStubInstance ( Timeline . TimelinePanel . TimelinePanel ) ) ;
1117- const { view, expectViewUpdate} = await createAiAssistancePanel ( ) ;
1118- sinon . assert . calledWith ( view , sinon . match ( {
1119- agentType : AiAssistance . AgentType . PERFORMANCE ,
1120- } ) ) ;
1121-
1122- await expectViewUpdate ( ( ) => {
1123- UI . Context . Context . instance ( ) . setFlavor ( Timeline . TimelinePanel . TimelinePanel , null ) ;
1124- } ) ;
1125- assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
1126- } ) ;
1127-
1128- it ( 'should render no agent state when Performance panel is open but devToolsAiAssistancePerformanceAgent is not enabled' ,
1129- async ( ) => {
1130- updateHostConfig ( {
1131- devToolsAiAssistancePerformanceAgent : {
1132- enabled : false ,
1133- } ,
1134- } ) ;
1135- UI . Context . Context . instance ( ) . setFlavor (
1136- Timeline . TimelinePanel . TimelinePanel , sinon . createStubInstance ( Timeline . TimelinePanel . TimelinePanel ) ) ;
1137- const { view} = await createAiAssistancePanel ( ) ;
1138-
1139- assert . isUndefined ( view . lastCall . args [ 0 ] . agentType ) ;
1140- } ) ;
1141- } ) ;
11421020 } ) ;
11431021
11441022 it ( 'erases previous partial response on blocked error' , async ( ) => {
0 commit comments