Have default values in add database dialog input boxes (#12155)

* show default values in text boxes

* add sqlcmd formatting

* add tests

* Add some sqlcmd variable name validation

* Addressing comments

* fixes after merge

* fix test

* don't localize OtherServer

* fix for windows

* one more fix

* fix test
This commit is contained in:
Kim Santiago
2020-09-11 14:05:39 -07:00
committed by GitHub
parent 61ceb72cea
commit a567ff6de4
8 changed files with 196 additions and 29 deletions

View File

@@ -32,10 +32,15 @@ describe('Add Database Reference Dialog', () => {
should(dialog.dialog.okButton.enabled).equal(false);
should(dialog.currentReferenceType).equal(ReferenceType.systemDb);
dialog.tryEnableAddReferenceButton();
should(dialog.dialog.okButton.enabled).equal(false);
should(dialog.dialog.okButton.enabled).equal(true, 'Ok button should be enabled because there is a default value in the database name textbox');
// empty db name textbox
dialog.databaseNameTextbox!.value = '';
dialog.tryEnableAddReferenceButton();
should(dialog.dialog.okButton.enabled).equal(false, 'Ok button should be disabled after clearing the database name textbox');
// fill in db name and ok button should be enabled
dialog.databaseNameTextbox!.value = 'dbName';
dialog.databaseNameTextbox!.value = 'master';
dialog.tryEnableAddReferenceButton();
should(dialog.dialog.okButton.enabled).equal(true, 'Ok button should be enabled after the database name textbox is filled');
@@ -43,10 +48,12 @@ describe('Add Database Reference Dialog', () => {
dialog.dacpacRadioButtonClick();
should(dialog.currentReferenceType).equal(ReferenceType.dacpac);
should(dialog.locationDropdown?.value).equal(constants.differentDbSameServer);
should(dialog.databaseNameTextbox!.value).equal('', 'database name text box should be empty because no dacpac has been selected');
should(dialog.dialog.okButton.enabled).equal(false, 'Ok button should not be enabled because dacpac input box is not filled');
// fill in dacpac textbox
// fill in dacpac textbox and database name text box
dialog.dacpacTextbox!.value = 'testDb.dacpac';
dialog.databaseNameTextbox!.value = 'testDb';
dialog.tryEnableAddReferenceButton();
should(dialog.dialog.okButton.enabled).equal(true, 'Ok button should be enabled after the dacpac textbox is filled');
@@ -54,13 +61,7 @@ describe('Add Database Reference Dialog', () => {
dialog.locationDropdown!.value = constants.differentDbDifferentServer;
dialog.updateEnabledInputBoxes();
dialog.tryEnableAddReferenceButton();
should(dialog.dialog.okButton.enabled).equal(false, 'Ok button should not be enabled because server fields are not filled');
// fill in server fields
dialog.serverNameTextbox!.value = 'serverName';
dialog.serverVariableTextbox!.value = '$(serverName)';
dialog.tryEnableAddReferenceButton();
should(dialog.dialog.okButton.enabled).equal(true, 'Ok button should be enabled after server fields are filled');
should(dialog.dialog.okButton.enabled).equal(true, 'Ok button should be enabled because server fields are filled');
// change location to same database
dialog.locationDropdown!.value = constants.sameDatabase;
@@ -74,8 +75,9 @@ describe('Add Database Reference Dialog', () => {
// change reference type back to system db
dialog.systemDbRadioButtonClick();
should(dialog.databaseNameTextbox?.value).equal('', `Database name textbox should be empty. Actual:${dialog.databaseNameTextbox?.value}`);
should(dialog.dialog.okButton.enabled).equal(false, 'Ok button should not be enabled because database name is not filled out');
should(dialog.locationDropdown?.value).equal(constants.differentDbSameServer);
should(dialog.databaseNameTextbox?.value).equal('master', `Database name textbox should be set to master. Actual:${dialog.databaseNameTextbox?.value}`);
should(dialog.dialog.okButton.enabled).equal(true, 'Ok button should be enabled because database name is filled');
});
it('Should enable and disable input boxes depending on the reference type', async function (): Promise<void> {

View File

@@ -62,7 +62,7 @@ describe('Publish profile tests', function (): void {
connectionId: 'connId',
options: {
'server': 'testserver',
'username': 'testUser'
'user': 'testUser'
}
};
testContext.dacFxService.setup(x => x.getOptionsFromProfile(TypeMoq.It.isAny())).returns(async () => {

View File

@@ -7,7 +7,7 @@ import * as should from 'should';
import * as path from 'path';
import * as os from 'os';
import { createDummyFileStructure } from './testUtils';
import { exists, trimUri } from '../common/utils';
import { exists, trimUri, removeSqlCmdVariableFormatting, formatSqlCmdVariable, isValidSqlCmdVariableName } from '../common/utils';
import { Uri } from 'vscode';
describe('Tests to verify utils functions', function (): void {
@@ -38,5 +38,45 @@ describe('Tests to verify utils functions', function (): void {
fileUri = Uri.file(path.join(root, 'forked', 'from', 'top', 'file.sql'));
should(trimUri(projectUri, fileUri)).equal('../../forked/from/top/file.sql');
});
it('Should remove $() from sqlcmd variables', () => {
should(removeSqlCmdVariableFormatting('$(test)')).equal('test', '$() surrounding the variable should have been removed');
should(removeSqlCmdVariableFormatting('$(test')).equal('test', '$( at the beginning of the variable should have been removed');
should(removeSqlCmdVariableFormatting('test')).equal('test', 'string should not have been changed because it is not in sqlcmd variable format');
});
it('Should make variable be in sqlcmd variable format with $()', () => {
should(formatSqlCmdVariable('$(test)')).equal('$(test)', 'string should not have been changed because it was already in the correct format');
should(formatSqlCmdVariable('test')).equal('$(test)', 'string should have been changed to be in sqlcmd variable format');
should(formatSqlCmdVariable('$(test')).equal('$(test)', 'string should have been changed to be in sqlcmd variable format');
should(formatSqlCmdVariable('')).equal('', 'should not do anything to an empty string');
});
it('Should determine invalid sqlcmd variable names', () => {
// valid names
should(isValidSqlCmdVariableName('$(test)')).equal(true);
should(isValidSqlCmdVariableName('$(test )')).equal(true, 'trailing spaces should be valid because they will be trimmed');
should(isValidSqlCmdVariableName('test')).equal(true);
should(isValidSqlCmdVariableName('test ')).equal(true, 'trailing spaces should be valid because they will be trimmed');
should(isValidSqlCmdVariableName('$(test')).equal(true);
should(isValidSqlCmdVariableName('$(test ')).equal(true, 'trailing spaces should be valid because they will be trimmed');
// whitespace
should(isValidSqlCmdVariableName('')).equal(false);
should(isValidSqlCmdVariableName(' ')).equal(false);
should(isValidSqlCmdVariableName(' ')).equal(false);
should(isValidSqlCmdVariableName('test abc')).equal(false);
should(isValidSqlCmdVariableName(' ')).equal(false);
// invalid characters
should(isValidSqlCmdVariableName('$($test')).equal(false);
should(isValidSqlCmdVariableName('$test')).equal(false);
should(isValidSqlCmdVariableName('$test')).equal(false);
should(isValidSqlCmdVariableName('test@')).equal(false);
should(isValidSqlCmdVariableName('test#')).equal(false);
should(isValidSqlCmdVariableName('test"')).equal(false);
should(isValidSqlCmdVariableName('test\'')).equal(false);
should(isValidSqlCmdVariableName('test-1')).equal(false);
});
});