Fixes reset of group name when not saving profile (#24000)

This commit is contained in:
Cheena Malhotra
2023-08-01 23:29:09 -07:00
committed by GitHub
parent 7662d425cf
commit 72873f7628
4 changed files with 42 additions and 15 deletions

View File

@@ -264,7 +264,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
}
let options: IConnectionCompletionOptions = this._options || {
params: params,
saveTheConnection: !isTemporaryConnection,
saveTheConnection: !isTemporaryConnection && !fromEditor,
showDashboard: params?.showDashboard ?? false,
showConnectionDialogOnError: false,
showFirewallRuleOnError: true

View File

@@ -67,7 +67,6 @@ export class ConnectionWidget extends lifecycle.Disposable {
private _azureAccountList: azdata.Account[];
private _callbacks: IConnectionComponentCallbacks;
private _focusedBeforeHandleOnConnection: HTMLElement;
private _saveProfile: boolean;
private _databaseDropdownExpanded: boolean = false;
private _defaultDatabaseName: string = localize('defaultDatabaseOption', "<Default>");
private _loadingDatabaseName: string = localize('loadingDatabaseOption', "Loading...");
@@ -893,20 +892,15 @@ export class ConnectionWidget extends lifecycle.Disposable {
this._connectionNameInputBox.value = this.getModelValue(connectionInfo.connectionName);
this._userNameInputBox.value = this.getModelValue(connectionInfo.userName);
this._passwordInputBox.value = this.getModelValue(connectionInfo.password);
this._saveProfile = connectionInfo.saveProfile;
this._azureTenantId = connectionInfo.azureTenantId;
if (this._databaseNameInputBox) {
this._databaseNameInputBox.value = this.getModelValue(connectionInfo.databaseName);
}
let groupName: string;
if (this._saveProfile) {
if (!connectionInfo.groupFullName) {
groupName = this.DefaultServerGroup.name;
} else {
groupName = connectionInfo.groupFullName.replace('root/', '');
}
if (!connectionInfo.groupFullName) {
groupName = this.DefaultServerGroup.name;
} else {
groupName = this.NoneServerGroup.name;
groupName = connectionInfo.groupFullName.replace('root/', '');
}
if (this._serverGroupSelectBox) {
this._serverGroupSelectBox.selectWithOptionName(groupName);

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { ConnectionManagementService } from 'sql/workbench/services/connection/browser/connectionManagementService';
import { ConnectionType, IConnectableInput, IConnectionResult, INewConnectionParams, IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { ConnectionType, IConnectableInput, IConnectionResult, INewConnectionParams, IConnectionManagementService, IConnectionCallbacks } from 'sql/platform/connection/common/connectionManagement';
import { TestErrorMessageService } from 'sql/platform/errorMessage/test/common/testErrorMessageService';
import * as TypeMoq from 'typemoq';
@@ -54,6 +54,8 @@ import { ConnectionBrowserView } from 'sql/workbench/services/connection/browser
import { ConnectionProviderProperties, ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { Emitter } from 'vs/base/common/event';
import { NullCommandService } from 'vs/platform/commands/test/common/nullCommandService';
import { delay } from 'sql/platform/connection/common/utils';
import { IConnectionCompletionOptions } from 'azdata';
suite('ConnectionDialogService tests', () => {
const testTreeViewId = 'testTreeView';
@@ -322,7 +324,8 @@ suite('ConnectionDialogService tests', () => {
assert(!!returnedModel);
assert.strictEqual(returnedModel._groupName, 'testGroup');
assert(called);
await delay(200);
assert(called, 'fillInConnectionInputs was not called as expected.');
});
test('handleOnConnect calls connectAndSaveProfile when called with profile', async () => {
@@ -339,8 +342,32 @@ suite('ConnectionDialogService tests', () => {
(connectionDialogService as any)._connectionDialog.connectButtonState = true;
((connectionDialogService as any)._connectionDialog as any).connect(connectionProfile);
});
await delay(200);
assert(called, 'connectAndSaveProfile was not called as expected.');
});
setTimeout(() => { assert(called); }, 200);
test('handleOnConnect does not save connection for editor type connection', async () => {
let called = false;
let saveConnection = true;
mockConnectionManagementService.setup(x => x.connectAndSaveProfile(TypeMoq.It.isAny(), TypeMoq.It.isAnyString(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((connection: IConnectionProfile, uri: string, options: IConnectionCompletionOptions, callbacks: IConnectionCallbacks) => {
saveConnection = options.saveConnection;
})
.returns(() => {
called = true;
return Promise.resolve(<IConnectionResult>{ connected: true, errorMessage: undefined, errorCode: undefined });
});
testConnectionParams.connectionType = ConnectionType.editor;
(connectionDialogService as any)._connectionDialog = undefined;
(connectionDialogService as any)._dialogDeferredPromise = new Deferred<IConnectionProfile>();
await connectionDialogService.showDialog(mockConnectionManagementService.object, testConnectionParams, connectionProfile);
((connectionDialogService as any)._connectionControllerMap['MSSQL'] as any)._model = connectionProfile;
(connectionDialogService as any)._connectionDialog.connectButtonState = true;
((connectionDialogService as any)._connectionDialog as any).connect(connectionProfile);
await delay(200);
assert(called, 'connectAndSaveProfile was not called as expected.');
assert(!saveConnection, 'Must not save connection for editor connection type');
});
test('handleOnConnect calls connectAndSaveProfile when called without profile', async () => {
@@ -356,7 +383,8 @@ suite('ConnectionDialogService tests', () => {
((connectionDialogService as any)._connectionControllerMap['MSSQL'] as any)._model = connectionProfile;
(connectionDialogService as any)._connectionDialog.connectButtonState = true;
((connectionDialogService as any)._connectionDialog as any).connect();
setTimeout(() => { assert(called); }, 200);
await delay(200);
assert(called, 'connectAndSaveProfile was not called as expected.');
});
test('handleOnCancel calls cancelEditorConnection', async () => {
@@ -373,6 +401,7 @@ suite('ConnectionDialogService tests', () => {
((connectionDialogService as any)._connectionDialog as any).cancel();
});
mockWidget.verify(x => x.databaseDropdownExpanded = false, TypeMoq.Times.atLeastOnce());
assert(called);
await delay(200);
assert(called, 'cancelEditorConnection was not called as expected.');
});
});