@@ -11,17 +11,11 @@ import {createViewFunctionStub, type ViewFunctionStub} from '../../../testing/Vi
1111import * as AiAssistance from '../ai_assistance.js' ;
1212
1313describeWithEnvironment ( 'ChatMessage' , ( ) => {
14- function createComponent ( props : AiAssistance . ChatMessage . MessageInput ) :
14+ function createComponent ( props : Partial < AiAssistance . ChatMessage . MessageInput > = { } ) :
1515 [ ViewFunctionStub < typeof AiAssistance . ChatMessage . ChatMessage > , AiAssistance . ChatMessage . ChatMessage ] {
1616 const view = createViewFunctionStub ( AiAssistance . ChatMessage . ChatMessage ) ;
1717 const component = new AiAssistance . ChatMessage . ChatMessage ( undefined , view ) ;
18- Object . assign ( component , props ) ;
19- component . wasShown ( ) ;
20- return [ view , component ] ;
21- }
22-
23- it ( 'should show the feedback form when canShowFeedbackForm is true' , async ( ) => {
24- const [ view ] = createComponent ( {
18+ Object . assign ( component , {
2519 message : {
2620 entity : AiAssistance . ChatMessage . ChatMessageEntity . MODEL ,
2721 parts : [ ] ,
@@ -36,6 +30,15 @@ describeWithEnvironment('ChatMessage', () => {
3630 onSuggestionClick : sinon . stub ( ) ,
3731 onCopyResponseClick : sinon . stub ( ) ,
3832 onFeedbackSubmit : sinon . stub ( ) ,
33+ ...props ,
34+ } ) ;
35+ component . wasShown ( ) ;
36+ return [ view , component ] ;
37+ }
38+
39+ it ( 'should show the feedback form when canShowFeedbackForm is true' , async ( ) => {
40+ const [ view ] = createComponent ( {
41+ canShowFeedbackForm : true ,
3942 } ) ;
4043
4144 sinon . assert . callCount ( view , 1 ) ;
@@ -54,20 +57,7 @@ describeWithEnvironment('ChatMessage', () => {
5457
5558 it ( 'should not show the feedback form when canShowFeedbackForm is false' , async ( ) => {
5659 const [ view ] = createComponent ( {
57- message : {
58- entity : AiAssistance . ChatMessage . ChatMessageEntity . MODEL ,
59- parts : [ ] ,
60- rpcId : 99 ,
61- } ,
62- isLoading : false ,
63- isReadOnly : false ,
64- isLastMessage : true ,
65- userInfo : { } ,
66- markdownRenderer : new AiAssistance . MarkdownRendererWithCodeBlock ( ) ,
6760 canShowFeedbackForm : false ,
68- onSuggestionClick : sinon . stub ( ) ,
69- onCopyResponseClick : sinon . stub ( ) ,
70- onFeedbackSubmit : sinon . stub ( ) ,
7161 } ) ;
7262
7363 sinon . assert . callCount ( view , 1 ) ;
@@ -85,20 +75,7 @@ describeWithEnvironment('ChatMessage', () => {
8575
8676 it ( 'should disable the submit button when the input is empty' , async ( ) => {
8777 const [ view ] = createComponent ( {
88- message : {
89- entity : AiAssistance . ChatMessage . ChatMessageEntity . MODEL ,
90- parts : [ ] ,
91- rpcId : 99 ,
92- } ,
93- isLoading : false ,
94- isReadOnly : false ,
9578 isLastMessage : false ,
96- userInfo : { } ,
97- markdownRenderer : new AiAssistance . MarkdownRendererWithCodeBlock ( ) ,
98- canShowFeedbackForm : true ,
99- onSuggestionClick : sinon . stub ( ) ,
100- onCopyResponseClick : sinon . stub ( ) ,
101- onFeedbackSubmit : sinon . stub ( ) ,
10279 } ) ;
10380
10481 sinon . assert . callCount ( view , 1 ) ;
@@ -131,21 +108,72 @@ describeWithEnvironment('ChatMessage', () => {
131108 entity : AiAssistance . ChatMessage . ChatMessageEntity . MODEL ,
132109 parts : [ ] ,
133110 } ,
134- isLoading : false ,
135- isReadOnly : false ,
136- isLastMessage : true ,
137- userInfo : { } ,
138- markdownRenderer : new AiAssistance . MarkdownRendererWithCodeBlock ( ) ,
139- canShowFeedbackForm : true ,
140- onSuggestionClick : sinon . stub ( ) ,
141- onCopyResponseClick : sinon . stub ( ) ,
142- onFeedbackSubmit : sinon . stub ( ) ,
143111 } ) ;
144112
145113 sinon . assert . callCount ( view , 1 ) ;
146114 expect ( view . input . showRateButtons ) . equals ( false ) ;
147115 } ) ;
148116
117+ it ( 'should show actions when it is not the last message and it is loading' , async ( ) => {
118+ const [ view ] = createComponent ( {
119+ isLoading : true ,
120+ isLastMessage : false ,
121+ } ) ;
122+
123+ sinon . assert . callCount ( view , 1 ) ;
124+ expect ( view . input . showActions ) . equals ( true ) ;
125+ } ) ;
126+
127+ it ( 'should not show actions when it is the last message and it is loading' , async ( ) => {
128+ const [ view ] = createComponent ( {
129+ isLoading : true ,
130+ isLastMessage : true ,
131+ } ) ;
132+
133+ sinon . assert . callCount ( view , 1 ) ;
134+ expect ( view . input . showActions ) . equals ( false ) ;
135+ } ) ;
136+
137+ it ( 'should not show suggestions when it is not the last message' , async ( ) => {
138+ const [ view ] = createComponent ( {
139+ message : {
140+ entity : AiAssistance . ChatMessage . ChatMessageEntity . MODEL ,
141+ parts : [
142+ {
143+ type : 'answer' ,
144+ text : 'test' ,
145+ suggestions : [ 'suggestion' ] ,
146+ } ,
147+ ] ,
148+ rpcId : 99 ,
149+ } ,
150+ isLastMessage : false ,
151+ } ) ;
152+
153+ sinon . assert . callCount ( view , 1 ) ;
154+ expect ( view . input . suggestions ) . equals ( undefined ) ;
155+ } ) ;
156+
157+ it ( 'should show suggestions when it is the last message' , async ( ) => {
158+ const [ view ] = createComponent ( {
159+ message : {
160+ entity : AiAssistance . ChatMessage . ChatMessageEntity . MODEL ,
161+ parts : [
162+ {
163+ type : 'answer' ,
164+ text : 'test' ,
165+ suggestions : [ 'suggestion' ] ,
166+ } ,
167+ ] ,
168+ rpcId : 99 ,
169+ } ,
170+ isLastMessage : true ,
171+ } ) ;
172+
173+ sinon . assert . callCount ( view , 1 ) ;
174+ expect ( view . input . suggestions ) . deep . equals ( [ 'suggestion' ] ) ;
175+ } ) ;
176+
149177 describe ( 'view' , ( ) => {
150178 it ( 'renders a minimal model message' , async ( ) => {
151179 const target = document . createElement ( 'div' ) ;
@@ -166,6 +194,7 @@ describeWithEnvironment('ChatMessage', () => {
166194 isSubmitButtonDisabled : false ,
167195 isShowingFeedbackForm : true ,
168196 isLastMessage : true ,
197+ showActions : true ,
169198 message : {
170199 entity : AiAssistance . ChatMessage . ChatMessageEntity . MODEL ,
171200 parts : [ ] ,
@@ -201,6 +230,7 @@ describeWithEnvironment('ChatMessage', () => {
201230 isSubmitButtonDisabled : false ,
202231 isShowingFeedbackForm : true ,
203232 isLastMessage : true ,
233+ showActions : true ,
204234 message : {
205235 entity : AiAssistance . ChatMessage . ChatMessageEntity . MODEL ,
206236 rpcId : 99 ,
@@ -253,6 +283,7 @@ describeWithEnvironment('ChatMessage', () => {
253283 isSubmitButtonDisabled : false ,
254284 isShowingFeedbackForm : false ,
255285 isLastMessage : true ,
286+ showActions : false ,
256287 message : {
257288 entity : AiAssistance . ChatMessage . ChatMessageEntity . USER ,
258289 text : 'Can you help me fix specific CSS rules?' ,
0 commit comments