mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
fix a couple things in create project from db dialog (#14511)
This commit is contained in:
@@ -227,9 +227,11 @@ export class CreateProjectFromDatabaseDialog {
|
|||||||
|
|
||||||
// populate database dropdown with the databases for this connection
|
// populate database dropdown with the databases for this connection
|
||||||
if (connectionId) {
|
if (connectionId) {
|
||||||
|
this.sourceDatabaseDropDown!.loading = true;
|
||||||
const databaseValues = await azdata.connection.listDatabases(connectionId);
|
const databaseValues = await azdata.connection.listDatabases(connectionId);
|
||||||
|
|
||||||
this.sourceDatabaseDropDown!.values = databaseValues;
|
this.sourceDatabaseDropDown!.values = databaseValues;
|
||||||
|
this.sourceDatabaseDropDown!.loading = false;
|
||||||
this.connectionId = connectionId;
|
this.connectionId = connectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ describe('NewProjectTool: New project tool tests', function (): void {
|
|||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
previousSetting = await vscode.workspace.getConfiguration(projectConfigurationKey)[projectSaveLocationKey];
|
previousSetting = await vscode.workspace.getConfiguration(projectConfigurationKey)[projectSaveLocationKey];
|
||||||
testFolderPath = await generateTestFolderPath();
|
testFolderPath = await generateTestFolderPath();
|
||||||
|
// set the default project folder path to the test folder
|
||||||
|
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, testFolderPath, true);
|
||||||
|
|
||||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||||
dataWorkspaceMock.setup(x => x.defaultProjectSaveLocation).returns(() => vscode.Uri.file(testFolderPath));
|
dataWorkspaceMock.setup(x => x.defaultProjectSaveLocation).returns(() => vscode.Uri.file(testFolderPath));
|
||||||
@@ -28,18 +30,17 @@ describe('NewProjectTool: New project tool tests', function (): void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
|
// reset the default project folder path to the previous setting
|
||||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, previousSetting, true);
|
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, previousSetting, true);
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should generate correct default project names', async function (): Promise<void> {
|
it('Should generate correct default project names', async function (): Promise<void> {
|
||||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, testFolderPath, true);
|
|
||||||
should(newProjectTool.defaultProjectNameNewProj()).equal('DatabaseProject1');
|
should(newProjectTool.defaultProjectNameNewProj()).equal('DatabaseProject1');
|
||||||
should(newProjectTool.defaultProjectNameFromDb('master')).equal('DatabaseProjectmaster');
|
should(newProjectTool.defaultProjectNameFromDb('master')).equal('DatabaseProjectmaster');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should auto-increment default project names for new projects', async function (): Promise<void> {
|
it('Should auto-increment default project names for new projects', async function (): Promise<void> {
|
||||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, testFolderPath, true);
|
|
||||||
should(newProjectTool.defaultProjectNameNewProj()).equal('DatabaseProject1');
|
should(newProjectTool.defaultProjectNameNewProj()).equal('DatabaseProject1');
|
||||||
|
|
||||||
await createTestFile('', 'DatabaseProject1', testFolderPath);
|
await createTestFile('', 'DatabaseProject1', testFolderPath);
|
||||||
@@ -49,14 +50,19 @@ describe('NewProjectTool: New project tool tests', function (): void {
|
|||||||
should(newProjectTool.defaultProjectNameNewProj()).equal('DatabaseProject3');
|
should(newProjectTool.defaultProjectNameNewProj()).equal('DatabaseProject3');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should auto-increment default project names for import projects', async function (): Promise<void> {
|
it('Should auto-increment default project names for create project for database', async function (): Promise<void> {
|
||||||
await vscode.workspace.getConfiguration(projectConfigurationKey).update(projectSaveLocationKey, testFolderPath, true);
|
should(newProjectTool.defaultProjectNameFromDb('master')).equal('DatabaseProjectmaster');
|
||||||
should(newProjectTool.defaultProjectNameFromDb("master")).equal('DatabaseProjectmaster');
|
|
||||||
|
|
||||||
await createTestFile('', 'DatabaseProjectmaster', testFolderPath);
|
await createTestFile('', 'DatabaseProjectmaster', testFolderPath);
|
||||||
should(newProjectTool.defaultProjectNameFromDb("master")).equal('DatabaseProjectmaster2');
|
should(newProjectTool.defaultProjectNameFromDb('master')).equal('DatabaseProjectmaster2');
|
||||||
|
|
||||||
await createTestFile('', 'DatabaseProjectmaster2', testFolderPath);
|
await createTestFile('', 'DatabaseProjectmaster2', testFolderPath);
|
||||||
should(newProjectTool.defaultProjectNameFromDb("master")).equal('DatabaseProjectmaster3');
|
should(newProjectTool.defaultProjectNameFromDb('master')).equal('DatabaseProjectmaster3');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should not return a project name if undefined is passed in ', async function (): Promise<void> {
|
||||||
|
should(newProjectTool.defaultProjectNameFromDb(undefined)).equal('');
|
||||||
|
should(newProjectTool.defaultProjectNameFromDb('')).equal('');
|
||||||
|
should(newProjectTool.defaultProjectNameFromDb('test')).equal('DatabaseProjecttest');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,7 +32,11 @@ export function defaultProjectNameNewProj(): string {
|
|||||||
*
|
*
|
||||||
* @param dbName the database name to base the default project name off of
|
* @param dbName the database name to base the default project name off of
|
||||||
*/
|
*/
|
||||||
export function defaultProjectNameFromDb(dbName: string): string {
|
export function defaultProjectNameFromDb(dbName: string | undefined): string {
|
||||||
|
if (!dbName) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
const projectNameStarter = constants.defaultProjectNameStarter + dbName;
|
const projectNameStarter = constants.defaultProjectNameStarter + dbName;
|
||||||
const defaultLocation = defaultProjectSaveLocation() ?? vscode.Uri.file(os.homedir());
|
const defaultLocation = defaultProjectSaveLocation() ?? vscode.Uri.file(os.homedir());
|
||||||
const projectPath: string = path.join(defaultLocation.fsPath, projectNameStarter);
|
const projectPath: string = path.join(defaultLocation.fsPath, projectNameStarter);
|
||||||
|
|||||||
Reference in New Issue
Block a user