Add project dropdown to Update project from database dialog (#21446)

* Add dropdown populated with projects in current workspace in Update Project from database dialog for target project location

* Select first from the list if no project is preselected

* Address comments
This commit is contained in:
Sakshi Sharma
2023-01-03 09:52:14 -08:00
committed by GitHub
parent 687bd1854c
commit d86044c4e3
4 changed files with 49 additions and 30 deletions

View File

@@ -10,7 +10,7 @@ import * as baselines from '../baselines/baselines';
import * as testUtils from '../testUtils';
import { UpdateProjectFromDatabaseDialog } from '../../dialogs/updateProjectFromDatabaseDialog';
import { mockConnectionProfile } from '../testContext';
import { mockConnectionProfile, mockURIList } from '../testContext';
describe('Update Project From Database Dialog', () => {
before(async function (): Promise<void> {
@@ -21,28 +21,28 @@ describe('Update Project From Database Dialog', () => {
sinon.restore();
});
after(async function(): Promise<void> {
after(async function (): Promise<void> {
await testUtils.deleteGeneratedTestFolder();
});
it('Should populate endpoints correctly when no context passed', async function (): Promise<void> {
const dialog = new UpdateProjectFromDatabaseDialog(undefined, undefined);
const dialog = new UpdateProjectFromDatabaseDialog(undefined, undefined, []);
await dialog.openDialog();
should.equal(dialog.serverDropdown!.value, undefined, `Server dropdown should not be populated, but instead was "${dialog.serverDropdown!.value}".`);
should.equal(dialog.databaseDropdown!.value, undefined, `Database dropdown should not be populated, but instead was "${dialog.databaseDropdown!.value}".`);
should.equal(dialog.projectFileTextBox!.value, '', `Project file textbox should not be populated, but instead was "${dialog.projectFileTextBox!.value}".`);
should.equal(dialog.projectFileDropdown!.value, '', `Project file dropdown should not be populated, but instead was "${dialog.projectFileDropdown!.value}".`);
should.equal(dialog.dialog.okButton.enabled, false, 'Okay button should be disabled.');
});
it('Should populate endpoints correctly when Project context is passed', async function (): Promise<void> {
const project = await testUtils.createTestProject(baselines.openProjectFileBaseline);
const dialog = new UpdateProjectFromDatabaseDialog(undefined, project);
const dialog = new UpdateProjectFromDatabaseDialog(undefined, project, mockURIList);
await dialog.openDialog();
should.equal(dialog.serverDropdown!.value, undefined, `Server dropdown should not be populated, but instead was "${dialog.serverDropdown!.value}".`);
should.equal(dialog.databaseDropdown!.value, undefined, `Database dropdown should not be populated, but instead was "${dialog.databaseDropdown!.value}".`);
should.equal(dialog.projectFileTextBox!.value, project.projectFilePath, `Project file textbox should be the sqlproj path (${project.projectFilePath}), but instead was "${dialog.projectFileTextBox!.value}".`);
should.equal(dialog.projectFileDropdown!.value, project.projectFilePath, `Project file dropdown should be the sqlproj path (${project.projectFilePath}), but instead was "${dialog.projectFileDropdown!.value}".`);
should.equal(dialog.dialog.okButton.enabled, false, 'Okay button should be disabled.');
});
@@ -51,13 +51,13 @@ describe('Update Project From Database Dialog', () => {
sinon.stub(azdata.connection, 'listDatabases').resolves([mockConnectionProfile.databaseName!]);
const profile = mockConnectionProfile;
const dialog = new UpdateProjectFromDatabaseDialog(profile, undefined);
const dialog = new UpdateProjectFromDatabaseDialog(profile, undefined, []);
await dialog.openDialog();
await dialog.populatedInputsPromise;
should.equal((<any>dialog.serverDropdown!.value).displayName, profile.options['connectionName'], `Server dropdown should be "${profile.options['connectionName']}", but instead was "${(<any>dialog.serverDropdown!.value).displayName}".`);
should.equal(dialog.databaseDropdown!.value, profile.databaseName, `Database dropdown should be "${profile.databaseName}", but instead was "${dialog.databaseDropdown!.value}".`);
should.equal(dialog.projectFileTextBox!.value, '', `Project file textbox should not be populated, but instead was "${dialog.projectFileTextBox!.value}".`);
should.equal(dialog.projectFileDropdown!.value, '', `Project file dropdown should not be populated, but instead was "${dialog.projectFileDropdown!.value}".`);
should.equal(dialog.dialog.okButton.enabled, false, 'Okay button should be disabled.');
});
@@ -67,13 +67,19 @@ describe('Update Project From Database Dialog', () => {
sinon.stub(azdata.connection, 'listDatabases').resolves([mockConnectionProfile.databaseName!]);
const profile = mockConnectionProfile;
const dialog = new UpdateProjectFromDatabaseDialog(profile, project);
const dialog = new UpdateProjectFromDatabaseDialog(profile, project, mockURIList);
await dialog.openDialog();
await dialog.populatedInputsPromise;
let uriList: string[] = [];
mockURIList.forEach(projectUri => {
uriList.push(projectUri.fsPath as string);
});
should.equal((<any>dialog.serverDropdown!.value).displayName, profile.options['connectionName'], `Server dropdown should be "${profile.options['connectionName']}", but instead was "${(<any>dialog.serverDropdown!.value).displayName}".`);
should.equal(dialog.databaseDropdown!.value, profile.databaseName, `Database dropdown should as "${profile.databaseName}", but instead was "${dialog.databaseDropdown!.value}".`);
should.equal(dialog.projectFileTextBox!.value, project.projectFilePath, `Project file textbox should be the sqlproj path (${project.projectFilePath}), but instead was "${dialog.projectFileTextBox!.value}".`);
should.equal(dialog.projectFileDropdown!.value, project.projectFilePath, `Project file dropdown should be the sqlproj path (${project.projectFilePath}), but instead was "${dialog.projectFileDropdown!.value}".`);
should.deepEqual(dialog.projectFileDropdown!.values, uriList, `Project file dropdown list should be the sqlproj path (${mockURIList}), but instead was "${dialog.projectFileDropdown!.values}".`);
should.equal(dialog.dialog.okButton.enabled, true, 'Okay button should be enabled when dialog is complete.');
});
});

View File

@@ -127,3 +127,9 @@ export const mockConnectionProfile: azdata.IConnectionProfile = {
connectionName: 'My Connection Name'
}
};
export const mockURIList: vscode.Uri[] = [
vscode.Uri.file('/test/folder/abc.sqlproj'),
vscode.Uri.file('/test/folder/folder1/abc1.sqlproj'),
vscode.Uri.file('/test/folder/folder2/abc2.sqlproj')
];