mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 01:25:36 -05:00
Allow adding new sqlcmd variables to sql project without DefaultValue (#23229)
This commit is contained in:
@@ -158,6 +158,7 @@ export const chooseSqlcmdVarsToModify = localize('chooseSqlcmdVarsToModify', "Ch
|
||||
export const enterNewValueForVar = (varName: string) => localize('enterNewValueForVar', "Enter new default value for variable '{0}'", varName);
|
||||
export const enterNewSqlCmdVariableName = localize('enterNewSqlCmdVariableName', "Enter new SQLCMD Variable name");
|
||||
export const enterNewSqlCmdVariableDefaultValue = (varName: string) => localize('enterNewSqlCmdVariableDefaultValue', "Enter default value for SQLCMD variable '{0}'", varName);
|
||||
export const addSqlCmdVariableWithoutDefaultValue = (varName: string) => localize('addSqlCmdVariableWithoutDefaultValue', "Add SQLCMD variable '{0}' to project without default value?", varName);
|
||||
export const sqlcmdVariableAlreadyExists = localize('sqlcmdVariableAlreadyExists', "A SQLCMD Variable with the same name already exists in this project");
|
||||
export const resetAllVars = localize('resetAllVars', "Reset all variables");
|
||||
export const createNew = localize('createNew', "Create New");
|
||||
|
||||
@@ -993,14 +993,21 @@ export class ProjectsController {
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultValue = await vscode.window.showInputBox(
|
||||
let defaultValue = await vscode.window.showInputBox(
|
||||
{
|
||||
title: constants.enterNewSqlCmdVariableDefaultValue(variableName),
|
||||
ignoreFocusOut: true
|
||||
});
|
||||
|
||||
if (!defaultValue) {
|
||||
return;
|
||||
// prompt asking if they want to add to add a sqlcmd variable without a default value
|
||||
const result = await vscode.window.showInformationMessage(constants.addSqlCmdVariableWithoutDefaultValue(variableName), constants.yesString, constants.noString);
|
||||
|
||||
if (result === constants.noString) {
|
||||
return;
|
||||
} else {
|
||||
defaultValue = '';
|
||||
}
|
||||
}
|
||||
|
||||
await project.addSqlCmdVariable(variableName, defaultValue);
|
||||
|
||||
@@ -1116,6 +1116,40 @@ describe('ProjectsController', function (): void {
|
||||
should(project.sqlCmdVariables.size).equal(3, 'The project should have 3 sqlcmd variable after adding a new one');
|
||||
});
|
||||
|
||||
it('Should add sqlcmd variable without DefaultValue', async function (): Promise<void> {
|
||||
let project = await testUtils.createTestProject(this.test, baselines.openSdkStyleSqlProjectBaseline);
|
||||
const sqlProjectsService = await utils.getSqlProjectsService();
|
||||
await sqlProjectsService.openProject(project.projectFilePath);
|
||||
|
||||
const projController = new ProjectsController(testContext.outputChannel);
|
||||
const projRoot = new ProjectRootTreeItem(project);
|
||||
|
||||
should(project.sqlCmdVariables.size).equal(2, 'The project should start with 2 sqlcmd variables');
|
||||
|
||||
const inputBoxStub = sinon.stub(vscode.window, 'showInputBox');
|
||||
inputBoxStub.onFirstCall().resolves('newVariable');
|
||||
inputBoxStub.onSecondCall().resolves(undefined);
|
||||
const infoMessageStub = sinon.stub(vscode.window, 'showInformationMessage');
|
||||
infoMessageStub.onFirstCall().returns(<any>Promise.resolve(constants.noString));
|
||||
await projController.addSqlCmdVariable(createWorkspaceTreeItem(projRoot.children.find(x => x.friendlyName === constants.sqlcmdVariablesNodeName)!));
|
||||
|
||||
// reload project
|
||||
project = await Project.openProject(project.projectFilePath);
|
||||
should(project.sqlCmdVariables.size).equal(2, 'The project should still have 2 sqlcmd variables if no was selected for adding sqlcmd variable without a DefaultValue');
|
||||
|
||||
inputBoxStub.reset();
|
||||
inputBoxStub.onFirstCall().resolves('newVariable');
|
||||
inputBoxStub.onSecondCall().resolves(undefined);
|
||||
infoMessageStub.onSecondCall().returns(<any>Promise.resolve(constants.yesString));
|
||||
await projController.addSqlCmdVariable(createWorkspaceTreeItem(projRoot.children.find(x => x.friendlyName === constants.sqlcmdVariablesNodeName)!));
|
||||
|
||||
// reload project
|
||||
project = await Project.openProject(project.projectFilePath);
|
||||
should(project.sqlCmdVariables.size).equal(3, 'The project should have 3 sqlcmd variable after adding a new one without a DefaultValue');
|
||||
should(project.sqlCmdVariables.get('newVariable')).equal('', 'The default value of newVariable should be an empty string');
|
||||
});
|
||||
|
||||
|
||||
it('Should update sqlcmd variable', async function (): Promise<void> {
|
||||
let project = await testUtils.createTestProject(this.test, baselines.openSdkStyleSqlProjectBaseline);
|
||||
const sqlProjectsService = await utils.getSqlProjectsService();
|
||||
|
||||
Reference in New Issue
Block a user