Skip to content

Commit ee8f643

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[AiAssistance] Move toolbar to use LitHtml
Fixed: 396611915 Change-Id: Icd87972bf92cf1b1afed14fab45e6b2168325aab Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6278505 Reviewed-by: Nikolay Vitkov <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]>
1 parent 037082b commit ee8f643

File tree

6 files changed

+132
-130
lines changed

6 files changed

+132
-130
lines changed

front_end/panels/ai_assistance/AiAssistancePanel.test.ts

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
mockAidaClient
1515
} from '../../testing/AiAssistanceHelpers.js';
1616
import {findMenuItemWithLabel, getMenu} from '../../testing/ContextMenuHelpers.js';
17-
import {dispatchClickEvent} from '../../testing/DOMHelpers.js';
1817
import {createTarget, registerNoopActions, updateHostConfig} from '../../testing/EnvironmentHelpers.js';
1918
import {expectCall} from '../../testing/ExpectStubCall.js';
2019
import {describeWithMockConnection} from '../../testing/MockConnection.js';
@@ -113,15 +112,6 @@ describeWithMockConnection('AI Assistance Panel', () => {
113112
});
114113

115114
describe('rating', () => {
116-
it('renders a button linking to settings', async () => {
117-
const stub = sinon.stub(UI.ViewManager.ViewManager.instance(), 'showView');
118-
const {panel} = await createAiAssistancePanel();
119-
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'Settings\']');
120-
assert.instanceOf(button, HTMLElement);
121-
button.click();
122-
assert.isTrue(stub.calledWith('chrome-ai'));
123-
});
124-
125115
it('should allow logging if configured', async () => {
126116
updateHostConfig({
127117
aidaAvailability: {
@@ -378,6 +368,15 @@ describeWithMockConnection('AI Assistance Panel', () => {
378368
});
379369
});
380370

371+
describe('toolbar actions', () => {
372+
it('should show chrome-ai view on settings click', async () => {
373+
const stub = sinon.stub(UI.ViewManager.ViewManager.instance(), 'showView');
374+
const {initialViewInput} = await createAiAssistancePanel();
375+
initialViewInput.onSettingsClick();
376+
assert.isTrue(stub.calledWith('chrome-ai'));
377+
});
378+
});
379+
381380
describe('history interactions', () => {
382381
it('should have empty messages after new chat', async () => {
383382
const {panel, expectViewUpdate} =
@@ -407,10 +406,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
407406
]);
408407

409408
const updatedViewInputAfterNewChat = await expectViewUpdate(() => {
410-
// TODO: remove DOM access
411-
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'New chat\']');
412-
assert.instanceOf(button, HTMLElement);
413-
dispatchClickEvent(button);
409+
updatedViewInputAfterMessage.onNewChatClick();
414410
});
415411

416412
assert.deepEqual(updatedViewInputAfterNewChat.messages, []);
@@ -451,10 +447,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
451447
},
452448
]);
453449
const updatedViewInputAfterNewChat = await expectViewUpdate(() => {
454-
// TODO: remove DOM access
455-
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'New chat\']');
456-
assert.instanceOf(button, HTMLElement);
457-
dispatchClickEvent(button);
450+
updatedViewInputAfterMessage.onNewChatClick();
458451
});
459452

460453
assert.deepEqual(updatedViewInputAfterNewChat.messages, []);
@@ -497,10 +490,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
497490
},
498491
]);
499492
const updatedViewInputAfterNewChat = await expectViewUpdate(() => {
500-
// TODO: remove DOM access
501-
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'New chat\']');
502-
assert.instanceOf(button, HTMLElement);
503-
dispatchClickEvent(button);
493+
updatedViewInputAfterMessage.onNewChatClick();
504494
});
505495

506496
assert.deepEqual(updatedViewInputAfterNewChat.messages, []);
@@ -543,10 +533,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
543533
},
544534
]);
545535
const updatedViewInputAfterNewChat = await expectViewUpdate(() => {
546-
// TODO: remove DOM access
547-
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'New chat\']');
548-
assert.instanceOf(button, HTMLElement);
549-
dispatchClickEvent(button);
536+
updatedViewInputAfterMessage.onNewChatClick();
550537
});
551538

