@@ -18,7 +18,7 @@ const {html} = Lit;
1818
1919describeWithEnvironment ( 'BaseInsightComponent' , ( ) => {
2020 const { BaseInsightComponent} = Insights . BaseInsightComponent ;
21- class TestInsightComponent extends BaseInsightComponent < Trace . Insights . Types . InsightModel > {
21+ class TestInsightComponentNoAISupport extends BaseInsightComponent < Trace . Insights . Types . InsightModel > {
2222 override internalName = 'test-insight' ;
2323 override createOverlays ( ) : TimelineOverlay [ ] {
2424 return [ ] ;
@@ -27,11 +27,22 @@ describeWithEnvironment('BaseInsightComponent', () => {
2727 return html `< div > test content</ div > ` ;
2828 }
2929 }
30- customElements . define ( 'test-insight-component' , TestInsightComponent ) ;
30+ class TestInsightComponentWithAISupport extends BaseInsightComponent < Trace . Insights . Types . InsightModel > {
31+ override internalName = 'test-insight' ;
32+ protected override hasAskAISupport = true ;
33+ override createOverlays ( ) : TimelineOverlay [ ] {
34+ return [ ] ;
35+ }
36+ override renderContent ( ) : Lit . LitTemplate {
37+ return html `< div > test content</ div > ` ;
38+ }
39+ }
40+ customElements . define ( 'test-insight-component-no-ai-support' , TestInsightComponentNoAISupport ) ;
41+ customElements . define ( 'test-insight-component-ai-support' , TestInsightComponentWithAISupport ) ;
3142
3243 describe ( 'sidebar insight component rendering' , ( ) => {
3344 it ( 'renders insight title even when not active' , async ( ) => {
34- const component = new TestInsightComponent ( ) ;
45+ const component = new TestInsightComponentNoAISupport ( ) ;
3546 component . selected = false ;
3647 component . model = {
3748 insightKey : 'LCPPhases' ,
@@ -57,7 +68,7 @@ describeWithEnvironment('BaseInsightComponent', () => {
5768 } ) ;
5869
5970 it ( 'renders title, description and content when toggled' , async ( ) => {
60- const component = new TestInsightComponent ( ) ;
71+ const component = new TestInsightComponentNoAISupport ( ) ;
6172 component . selected = true ;
6273 component . model = {
6374 insightKey : 'LCPPhases' ,
@@ -99,8 +110,10 @@ describeWithEnvironment('BaseInsightComponent', () => {
99110 state : 'fail' ,
100111 frameId : '123' ,
101112 } as const ;
102- async function renderComponent ( ) : Promise < TestInsightComponent > {
103- const component = new TestInsightComponent ( ) ;
113+ async function renderComponent ( { insightHasAISupport} : { insightHasAISupport : boolean } ) :
114+ Promise < TestInsightComponentNoAISupport | TestInsightComponentWithAISupport > {
115+ const component =
116+ insightHasAISupport ? new TestInsightComponentWithAISupport ( ) : new TestInsightComponentNoAISupport ( ) ;
104117 component . selected = true ;
105118 component . model = FAKE_LCP_MODEL ;
106119 // We don't need a real trace for these tests.
@@ -111,27 +124,40 @@ describeWithEnvironment('BaseInsightComponent', () => {
111124 return component ;
112125 }
113126
114- it ( 'renders the "Ask AI" button when perf insights AI is enabled' , async ( ) => {
127+ it ( 'renders the "Ask AI" button when perf insights AI is enabled and the Insight supports it ' , async ( ) => {
115128 updateHostConfig ( {
116129 devToolsAiAssistancePerformanceAgent : {
117130 enabled : true ,
118131 insightsEnabled : true ,
119132 }
120133 } ) ;
121- const component = await renderComponent ( ) ;
134+ const component = await renderComponent ( { insightHasAISupport : true } ) ;
122135 assert . isOk ( component . shadowRoot ) ;
123136 const button = component . shadowRoot . querySelector ( 'devtools-button[data-insights-ask-ai]' ) ;
124137 assert . isOk ( button ) ;
125138 } ) ;
126139
140+ it ( 'does not show the button if the feature is enabled but the Insight does not support it' , async ( ) => {
141+ updateHostConfig ( {
142+ devToolsAiAssistancePerformanceAgent : {
143+ enabled : true ,
144+ insightsEnabled : true ,
145+ }
146+ } ) ;
147+ const component = await renderComponent ( { insightHasAISupport : false } ) ;
148+ assert . isOk ( component . shadowRoot ) ;
149+ const button = component . shadowRoot . querySelector ( 'devtools-button[data-insights-ask-ai]' ) ;
150+ assert . isNull ( button ) ;
151+ } ) ;
152+
127153 it ( 'sets the context when the user clicks the button' , async ( ) => {
128154 updateHostConfig ( {
129155 devToolsAiAssistancePerformanceAgent : {
130156 enabled : true ,
131157 insightsEnabled : true ,
132158 }
133159 } ) ;
134- const component = await renderComponent ( ) ;
160+ const component = await renderComponent ( { insightHasAISupport : true } ) ;
135161 assert . isOk ( component . shadowRoot ) ;
136162 const button = component . shadowRoot . querySelector ( 'devtools-button[data-insights-ask-ai]' ) ;
137163 assert . isOk ( button ) ;
@@ -152,7 +178,7 @@ describeWithEnvironment('BaseInsightComponent', () => {
152178 it ( 'clears the active context when it gets toggled shut' , async ( ) => {
153179 const FAKE_ACTIVE_INSIGHT = { } as unknown as Utils . InsightAIContext . ActiveInsight ;
154180 UI . Context . Context . instance ( ) . setFlavor ( Utils . InsightAIContext . ActiveInsight , FAKE_ACTIVE_INSIGHT ) ;
155- const component = await renderComponent ( ) ;
181+ const component = await renderComponent ( { insightHasAISupport : true } ) ;
156182 const header = component . shadowRoot ?. querySelector ( 'header' ) ;
157183 assert . isOk ( header ) ;
158184 dispatchClickEvent ( header ) ;
@@ -166,7 +192,8 @@ describeWithEnvironment('BaseInsightComponent', () => {
166192 enabled : false ,
167193 }
168194 } ) ;
169- const component = await renderComponent ( ) ;
195+ const component = await renderComponent (
196+ { insightHasAISupport : true } ) ; // The Insight supports it, but the feature is not enabled
170197 assert . isOk ( component . shadowRoot ) ;
171198 const button = component . shadowRoot . querySelector ( 'devtools-button[data-insights-ask-ai]' ) ;
172199 assert . isNull ( button ) ;
@@ -179,7 +206,7 @@ describeWithEnvironment('BaseInsightComponent', () => {
179206 insightsEnabled : false ,
180207 }
181208 } ) ;
182- const component = await renderComponent ( ) ;
209+ const component = await renderComponent ( { insightHasAISupport : true } ) ;
183210 assert . isOk ( component . shadowRoot ) ;
184211 const button = component . shadowRoot . querySelector ( 'devtools-button[data-insights-ask-ai]' ) ;
185212 assert . isNull ( button ) ;
0 commit comments