Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/test/browser/componentFixtures/sessions/aiCustomizationWelcomePages.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 { constObservable } from '../../../../../base/common/observable.js';
8
import { URI } from '../../../../../base/common/uri.js';
9
import { CancellationToken } from '../../../../../base/common/cancellation.js';
10
import { mock } from '../../../../../base/test/common/mock.js';
11
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
12
import { IChatPromptSlashCommand, PromptsStorage } from '../../../../contrib/chat/common/promptSyntax/service/promptsService.js';
13
import { AICustomizationManagementSection } from '../../../../contrib/chat/browser/aiCustomization/aiCustomizationManagement.js';
14
import { IAICustomizationWorkspaceService, IStorageSourceFilter } from '../../../../contrib/chat/common/aiCustomizationWorkspaceService.js';
15
import { PromptsType } from '../../../../contrib/chat/common/promptSyntax/promptTypes.js';
16
import { AICustomizationWelcomePage } from '../../../../contrib/chat/browser/aiCustomization/aiCustomizationWelcomePage.js';
17
import { ComponentFixtureContext, defineComponentFixture, defineThemedFixtureGroup } from '../fixtureUtils.js';
18
import { NullHoverService } from '../../../../../platform/hover/test/browser/nullHoverService.js';
19
20
import '../../../../../platform/theme/common/colors/inputColors.js';
21
import '../../../../../platform/theme/common/colors/listColors.js';
22
import '../../../../contrib/chat/browser/aiCustomization/media/aiCustomizationManagement.css';
23
24
const visibleSections = new Set<AICustomizationManagementSection>([
25
AICustomizationManagementSection.Agents,
26
AICustomizationManagementSection.Skills,
27
AICustomizationManagementSection.Instructions,
28
AICustomizationManagementSection.Prompts,
29
AICustomizationManagementSection.Hooks,
30
AICustomizationManagementSection.McpServers,
31
AICustomizationManagementSection.Plugins,
32
]);
33
34
const defaultFilter: IStorageSourceFilter = {
35
sources: [PromptsStorage.local, PromptsStorage.user, PromptsStorage.extension, PromptsStorage.plugin],
36
};
37
38
function createMockWorkspaceService(): IAICustomizationWorkspaceService {
39
return new class extends mock<IAICustomizationWorkspaceService>() {
40
override readonly isSessionsWindow = false;
41
override readonly managementSections = Array.from(visibleSections);
42
override readonly welcomePageFeatures = {
43
showGettingStartedBanner: true,
44
};
45
override readonly activeProjectRoot = constObservable(URI.file('/workspace'));
46
override readonly hasOverrideProjectRoot = constObservable(false);
47
override getActiveProjectRoot(): URI {
48
return URI.file('/workspace');
49
}
50
override getStorageSourceFilter(_type: PromptsType): IStorageSourceFilter {
51
return defaultFilter;
52
}
53
override async commitFiles(): Promise<void> { }
54
override async deleteFiles(): Promise<void> { }
55
override async generateCustomization(): Promise<void> { }
56
override setOverrideProjectRoot(): void { }
57
override clearOverrideProjectRoot(): void { }
58
override async getFilteredPromptSlashCommands(_token: CancellationToken): Promise<readonly IChatPromptSlashCommand[]> {
59
return [];
60
}
61
override getSkillUIIntegrations(): ReadonlyMap<string, string> {
62
return new Map();
63
}
64
}();
65
}
66
67
function createMockCommandService(): ICommandService {
68
return new class extends mock<ICommandService>() {
69
override async executeCommand<R = unknown>(_commandId: string, ..._args: unknown[]): Promise<R | undefined> {
70
return undefined;
71
}
72
}();
73
}
74
75
function createHost(container: HTMLElement): HTMLElement {
76
container.style.width = '1024px';
77
container.style.height = '960px';
78
const editor = DOM.append(container, DOM.$('.ai-customization-management-editor'));
79
editor.style.height = '100%';
80
const content = DOM.append(editor, DOM.$('.management-content'));
81
return DOM.append(content, DOM.$('.content-inner'));
82
}
83
84
function renderWelcomePage(ctx: ComponentFixtureContext): void {
85
const host = createHost(ctx.container);
86
const workspaceService = createMockWorkspaceService();
87
const page = ctx.disposableStore.add(new AICustomizationWelcomePage(
88
host,
89
workspaceService.welcomePageFeatures,
90
{
91
selectSection: () => { },
92
selectSectionWithMarketplace: () => { },
93
closeEditor: () => { },
94
prefillChat: () => { },
95
},
96
createMockCommandService(),
97
workspaceService,
98
NullHoverService,
99
));
100
page.rebuildCards(visibleSections);
101
}
102
103
export default defineThemedFixtureGroup({ path: 'chat/aiCustomizations/' }, {
104
WelcomePage: defineComponentFixture({
105
labels: { kind: 'screenshot' },
106
render: renderWelcomePage,
107
}),
108
});
109
110