Terminal profile enum tests, fix arg formatting

Part of #129140
This commit is contained in:
Daniel Imms 2021-07-21 18:12:01 -07:00
parent f831c8d3cb
commit 50e025e0d9
2 changed files with 80 additions and 14 deletions

View file

@ -11,19 +11,16 @@ export function createProfileSchemaEnums(detectedProfiles: ITerminalProfile[]):
values: string[] | undefined,
markdownDescriptions: string[] | undefined
} {
let values: string[] | undefined = undefined;
let markdownDescriptions: string[] | undefined = undefined;
if (detectedProfiles) {
const result = detectedProfiles.map(e => {
return {
name: e.profileName,
description: createProfileDescription(e)
};
});
values = result.map(e => e.name);
markdownDescriptions = result.map(e => e.description);
}
return { values, markdownDescriptions };
const result = detectedProfiles.map(e => {
return {
name: e.profileName,
description: createProfileDescription(e)
};
});
return {
values: result.map(e => e.name),
markdownDescriptions: result.map(e => e.description)
};
}
function createProfileDescription(profile: ITerminalProfile): string {
@ -32,7 +29,7 @@ function createProfileDescription(profile: ITerminalProfile): string {
if (typeof profile.args === 'string') {
description += `\n- args: "${profile.args}"`;
} else {
description += `\n- args: [${profile.args.length === 0 ? '' : profile.args.join(`','`)}]`;
description += `\n- args: [${profile.args.length === 0 ? '' : `'${profile.args.join(`','`)}'`}]`;
}
}
if (profile.overrideName !== undefined) {

View file

@ -0,0 +1,69 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { deepStrictEqual } from 'assert';
import { Codicon } from 'vs/base/common/codicons';
import { ITerminalProfile } from 'vs/platform/terminal/common/terminal';
import { createProfileSchemaEnums } from 'vs/platform/terminal/common/terminalProfiles';
suite('terminalProfiles', () => {
suite('createProfileSchemaEnums', () => {
test('should return an empty array when there are no profiles', () => {
deepStrictEqual(createProfileSchemaEnums([]), {
values: [],
markdownDescriptions: []
});
});
test('should return a single entry when there is one profile', () => {
const profile: ITerminalProfile = {
profileName: 'name',
path: 'path',
isDefault: true
};
deepStrictEqual(createProfileSchemaEnums([profile]), {
values: ['name'],
markdownDescriptions: ['$(terminal) name\n- path: path']
});
});
test('should show all profile information', () => {
const profile: ITerminalProfile = {
profileName: 'name',
path: 'path',
isDefault: true,
args: ['a', 'b'],
color: 'terminal.ansiRed',
env: {
c: 'd',
e: 'f'
},
icon: Codicon.zap,
overrideName: true
};
deepStrictEqual(createProfileSchemaEnums([profile]), {
values: ['name'],
markdownDescriptions: [`$(zap) name\n- path: path\n- args: ['a','b']\n- overrideName: true\n- color: terminal.ansiRed\n- env: {\"c\":\"d\",\"e\":\"f\"}`]
});
});
test('should return a multiple entries when there are multiple profiles', () => {
const profile1: ITerminalProfile = {
profileName: 'name',
path: 'path',
isDefault: true
};
const profile2: ITerminalProfile = {
profileName: 'foo',
path: 'bar',
isDefault: false
};
deepStrictEqual(createProfileSchemaEnums([profile1, profile2]), {
values: ['name', 'foo'],
markdownDescriptions: [
'$(terminal) name\n- path: path',
'$(terminal) foo\n- path: bar'
]
});
});
});
});