Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/test/browser/componentFixtures/chat/chatTerminalCollapsible.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 * as dom from '../../../../../base/browser/dom.js';
7
import { Event } from '../../../../../base/common/event.js';
8
import { observableValue } from '../../../../../base/common/observable.js';
9
import { mock, upcastPartial } from '../../../../../base/test/common/mock.js';
10
import type { IChatContentPartRenderContext, InlineTextModelCollection } from '../../../../contrib/chat/browser/widget/chatContentParts/chatContentParts.js';
11
import type { IChatResponseViewModel } from '../../../../contrib/chat/common/model/chatViewModel.js';
12
import { ChatTerminalThinkingCollapsibleWrapper } from '../../../../contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolProgressPart.js';
13
import { ComponentFixtureContext, createEditorServices, defineComponentFixture, defineThemedFixtureGroup } from '../fixtureUtils.js';
14
15
import '../../../../contrib/chat/browser/widget/media/chat.css';
16
17
function createMockContext(): IChatContentPartRenderContext {
18
return {
19
element: new class extends mock<IChatResponseViewModel>() { }(),
20
elementIndex: 0,
21
container: document.createElement('div'),
22
content: [],
23
contentIndex: 0,
24
editorPool: undefined!,
25
codeBlockStartIndex: 0,
26
treeStartIndex: 0,
27
diffEditorPool: undefined!,
28
currentWidth: observableValue('currentWidth', 400),
29
onDidChangeVisibility: Event.None,
30
inlineTextModels: upcastPartial<InlineTextModelCollection>({}),
31
};
32
}
33
34
function renderCollapsible(context: ComponentFixtureContext, commandText: string, isSandboxWrapped: boolean, isComplete: boolean): void {
35
const { container, disposableStore } = context;
36
37
const instantiationService = createEditorServices(disposableStore, {
38
colorTheme: context.theme,
39
});
40
41
container.style.width = '500px';
42
container.style.padding = '8px';
43
container.classList.add('monaco-workbench');
44
45
const session = dom.$('.interactive-session');
46
container.appendChild(session);
47
48
const contentElement = dom.$('.chat-terminal-output-placeholder');
49
contentElement.textContent = '(terminal output would appear here)';
50
contentElement.style.padding = '8px';
51
contentElement.style.color = 'var(--vscode-descriptionForeground)';
52
53
const wrapper = disposableStore.add(instantiationService.createInstance(
54
ChatTerminalThinkingCollapsibleWrapper,
55
commandText,
56
isSandboxWrapped,
57
contentElement,
58
createMockContext(),
59
false,
60
isComplete,
61
));
62
63
session.appendChild(wrapper.domNode);
64
}
65
66
export default defineThemedFixtureGroup({ path: 'chat/terminalCollapsible/' }, {
67
'Ran - simple command': defineComponentFixture({
68
render: ctx => renderCollapsible(ctx, 'ls -lh', false, true),
69
}),
70
'Running - simple command': defineComponentFixture({
71
render: ctx => renderCollapsible(ctx, 'ls -lh', false, false),
72
}),
73
'Ran sandbox - simple command': defineComponentFixture({
74
render: ctx => renderCollapsible(ctx, 'ls -lh', true, true),
75
}),
76
'Running sandbox - simple command': defineComponentFixture({
77
render: ctx => renderCollapsible(ctx, 'ls -lh', true, false),
78
}),
79
'Ran - special chars': defineComponentFixture({
80
render: ctx => renderCollapsible(ctx, 'grep -rn "hello" ./src --include="*.ts"', false, true),
81
}),
82
'Ran sandbox - special chars': defineComponentFixture({
83
render: ctx => renderCollapsible(ctx, 'grep -rn "hello" ./src --include="*.ts"', true, true),
84
}),
85
'Ran - backticks': defineComponentFixture({
86
render: ctx => renderCollapsible(ctx, 'echo `date` && echo `hostname`', false, true),
87
}),
88
'Ran sandbox - backticks': defineComponentFixture({
89
render: ctx => renderCollapsible(ctx, 'echo `date` && echo `hostname`', true, true),
90
}),
91
'Ran sandbox - powershell backticks': defineComponentFixture({
92
render: ctx => renderCollapsible(ctx, 'Get-Process | Where-Object {$_.Name -eq `"notepad`"}', true, true),
93
}),
94
});
95
96