Skip to content

Commit cd31c96

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Fix regressed action row
Bug: none Change-Id: Ic9c95eac041eff1b0aa216241c0e0f3406b0255d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7573132 Auto-Submit: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Nikolay Vitkov <nvitkov@chromium.org> Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org>
1 parent b7c6b7d commit cd31c96

2 files changed

Lines changed: 78 additions & 45 deletions

File tree

front_end/panels/ai_assistance/components/ChatMessage.test.ts

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@ import {createViewFunctionStub, type ViewFunctionStub} from '../../../testing/Vi
1111
import * as AiAssistance from '../ai_assistance.js';
1212

1313
describeWithEnvironment('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?',

front_end/panels/ai_assistance/components/ChatMessage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export interface RatingViewInput {
221221
export interface ActionViewInput {
222222
onReportClick: () => void;
223223
onCopyResponseClick: () => void;
224+
showActions: boolean;
224225
}
225226

226227
export interface SuggestionViewInput {
@@ -330,7 +331,7 @@ export const DEFAULT_VIEW = (input: ChatMessageViewInput, output: ViewOutput, ta
330331
},
331332
)}
332333
${renderError(message)}
333-
${input.isLastMessage && !input.isLoading ? renderActions(input, output) : Lit.nothing}
334+
${input.showActions ? renderActions(input, output) : Lit.nothing}
334335
</section>
335336
`, target);
336337
// clang-format on
@@ -812,8 +813,9 @@ export class ChatMessage extends UI.Widget.Widget {
812813
onInputChange: this.#handleInputChange.bind(this),
813814
isSubmitButtonDisabled: this.#isSubmitButtonDisabled,
814815
// Props for actions logic
816+
showActions: !(this.isLastMessage && this.isLoading),
815817
showRateButtons: this.message.entity === ChatMessageEntity.MODEL && !!this.message.rpcId,
816-
suggestions: (this.message.entity === ChatMessageEntity.MODEL && !this.isReadOnly &&
818+
suggestions: (this.isLastMessage && this.message.entity === ChatMessageEntity.MODEL && !this.isReadOnly &&
817819
this.message.parts.at(-1)?.type === 'answer') ?
818820
(this.message.parts.at(-1) as AnswerPart).suggestions :
819821
undefined,

0 commit comments

Comments
 (0)