552539
assert.deepEqual(updatedViewInputAfterNewChat.messages, []);
@@ -582,7 +569,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
582569
},
583570
]);
584571

585-
await expectViewUpdate(() => {
572+
const updatedViewInputAfterSwitchToNetwork = await expectViewUpdate(() => {
586573
panel.handleAction('drjones.network-floating-button');
587574
});
588575
await view.lastCall.args[0].onTextSubmit('User question to DrJones?');
@@ -601,11 +588,8 @@ describeWithMockConnection('AI Assistance Panel', () => {
601588
},
602589
]);
603590

604-
// TODO: this should not look into DOM.
605-
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'History\']');
606-
assert.instanceOf(button, HTMLElement);
607591
const contextMenu = getMenu(() => {
608-
dispatchClickEvent(button);
592+
updatedViewInputAfterSwitchToNetwork.onHistoryClick(new MouseEvent('click'));
609593
});
610594
const freestylerEntry = findMenuItemWithLabel(contextMenu.defaultSection(), 'User question to Freestyler?')!;
611595
assert.isDefined(freestylerEntry);
@@ -679,10 +663,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
679663
]);
680664

681665
const updatedViewInputAfterDelete = await expectViewUpdate(() => {
682-
// TODO: remove DOM lookup.
683-
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'Delete local chat\']');
684-
assert.instanceOf(button, HTMLElement);
685-
dispatchClickEvent(button);
666+
updatedViewInputAfterMessage.onDeleteClick();
686667
});
687668
assert.deepEqual(updatedViewInputAfterDelete.messages, []);
688669
assert.isUndefined(updatedViewInputAfterDelete.agentType);
@@ -719,10 +700,7 @@ describeWithMockConnection('AI Assistance Panel', () => {
719700
},
720701
]);
721702
const updatedViewInputAfterDelete = await expectViewUpdate(() => {
722-
// TODO: remove DOM lookup.
723-
const button = panel.contentElement.querySelector('devtools-button[aria-label=\'Delete local chat\']');
724-
assert.instanceOf(button, HTMLElement);
725-
dispatchClickEvent(button);
703+
updatedViewInputAfterMessage.onDeleteClick();
726704
});
727705
assert.deepEqual(updatedViewInputAfterDelete.messages, []);
728706
assert.deepEqual(updatedViewInputAfterDelete.agentType, AiAssistance.AgentType.STYLING);
@@ -774,26 +752,20 @@ describeWithMockConnection('AI Assistance Panel', () => {
774752
},
775753
]);
776754

777-
// TODO: remove poking into DOM.
778-
let button = panel.contentElement.querySelector('devtools-button[aria-label=\'History\']');
779-
assert.instanceOf(button, HTMLElement);
780755
let contextMenu = getMenu(() => {
781-
dispatchClickEvent(button!);
756+
updatedViewInputAfterMessageToNetwork.onHistoryClick(new MouseEvent('click'));
782757
});
783758
const clearAll = findMenuItemWithLabel(contextMenu.footerSection(), 'Clear local chats')!;
784759
assert.isDefined(clearAll);
785-
await expectViewUpdate(() => {
760+
const updatedViewInputAfterClearAll = await expectViewUpdate(() => {
786761
contextMenu.invokeHandler(clearAll.id());
787762
});
788763
assert.deepEqual(view.lastCall.args[0].messages, []);
789764
assert.isUndefined(view.lastCall.args[0].agentType);
790-
791765
contextMenu.discard();
792766

793-
button = panel.contentElement.querySelector('devtools-button[aria-label=\'History\']');
794-
assert.instanceOf(button, HTMLElement);
795767
contextMenu = getMenu(() => {
796-
dispatchClickEvent(button);
768+
updatedViewInputAfterClearAll.onHistoryClick(new MouseEvent('click'));
797769
});
798770
const menuItem = findMenuItemWithLabel(contextMenu.defaultSection(), 'No past conversations');
799771
assert(menuItem);

0 commit comments

Comments
 (0)