Skip to content

Commit 75fdad2

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[AiAssistance] Make ChatView more presentational
Previously, it was deciding on "what" text to render based on the parameters. Now, for the text that's changing based on the business logic; it accepts an input that is supplied by the AiAssistancePanel. Drive-by: * Previously, after `aidaAvailability` is set in panel construction, it was getting updated after a call to `checkAccessPreconditions` when it's shown. I have stubbed that as well and added a helper function to stub it in tests. Bug: 394005781 Change-Id: Ie111d397dee7c5cd117c651271c2e57453898160 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6298050 Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]>
1 parent dadaaf7 commit 75fdad2

File tree

5 files changed

+427
-299
lines changed

5 files changed

+427
-299
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,13 @@ describeWithMockConnection('AI Assistance Panel', () => {
9393
it('updates when the user logs in', async () => {
9494
Common.Settings.moduleSetting('ai-assistance-enabled').set(true);
9595

96-
const {initialViewInput, expectViewUpdate} =
96+
const {initialViewInput, expectViewUpdate, stubAidaCheckAccessPreconditions} =
9797
await createAiAssistancePanel({aidaAvailability: Host.AidaClient.AidaAccessPreconditions.NO_ACCOUNT_EMAIL});
9898

9999
assert.strictEqual(initialViewInput.state, AiAssistance.State.CHAT_VIEW);
100100
assert.strictEqual(initialViewInput.aidaAvailability, Host.AidaClient.AidaAccessPreconditions.NO_ACCOUNT_EMAIL);
101101

102-
sinon.stub(Host.AidaClient.AidaClient, 'checkAccessPreconditions')
103-
.returns(Promise.resolve(Host.AidaClient.AidaAccessPreconditions.AVAILABLE));
102+
stubAidaCheckAccessPreconditions(Host.AidaClient.AidaAccessPreconditions.AVAILABLE);
104103

105104
const updatedViewInput = await expectViewUpdate(() => {
106105
Host.AidaClient.HostConfigTracker.instance().dispatchEventToListeners(
@@ -1017,6 +1016,120 @@ describeWithMockConnection('AI Assistance Panel', () => {
10171016
]);
10181017
});
10191018

1019+
describe('chat input', () => {
1020+
describe('disabled state', () => {
1021+
it('should be disabled when ai assistance enabled setting is disabled and show followTheSteps placeholder',
1022+
async () => {
1023+
Common.Settings.moduleSetting('ai-assistance-enabled').setDisabled(true);
1024+
1025+
const {initialViewInput} = await createAiAssistancePanel();
1026+
1027+
assert.isTrue(initialViewInput.isTextInputDisabled);
1028+
assert.strictEqual(initialViewInput.inputPlaceholder, 'Follow the steps above to ask a question');
1029+
assert.strictEqual(
1030+
initialViewInput.disclaimerText, 'This is an experimental AI feature and won\'t always get it right.');
1031+
});
1032+
1033+
it('should be disabled when ai assistance setting is marked as false and show followTheSteps placeholder',
1034+
async () => {
1035+
Common.Settings.moduleSetting('ai-assistance-enabled').set(false);
1036+
1037+
const {initialViewInput} = await createAiAssistancePanel();
1038+
1039+
assert.isTrue(initialViewInput.isTextInputDisabled);
1040+
assert.strictEqual(initialViewInput.inputPlaceholder, 'Follow the steps above to ask a question');
1041+
assert.strictEqual(
1042+
initialViewInput.disclaimerText, 'This is an experimental AI feature and won\'t always get it right.');
1043+
});
1044+
1045+
it('should be disabled when the user is blocked by age and show followTheSteps placeholder', async () => {
1046+
Common.Settings.moduleSetting('ai-assistance-enabled').set(true);
1047+
updateHostConfig({
1048+
aidaAvailability: {
1049+
blockedByAge: true,
1050+
},
1051+
});
1052+
1053+
const {initialViewInput} = await createAiAssistancePanel();
1054+
1055+
assert.isTrue(initialViewInput.isTextInputDisabled);
1056+
assert.strictEqual(initialViewInput.inputPlaceholder, 'Follow the steps above to ask a question');
1057+
assert.strictEqual(
1058+
initialViewInput.disclaimerText, 'This is an experimental AI feature and won\'t always get it right.');
1059+
});
1060+
1061+
it('should be disabled when Aida availability status is not AVAILABLE', async () => {
1062+
Common.Settings.moduleSetting('ai-assistance-enabled').set(true);
1063+
const {initialViewInput} =
1064+
await createAiAssistancePanel({aidaAvailability: Host.AidaClient.AidaAccessPreconditions.NO_INTERNET});
1065+
1066+
assert.isTrue(initialViewInput.isTextInputDisabled);
1067+
});
1068+
1069+
it('should be disabled when the next message is blocked by cross origin and show crossOriginError placeholder',
1070+
async () => {
1071+
Common.Settings.moduleSetting('ai-assistance-enabled').set(true);
1072+
const networkRequest = createNetworkRequest({
1073+
url: urlString`https://a.test`,
1074+
});
1075+
UI.Context.Context.instance().setFlavor(SDK.NetworkRequest.NetworkRequest, networkRequest);
1076+
1077+
const {panel, expectViewUpdate} = await createAiAssistancePanel({
1078+
aidaClient: mockAidaClient([
1079+
[{explanation: 'test'}],
1080+
]),
1081+
});
1082+
const updatedViewInput = await expectViewUpdate(() => {
1083+
panel.handleAction('drjones.network-floating-button');
1084+
});
1085+
1086+
assert.isFalse(updatedViewInput.blockedByCrossOrigin);
1087+
assert.strictEqual(updatedViewInput.selectedContext?.getItem(), networkRequest);
1088+
1089+
// Send a query for https://a.test.
1090+
await expectViewUpdate(() => {
1091+
panel.handleAction('drjones.network-floating-button');
1092+
updatedViewInput.onTextSubmit('test');
1093+
});
1094+
1095+
// Change context to https://b.test.
1096+
const networkRequest2 = createNetworkRequest({
1097+
url: urlString`https://b.test`,
1098+
});
1099+
UI.Context.Context.instance().setFlavor(SDK.NetworkRequest.NetworkRequest, networkRequest2);
1100+
1101+
const updatedViewInputWithCrossOriginContext = await expectViewUpdate(() => {
1102+
panel.handleAction('drjones.network-floating-button');
1103+
});
1104+
1105+
assert.isTrue(updatedViewInputWithCrossOriginContext.blockedByCrossOrigin);
1106+
assert.isTrue(updatedViewInputWithCrossOriginContext.isTextInputDisabled);
1107+
assert.strictEqual(
1108+
updatedViewInputWithCrossOriginContext.inputPlaceholder,
1109+
'To talk about data from another origin, start a new chat');
1110+
});
1111+
1112+
it('should be disabled when there is no selected context and show inputPlaceholderForStylingNoContext',
1113+
async () => {
1114+
updateHostConfig({
1115+
devToolsFreestyler: {
1116+
enabled: true,
1117+
},
1118+
});
1119+
Common.Settings.moduleSetting('ai-assistance-enabled').set(true);
1120+
const {panel, expectViewUpdate} =
1121+
await createAiAssistancePanel({aidaAvailability: Host.AidaClient.AidaAccessPreconditions.AVAILABLE});
1122+
const updatedViewInput = await expectViewUpdate(() => {
1123+
panel.handleAction('freestyler.elements-floating-button');
1124+
});
1125+
1126+
assert.isNull(updatedViewInput.selectedContext);
1127+
assert.isTrue(updatedViewInput.isTextInputDisabled);
1128+
assert.strictEqual(updatedViewInput.inputPlaceholder, 'Select an element to ask a question');
1129+
});
1130+
});
1131+
});
1132+
10201133
describe('multimodal input', () => {
10211134
function mockScreenshotModel() {
10221135
const target = createTarget();

0 commit comments

Comments
 (0)