Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/agentFeedback/test/browser/agentFeedbackEditorOverlayWidget.fixture.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
7
import { toAction } from '../../../../../base/common/actions.js';
8
import { Event } from '../../../../../base/common/event.js';
9
import { IMenu, IMenuActionOptions, IMenuService, MenuId, MenuItemAction, SubmenuItemAction } from '../../../../../platform/actions/common/actions.js';
10
import { ComponentFixtureContext, createEditorServices, defineComponentFixture, defineThemedFixtureGroup, registerWorkbenchServices } from '../../../../../workbench/test/browser/componentFixtures/fixtureUtils.js';
11
import { AgentFeedbackOverlayWidget } from '../../browser/agentFeedbackEditorOverlay.js';
12
import { clearAllFeedbackActionId, navigateNextFeedbackActionId, navigatePreviousFeedbackActionId, navigationBearingFakeActionId, submitFeedbackActionId } from '../../browser/agentFeedbackEditorActions.js';
13
14
interface INavigationBearings {
15
readonly activeIdx: number;
16
readonly totalCount: number;
17
}
18
19
interface IFixtureOptions {
20
readonly navigationBearings: INavigationBearings;
21
readonly hasAgentFeedbackActions?: boolean;
22
}
23
24
class FixtureMenuService implements IMenuService {
25
constructor(private readonly _hasAgentFeedbackActions: boolean) {
26
}
27
28
declare readonly _serviceBrand: undefined;
29
30
createMenu(_id: MenuId): IMenu {
31
const navigateActions = [
32
toAction({ id: navigationBearingFakeActionId, label: 'Navigation Status', run: () => { } }),
33
toAction({ id: navigatePreviousFeedbackActionId, label: 'Previous', class: 'codicon codicon-arrow-up', run: () => { } }),
34
toAction({ id: navigateNextFeedbackActionId, label: 'Next', class: 'codicon codicon-arrow-down', run: () => { } }),
35
] as unknown as (MenuItemAction | SubmenuItemAction)[];
36
37
const submitActions = this._hasAgentFeedbackActions
38
? [
39
toAction({ id: submitFeedbackActionId, label: 'Submit', class: 'codicon codicon-send', run: () => { } }),
40
toAction({ id: clearAllFeedbackActionId, label: 'Clear', class: 'codicon codicon-clear-all', run: () => { } }),
41
] as unknown as (MenuItemAction | SubmenuItemAction)[]
42
: [];
43
44
return {
45
onDidChange: Event.None,
46
dispose: () => { },
47
getActions: () => submitActions.length > 0
48
? [
49
['navigate', navigateActions],
50
['a_submit', submitActions],
51
]
52
: [
53
['navigate', navigateActions],
54
],
55
};
56
}
57
58
getMenuActions(_id: MenuId, _contextKeyService: unknown, _options?: IMenuActionOptions) { return []; }
59
getMenuContexts() { return new Set<string>(); }
60
resetHiddenStates() { }
61
}
62
63
function renderWidget(context: ComponentFixtureContext, options: IFixtureOptions): void {
64
const scopedDisposables = context.disposableStore.add(new DisposableStore());
65
context.container.classList.add('monaco-workbench');
66
context.container.style.width = '420px';
67
context.container.style.height = '64px';
68
context.container.style.padding = '12px';
69
context.container.style.background = 'var(--vscode-editor-background)';
70
71
const instantiationService = createEditorServices(scopedDisposables, {
72
colorTheme: context.theme,
73
additionalServices: reg => {
74
registerWorkbenchServices(reg);
75
reg.defineInstance(IMenuService, new FixtureMenuService(options.hasAgentFeedbackActions ?? true));
76
},
77
});
78
79
const widget = scopedDisposables.add(instantiationService.createInstance(AgentFeedbackOverlayWidget));
80
widget.show(options.navigationBearings);
81
context.container.appendChild(widget.getDomNode());
82
}
83
84
export default defineThemedFixtureGroup({ path: 'sessions/agentFeedback/' }, {
85
ZeroOfZero: defineComponentFixture({
86
labels: { kind: 'screenshot' },
87
render: context => renderWidget(context, {
88
navigationBearings: { activeIdx: -1, totalCount: 0 },
89
hasAgentFeedbackActions: false,
90
}),
91
}),
92
93
SingleFeedback: defineComponentFixture({
94
labels: { kind: 'screenshot' },
95
render: context => renderWidget(context, {
96
navigationBearings: { activeIdx: 0, totalCount: 1 },
97
}),
98
}),
99
100
FirstOfThree: defineComponentFixture({
101
labels: { kind: 'screenshot' },
102
render: context => renderWidget(context, {
103
navigationBearings: { activeIdx: -1, totalCount: 3 },
104
}),
105
}),
106
107
ReviewOnlyTwoComments: defineComponentFixture({
108
labels: { kind: 'screenshot' },
109
render: context => renderWidget(context, {
110
navigationBearings: { activeIdx: 0, totalCount: 2 },
111
hasAgentFeedbackActions: false,
112
}),
113
}),
114
115
MiddleOfThree: defineComponentFixture({
116
labels: { kind: 'screenshot' },
117
render: context => renderWidget(context, {
118
navigationBearings: { activeIdx: 1, totalCount: 3 },
119
}),
120
}),
121
122
MixedFourComments: defineComponentFixture({
123
labels: { kind: 'screenshot' },
124
render: context => renderWidget(context, {
125
navigationBearings: { activeIdx: 2, totalCount: 4 },
126
hasAgentFeedbackActions: true,
127
}),
128
}),
129
130
LastOfThree: defineComponentFixture({
131
labels: { kind: 'screenshot' },
132
render: context => renderWidget(context, {
133
navigationBearings: { activeIdx: 2, totalCount: 3 },
134
}),
135
}),
136
});
137
138