mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 01:25:36 -05:00
connection tests for connectionDialogWidget (#11160)
* Added providerRegistered test * test for EditConnectionDialog * changed wording * added test for connectionInfo * utils.ts tests added * hasRegisteredServers test * commented out editconnection tests, addl. tests * added onConnectionChangedNotification test * added changeGroupId tests * Added connection profile changes * added connectIfNotConnected test * added delete connection test * isRecent and disconnect editor tests * Add CodeQL Analysis workflow (#10195) * Add CodeQL Analysis workflow * Fix path * added registerIconProvider test * Fix for ensureDefaultLanguageFlavor test * added a few tests * utils prefix test updated * added utils tests * disconnect tests added * Added additional get connection info tests * added some more tests * minor additions to tests * again another commit * another change * connectionManagementService finalized * connectionDialogWidget test WIP * wip connectiondialogwidget test * added working connectionDialogWidget test * added more tests * current connectionDialogWidget tests * undid space * hanging promise addressed * added open test * finished connectionDialogWidget tests * Added showDialog test * mockConnectionDialogService added * added accessorConnectionDialogService * removed accessor service * added openDialogAndWait test * added fake error to test * added error tests * Added comments to test * more coverage * async to await change * registerCapabilities test added * connectionDialogService tests finished * undefined added * Added views for tests * tslint disable added * error catchers added * added empty connectioninfo Co-authored-by: Justin Hutchings <jhutchings1@users.noreply.github.com>
This commit is contained in:
@@ -156,6 +156,10 @@ export class ConnectionDialogWidget extends Modal implements IViewPaneContainer
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
public getDisplayNameFromProviderName(providerName: string): string {
|
||||
return this.providerNameToDisplayNameMap[providerName];
|
||||
}
|
||||
|
||||
public refresh(): void {
|
||||
let filteredProviderMap = this.providerNameToDisplayNameMap;
|
||||
if (this._newConnectionParams && this._newConnectionParams.providers) {
|
||||
|
||||
@@ -3,58 +3,220 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ConnectionDialogService } from 'sql/workbench/services/connection/browser/connectionDialogService';
|
||||
import { ConnectionDialogWidget } from 'sql/workbench/services/connection/browser/connectionDialogWidget';
|
||||
import { ConnectionManagementService } from 'sql/workbench/services/connection/browser/connectionManagementService';
|
||||
import { ConnectionType, IConnectableInput, IConnectionResult, INewConnectionParams } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ConnectionType, IConnectableInput, IConnectionResult, INewConnectionParams, IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { TestErrorMessageService } from 'sql/platform/errorMessage/test/common/testErrorMessageService';
|
||||
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as assert from 'assert';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import * as Constants from 'sql/platform/connection/common/constants';
|
||||
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { NullLogService, ILogService } from 'vs/platform/log/common/log';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { TestStorageService, TestTextResourcePropertiesService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { createConnectionProfile } from 'sql/workbench/services/connection/test/browser/connectionManagementService.test';
|
||||
import { getUniqueConnectionProvidersByNameMap } from 'sql/workbench/services/connection/test/browser/connectionDialogWidget.test';
|
||||
import { TestConnectionDialogWidget } from 'sql/workbench/services/connection/test/browser/testConnectionDialogWidget';
|
||||
import { ConnectionDialogService } from 'sql/workbench/services/connection/browser/connectionDialogService';
|
||||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
import { TestLayoutService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
|
||||
import { ServiceOptionType, ConnectionOptionSpecialType, IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { ConnectionWidget } from 'sql/workbench/services/connection/browser/connectionWidget';
|
||||
import { BrowserClipboardService } from 'vs/platform/clipboard/browser/clipboardService';
|
||||
import { NullCommandService } from 'vs/platform/commands/common/commands';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
|
||||
import { ClearRecentConnectionsAction } from 'sql/workbench/services/connection/browser/connectionActions';
|
||||
import { RecentConnectionActionsProvider } from 'sql/workbench/services/connection/browser/recentConnectionTreeController';
|
||||
import { RecentConnectionDataSource } from 'sql/workbench/services/objectExplorer/browser/recentConnectionDataSource';
|
||||
import { ServerTreeRenderer } from 'sql/workbench/services/objectExplorer/browser/serverTreeRenderer';
|
||||
import { RecentConnectionsDragAndDrop } from 'sql/workbench/services/objectExplorer/browser/dragAndDropController';
|
||||
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
||||
import { Deferred } from 'sql/base/common/promise';
|
||||
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import { localize } from 'vs/nls';
|
||||
import { ViewDescriptorService } from 'vs/workbench/services/views/browser/viewDescriptorService';
|
||||
import { ViewContainer, Extensions, IViewsRegistry, IViewContainersRegistry, ITreeViewDescriptor, ViewContainerLocation, IViewDescriptorService } from 'vs/workbench/common/views';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { TestTreeView } from 'sql/workbench/services/connection/test/browser/testTreeView';
|
||||
|
||||
suite('ConnectionDialogService tests', () => {
|
||||
const testTreeViewId = 'testTreeView';
|
||||
const ViewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
|
||||
|
||||
let connectionDialogService: ConnectionDialogService;
|
||||
let mockConnectionManagementService: TypeMoq.Mock<ConnectionManagementService>;
|
||||
let mockConnectionDialog: TypeMoq.Mock<ConnectionDialogWidget>;
|
||||
let testConnectionDialog: TestConnectionDialogWidget;
|
||||
let mockInstantationService: TypeMoq.Mock<InstantiationService>;
|
||||
let testConnectionParams: INewConnectionParams;
|
||||
let connectionProfile: ConnectionProfile;
|
||||
let mockWidget: TypeMoq.Mock<ConnectionWidget>;
|
||||
let testInstantiationService: TestInstantiationService;
|
||||
let container: ViewContainer;
|
||||
|
||||
setup(() => {
|
||||
let testinstantiationService = new TestInstantiationService();
|
||||
testinstantiationService.stub(IStorageService, new TestStorageService());
|
||||
const viewInstantiationService: TestInstantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
const viewDescriptorService = viewInstantiationService.createInstance(ViewDescriptorService);
|
||||
container = Registry.as<IViewContainersRegistry>(Extensions.ViewContainersRegistry).registerViewContainer({ id: 'testContainer', name: 'test', ctorDescriptor: new SyncDescriptor(<any>{}) }, ViewContainerLocation.Sidebar);
|
||||
viewInstantiationService.stub(IViewDescriptorService, viewDescriptorService);
|
||||
const viewDescriptor: ITreeViewDescriptor = {
|
||||
id: testTreeViewId,
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
treeView: viewInstantiationService.createInstance(TestTreeView, 'testTree', 'Test Title'),
|
||||
};
|
||||
ViewsRegistry.registerViews([viewDescriptor], container);
|
||||
|
||||
mockInstantationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Strict);
|
||||
testInstantiationService = new TestInstantiationService();
|
||||
testInstantiationService.stub(IStorageService, new TestStorageService());
|
||||
testInstantiationService.stub(ILogService, new NullLogService());
|
||||
testInstantiationService.stub(IConfigurationService, new TestConfigurationService());
|
||||
testInstantiationService.stub(IInstantiationService, mockInstantationService.object);
|
||||
testInstantiationService.stub(IViewDescriptorService, viewDescriptorService);
|
||||
let errorMessageService = getMockErrorMessageService();
|
||||
connectionDialogService = new ConnectionDialogService(undefined, undefined, errorMessageService.object,
|
||||
undefined, undefined, undefined, new NullLogService());
|
||||
let capabilitiesService = new TestCapabilitiesService();
|
||||
mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict,
|
||||
undefined, // connection store
|
||||
undefined, // connection status manager
|
||||
undefined, // connection dialog service
|
||||
testinstantiationService, // instantiation service
|
||||
testInstantiationService, // instantiation service
|
||||
undefined, // editor service
|
||||
undefined, // telemetry service
|
||||
undefined, // configuration service
|
||||
new TestCapabilitiesService());
|
||||
testInstantiationService.stub(IConnectionManagementService, mockConnectionManagementService.object);
|
||||
testInstantiationService.stub(IContextKeyService, new MockContextKeyService());
|
||||
testInstantiationService.stub(IThemeService, new TestThemeService());
|
||||
testInstantiationService.stub(ILayoutService, new TestLayoutService());
|
||||
testInstantiationService.stub(IAdsTelemetryService, new NullAdsTelemetryService());
|
||||
connectionDialogService = new ConnectionDialogService(testInstantiationService, capabilitiesService, errorMessageService.object,
|
||||
new TestConfigurationService(), new BrowserClipboardService(), NullCommandService, new NullLogService());
|
||||
(connectionDialogService as any)._connectionManagementService = mockConnectionManagementService.object;
|
||||
mockConnectionDialog = TypeMoq.Mock.ofType(ConnectionDialogWidget, TypeMoq.MockBehavior.Strict,
|
||||
undefined, // providerDisplayNameOptions
|
||||
undefined, // selectedProviderType
|
||||
undefined, // providerNameToDisplayNameMap
|
||||
undefined, // instantiationService
|
||||
undefined, // connectionManagementService
|
||||
undefined, // contextMenuService
|
||||
undefined, // contextViewService
|
||||
{ getViewContainerById: () => ({}), getViewContainerModel: () => ({}) }, // viewDescriptorService
|
||||
undefined, // themeService
|
||||
undefined, // layoutService
|
||||
undefined, // telemetryService
|
||||
new MockContextKeyService()
|
||||
);
|
||||
mockConnectionDialog.setup(c => c.resetConnection());
|
||||
(connectionDialogService as any)._connectionDialog = mockConnectionDialog.object;
|
||||
let providerDisplayNames = ['Mock SQL Server'];
|
||||
let providerNameToDisplayMap = { 'MSSQL': 'Mock SQL Server' };
|
||||
mockConnectionManagementService.setup(x => x.getUniqueConnectionProvidersByNameMap(TypeMoq.It.isAny())).returns(() => {
|
||||
return getUniqueConnectionProvidersByNameMap(providerNameToDisplayMap);
|
||||
});
|
||||
mockConnectionManagementService.setup(x => x.getConnectionGroups(TypeMoq.It.isAny())).returns(() => {
|
||||
return [new ConnectionProfileGroup('test_group', undefined, 'test_group')];
|
||||
});
|
||||
testConnectionDialog = new TestConnectionDialogWidget(providerDisplayNames, providerNameToDisplayMap['MSSQL'], providerNameToDisplayMap, testInstantiationService, mockConnectionManagementService.object, undefined, undefined, viewDescriptorService, new TestThemeService(), new TestLayoutService(), new NullAdsTelemetryService(), new MockContextKeyService(), undefined, new NullLogService(), new TestTextResourcePropertiesService(new TestConfigurationService), new TestConfigurationService());
|
||||
testConnectionDialog.render();
|
||||
testConnectionDialog.renderBody(DOM.createStyleSheet());
|
||||
(connectionDialogService as any)._connectionDialog = testConnectionDialog;
|
||||
|
||||
capabilitiesService.capabilities[Constants.mssqlProviderName] = {
|
||||
connection: {
|
||||
providerId: Constants.mssqlProviderName,
|
||||
displayName: 'MSSQL',
|
||||
connectionOptions: [
|
||||
{
|
||||
name: 'authenticationType',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: [
|
||||
{
|
||||
name: 'authenticationType',
|
||||
displayName: 'authenticationType'
|
||||
}
|
||||
],
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.authType,
|
||||
valueType: ServiceOptionType.string
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
capabilitiesService.fireCapabilitiesRegistered(Constants.mssqlProviderName, capabilitiesService.capabilities[Constants.mssqlProviderName]);
|
||||
testConnectionParams = <INewConnectionParams>{
|
||||
connectionType: ConnectionType.editor,
|
||||
input: <IConnectableInput>{
|
||||
uri: 'test_uri',
|
||||
onConnectStart: undefined,
|
||||
onConnectSuccess: undefined,
|
||||
onConnectReject: undefined,
|
||||
onDisconnect: undefined,
|
||||
onConnectCanceled: undefined
|
||||
},
|
||||
runQueryOnCompletion: undefined,
|
||||
querySelection: undefined,
|
||||
providers: ['MSSQL']
|
||||
};
|
||||
connectionProfile = createConnectionProfile('test_id');
|
||||
connectionProfile.providerName = undefined;
|
||||
|
||||
mockConnectionManagementService.setup(x => x.getRecentConnections(TypeMoq.It.isValue(testConnectionParams.providers))).returns(() => {
|
||||
return [connectionProfile];
|
||||
});
|
||||
mockConnectionManagementService.setup(x => x.addSavedPassword(TypeMoq.It.isAny())).returns(() => {
|
||||
return Promise.resolve(connectionProfile);
|
||||
});
|
||||
mockWidget = TypeMoq.Mock.ofType(ConnectionWidget, TypeMoq.MockBehavior.Strict, [], undefined, 'MSSQL');
|
||||
mockWidget.setup(x => x.focusOnOpen());
|
||||
mockWidget.setup(x => x.handleOnConnecting());
|
||||
mockWidget.setup(x => x.handleResetConnection());
|
||||
mockWidget.setup(x => x.connect(TypeMoq.It.isValue(connectionProfile))).returns(() => true);
|
||||
mockWidget.setup(x => x.createConnectionWidget(TypeMoq.It.isAny()));
|
||||
mockWidget.setup(x => x.updateServerGroup(TypeMoq.It.isAny()));
|
||||
mockWidget.setup(x => x.initDialog(TypeMoq.It.isAny()));
|
||||
mockInstantationService.setup(x => x.createInstance(TypeMoq.It.isValue(ConnectionWidget), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAnyString())).returns(() => {
|
||||
return mockWidget.object;
|
||||
});
|
||||
mockWidget.setup(x => x.DefaultServerGroup).returns(() => {
|
||||
return {
|
||||
id: '',
|
||||
name: localize('defaultServerGroup', "<Default>"),
|
||||
parentId: undefined,
|
||||
color: undefined,
|
||||
description: undefined,
|
||||
};
|
||||
});
|
||||
mockWidget.setup(x => x.NoneServerGroup).returns(() => {
|
||||
return {
|
||||
id: '',
|
||||
name: localize('noneServerGroup', "<Do not save>"),
|
||||
parentId: undefined,
|
||||
color: undefined,
|
||||
description: undefined,
|
||||
};
|
||||
});
|
||||
mockWidget.setup(x => x.databaseDropdownExpanded).returns(() => false);
|
||||
mockWidget.setup(x => x.databaseDropdownExpanded = false);
|
||||
|
||||
mockInstantationService.setup(x => x.createInstance(TypeMoq.It.isValue(ClearRecentConnectionsAction), TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => {
|
||||
return testInstantiationService.createInstance(ClearRecentConnectionsAction, ClearRecentConnectionsAction.ID, ClearRecentConnectionsAction.LABEL);
|
||||
});
|
||||
mockInstantationService.setup(x => x.createInstance(TypeMoq.It.isValue(RecentConnectionActionsProvider))).returns(() => {
|
||||
return testInstantiationService.createInstance(RecentConnectionActionsProvider);
|
||||
});
|
||||
mockInstantationService.setup(x => x.createInstance(TypeMoq.It.isValue(RecentConnectionDataSource))).returns(() => {
|
||||
return testInstantiationService.createInstance(RecentConnectionDataSource);
|
||||
});
|
||||
mockInstantationService.setup(x => x.createInstance(TypeMoq.It.isValue(ServerTreeRenderer), true)).returns(() => {
|
||||
return testInstantiationService.createInstance(ServerTreeRenderer, true);
|
||||
});
|
||||
mockInstantationService.setup(x => x.createInstance(TypeMoq.It.isValue(RecentConnectionsDragAndDrop))).returns(() => {
|
||||
return testInstantiationService.createInstance(RecentConnectionsDragAndDrop);
|
||||
});
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
ViewsRegistry.deregisterViews(ViewsRegistry.getViews(container), container);
|
||||
});
|
||||
|
||||
function getMockErrorMessageService(): TypeMoq.Mock<TestErrorMessageService> {
|
||||
@@ -73,7 +235,7 @@ suite('ConnectionDialogService tests', () => {
|
||||
onConnectSuccess: undefined,
|
||||
onConnectReject: undefined,
|
||||
onDisconnect: undefined,
|
||||
onConnectCanceled: undefined
|
||||
onConnectCanceled: function () { }
|
||||
},
|
||||
runQueryOnCompletion: undefined,
|
||||
querySelection: undefined
|
||||
@@ -99,4 +261,87 @@ suite('ConnectionDialogService tests', () => {
|
||||
test('handleDefaultOnConnect uses undefined URI for non-editor connections', () => {
|
||||
return testHandleDefaultOnConnectUri(false);
|
||||
});
|
||||
|
||||
test('openDialogAndWait should return a deferred promise when called', async () => {
|
||||
// connectionResult is used for testing showErrorDialog.
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: false,
|
||||
errorMessage: 'test_error',
|
||||
errorCode: -1,
|
||||
callStack: 'testCallStack'
|
||||
};
|
||||
// promise only resolves upon handleDefaultOnConnect, must return it at the end
|
||||
let connectionPromise = connectionDialogService.openDialogAndWait(mockConnectionManagementService.object, testConnectionParams, connectionProfile, connectionResult, false);
|
||||
|
||||
/* handleDefaultOnConnect should reset connection and resolve properly
|
||||
Also openDialogAndWait returns the connection profile passed in */
|
||||
(connectionDialogService as any).handleDefaultOnConnect(testConnectionParams, connectionProfile);
|
||||
let result = await connectionPromise;
|
||||
assert.equal(result, connectionProfile);
|
||||
});
|
||||
|
||||
test('handleFillInConnectionInputs calls function on ConnectionController widget', async () => {
|
||||
let called = false;
|
||||
mockWidget.setup(x => x.fillInConnectionInputs(TypeMoq.It.isAny())).returns(() => {
|
||||
called = true;
|
||||
});
|
||||
await connectionDialogService.showDialog(mockConnectionManagementService.object, testConnectionParams, connectionProfile);
|
||||
await (connectionDialogService as any).handleFillInConnectionInputs(connectionProfile);
|
||||
let returnedModel = ((connectionDialogService as any)._connectionControllerMap['MSSQL'] as any)._model;
|
||||
assert.equal(returnedModel._groupName, 'testGroup');
|
||||
assert(called);
|
||||
});
|
||||
|
||||
test('handleOnConnect calls connectAndSaveProfile when called with profile', async () => {
|
||||
let called = false;
|
||||
mockConnectionManagementService.setup(x => x.connectAndSaveProfile(TypeMoq.It.isAny(), TypeMoq.It.isAnyString(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
|
||||
called = true;
|
||||
return Promise.resolve(<IConnectionResult>{ connected: true, errorMessage: undefined, errorCode: undefined });
|
||||
});
|
||||
|
||||
(connectionDialogService as any)._connectionDialog = undefined;
|
||||
(connectionDialogService as any)._dialogDeferredPromise = new Deferred<IConnectionProfile>();
|
||||
await connectionDialogService.showDialog(mockConnectionManagementService.object, testConnectionParams, connectionProfile).then(() => {
|
||||
((connectionDialogService as any)._connectionControllerMap['MSSQL'] as any)._model = connectionProfile;
|
||||
(connectionDialogService as any)._connectionDialog.connectButtonState = true;
|
||||
((connectionDialogService as any)._connectionDialog as any).connect(connectionProfile);
|
||||
});
|
||||
|
||||
assert(called);
|
||||
});
|
||||
|
||||
test('handleOnConnect calls connectAndSaveProfile when called without profile', async () => {
|
||||
let called = false;
|
||||
mockConnectionManagementService.setup(x => x.connectAndSaveProfile(TypeMoq.It.isAny(), TypeMoq.It.isAnyString(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => {
|
||||
called = true;
|
||||
return Promise.resolve(<IConnectionResult>{ connected: true, errorMessage: undefined, errorCode: undefined });
|
||||
});
|
||||
|
||||
(connectionDialogService as any)._connectionDialog = undefined;
|
||||
(connectionDialogService as any)._dialogDeferredPromise = new Deferred<IConnectionProfile>();
|
||||
await connectionDialogService.showDialog(mockConnectionManagementService.object, testConnectionParams, connectionProfile).then(() => {
|
||||
((connectionDialogService as any)._connectionControllerMap['MSSQL'] as any)._model = connectionProfile;
|
||||
(connectionDialogService as any)._connectionDialog.connectButtonState = true;
|
||||
((connectionDialogService as any)._connectionDialog as any).connect();
|
||||
});
|
||||
|
||||
assert(called);
|
||||
});
|
||||
|
||||
test('handleOnCancel calls cancelEditorConnection', async () => {
|
||||
let called = false;
|
||||
mockConnectionManagementService.setup(x => x.cancelEditorConnection(TypeMoq.It.isAny())).returns(() => {
|
||||
called = true;
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
|
||||
(connectionDialogService as any)._connectionDialog = undefined;
|
||||
(connectionDialogService as any)._dialogDeferredPromise = new Deferred<IConnectionProfile>();
|
||||
await connectionDialogService.showDialog(mockConnectionManagementService.object, testConnectionParams, connectionProfile).then(() => {
|
||||
((connectionDialogService as any)._connectionControllerMap['MSSQL'] as any)._model = connectionProfile;
|
||||
((connectionDialogService as any)._connectionDialog as any).cancel();
|
||||
});
|
||||
mockWidget.verify(x => x.databaseDropdownExpanded = false, TypeMoq.Times.atLeastOnce());
|
||||
assert(called);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as assert from 'assert';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import * as Constants from 'sql/platform/connection/common/constants';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { TestStorageService, TestTextResourcePropertiesService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { ConnectionManagementService } from 'sql/workbench/services/connection/browser/connectionManagementService';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
|
||||
import { TestConnectionDialogWidget } from 'sql/workbench/services/connection/test/browser/testConnectionDialogWidget';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
import { entries } from 'sql/base/common/collections';
|
||||
import { TestLayoutService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { INewConnectionParams, ConnectionType, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
|
||||
import { createConnectionProfile } from 'sql/workbench/services/connection/test/browser/connectionManagementService.test';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { ViewDescriptorService } from 'vs/workbench/services/views/browser/viewDescriptorService';
|
||||
import { ViewContainer, Extensions, IViewsRegistry, IViewContainersRegistry, ITreeViewDescriptor, ViewContainerLocation, IViewDescriptorService } from 'vs/workbench/common/views';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { TestTreeView } from 'sql/workbench/services/connection/test/browser/testTreeView';
|
||||
suite('ConnectionDialogWidget tests', () => {
|
||||
const testTreeViewId = 'testTreeView';
|
||||
const ViewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
|
||||
|
||||
let connectionDialogWidget: TestConnectionDialogWidget;
|
||||
let mockConnectionManagementService: TypeMoq.Mock<ConnectionManagementService>;
|
||||
let cmInstantiationService: TestInstantiationService;
|
||||
let element: HTMLElement;
|
||||
let container: ViewContainer;
|
||||
|
||||
setup(() => {
|
||||
const viewInstantiationService: TestInstantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
const viewDescriptorService = viewInstantiationService.createInstance(ViewDescriptorService);
|
||||
container = Registry.as<IViewContainersRegistry>(Extensions.ViewContainersRegistry).registerViewContainer({ id: 'testContainer', name: 'test', ctorDescriptor: new SyncDescriptor(<any>{}) }, ViewContainerLocation.Sidebar);
|
||||
viewInstantiationService.stub(IViewDescriptorService, viewDescriptorService);
|
||||
const viewDescriptor: ITreeViewDescriptor = {
|
||||
id: testTreeViewId,
|
||||
ctorDescriptor: null!,
|
||||
name: 'Test View 1',
|
||||
treeView: viewInstantiationService.createInstance(TestTreeView, 'testTree', 'Test Title'),
|
||||
};
|
||||
ViewsRegistry.registerViews([viewDescriptor], container);
|
||||
cmInstantiationService = new TestInstantiationService();
|
||||
cmInstantiationService.stub(IStorageService, new TestStorageService());
|
||||
mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict,
|
||||
undefined, // connection store
|
||||
undefined, // connection status manager
|
||||
undefined, // connection dialog service
|
||||
cmInstantiationService, // instantiation service
|
||||
undefined, // editor service
|
||||
undefined, // telemetry service
|
||||
undefined, // configuration service
|
||||
new TestCapabilitiesService());
|
||||
let providerDisplayNames = ['Mock SQL Server'];
|
||||
let providerNameToDisplayMap = { 'MSSQL': 'Mock SQL Server' };
|
||||
connectionDialogWidget = new TestConnectionDialogWidget(providerDisplayNames, providerNameToDisplayMap['MSSQL'], providerNameToDisplayMap, cmInstantiationService, mockConnectionManagementService.object, undefined, undefined, viewDescriptorService, new TestThemeService(), new TestLayoutService(), new NullAdsTelemetryService(), new MockContextKeyService(), undefined, new NullLogService(), new TestTextResourcePropertiesService(new TestConfigurationService()), new TestConfigurationService());
|
||||
element = DOM.createStyleSheet();
|
||||
connectionDialogWidget.render();
|
||||
connectionDialogWidget.renderBody(element);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
ViewsRegistry.deregisterViews(ViewsRegistry.getViews(container), container);
|
||||
});
|
||||
|
||||
test('renderBody should have attached a connection dialog body onto element', () => {
|
||||
assert.equal(element.childElementCount, 1);
|
||||
assert.equal(element.children[0].className, 'connection-dialog');
|
||||
});
|
||||
|
||||
test('updateConnectionProviders should update connection providers', () => {
|
||||
let providerDisplayNames = ['Mock SQL Server', 'Mock SQL Server 1'];
|
||||
let providerNameToDisplayMap = { 'MSSQL': 'Mock SQL Server', 'PGSQL': 'Mock SQL Server 1' };
|
||||
mockConnectionManagementService.setup(x => x.getUniqueConnectionProvidersByNameMap(TypeMoq.It.isAny())).returns(() => {
|
||||
return getUniqueConnectionProvidersByNameMap(providerNameToDisplayMap);
|
||||
});
|
||||
connectionDialogWidget.updateConnectionProviders(providerDisplayNames, providerNameToDisplayMap);
|
||||
assert.equal(connectionDialogWidget.getDisplayNameFromProviderName('PGSQL'), providerNameToDisplayMap['PGSQL']);
|
||||
});
|
||||
|
||||
test('setting newConnectionParams test for connectionDialogWidget', () => {
|
||||
let params: INewConnectionParams = {
|
||||
connectionType: ConnectionType.editor,
|
||||
input: {
|
||||
onConnectReject: undefined,
|
||||
onConnectStart: undefined,
|
||||
onDisconnect: undefined,
|
||||
onConnectSuccess: undefined,
|
||||
onConnectCanceled: undefined,
|
||||
uri: 'Editor Uri'
|
||||
},
|
||||
runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery,
|
||||
providers: ['MSSQL']
|
||||
};
|
||||
let providerNameToDisplayMap = { 'MSSQL': 'Mock SQL Server' };
|
||||
mockConnectionManagementService.setup(x => x.getUniqueConnectionProvidersByNameMap(TypeMoq.It.isAny())).returns(() => {
|
||||
return getUniqueConnectionProvidersByNameMap(providerNameToDisplayMap);
|
||||
});
|
||||
connectionDialogWidget.newConnectionParams = params;
|
||||
assert.equal(connectionDialogWidget.newConnectionParams, params);
|
||||
});
|
||||
|
||||
test('open should call onInitDialog', async () => {
|
||||
let params: INewConnectionParams = {
|
||||
connectionType: ConnectionType.editor,
|
||||
input: {
|
||||
onConnectReject: undefined,
|
||||
onConnectStart: undefined,
|
||||
onDisconnect: undefined,
|
||||
onConnectSuccess: undefined,
|
||||
onConnectCanceled: undefined,
|
||||
uri: 'Editor Uri'
|
||||
},
|
||||
runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery,
|
||||
providers: ['MSSQL']
|
||||
};
|
||||
let providerNameToDisplayMap = { 'MSSQL': 'Mock SQL Server' };
|
||||
mockConnectionManagementService.setup(x => x.getUniqueConnectionProvidersByNameMap(TypeMoq.It.isAny())).returns(() => {
|
||||
return getUniqueConnectionProvidersByNameMap(providerNameToDisplayMap);
|
||||
});
|
||||
//params must be assigned to get load providers
|
||||
connectionDialogWidget.newConnectionParams = params;
|
||||
let mockConnectionProfile = createConnectionProfile('test_id', '');
|
||||
mockConnectionManagementService.setup(x => x.getRecentConnections(TypeMoq.It.isValue(params.providers))).returns(() => {
|
||||
return [mockConnectionProfile];
|
||||
});
|
||||
let called = false;
|
||||
connectionDialogWidget.onInitDialog(() => {
|
||||
called = true;
|
||||
});
|
||||
await connectionDialogWidget.open(true);
|
||||
assert(called);
|
||||
called = false;
|
||||
await connectionDialogWidget.open(false);
|
||||
assert(called);
|
||||
});
|
||||
|
||||
test('get set tests for connectButtonState and databaseDropdownExpanded', () => {
|
||||
connectionDialogWidget.connectButtonState = true;
|
||||
assert(connectionDialogWidget.connectButtonState);
|
||||
connectionDialogWidget.databaseDropdownExpanded = true;
|
||||
assert(connectionDialogWidget.databaseDropdownExpanded);
|
||||
});
|
||||
|
||||
test('close/resetConnection should fire onRecentConnect', () => {
|
||||
let called = false;
|
||||
connectionDialogWidget.onResetConnection(() => {
|
||||
called = true;
|
||||
});
|
||||
connectionDialogWidget.close();
|
||||
assert(called);
|
||||
});
|
||||
|
||||
test('updateProvider should call onShowUiComponent and onInitDialog', () => {
|
||||
let returnedDisplayName: string;
|
||||
let returnedContainer: HTMLElement;
|
||||
let called = false;
|
||||
connectionDialogWidget.onInitDialog(() => {
|
||||
called = true;
|
||||
});
|
||||
connectionDialogWidget.onShowUiComponent(e => {
|
||||
returnedDisplayName = e.selectedProviderDisplayName;
|
||||
returnedContainer = e.container;
|
||||
});
|
||||
let providerDisplayName = 'Mock SQL Server';
|
||||
connectionDialogWidget.updateProvider(providerDisplayName);
|
||||
assert.equal(returnedDisplayName, providerDisplayName);
|
||||
assert.equal(returnedContainer.className, 'connection-provider-info');
|
||||
assert(called);
|
||||
});
|
||||
});
|
||||
|
||||
// Copy of function in connectionManagementService.
|
||||
export function getUniqueConnectionProvidersByNameMap(providerNameToDisplayNameMap: { [providerDisplayName: string]: string }): { [providerDisplayName: string]: string } {
|
||||
let uniqueProvidersMap = {};
|
||||
let providerNames = entries(providerNameToDisplayNameMap);
|
||||
providerNames.forEach(p => {
|
||||
// Only add CMS provider if explicitly called from CMS extension
|
||||
// otherwise avoid duplicate listing in dropdown
|
||||
if (p[0] !== Constants.cmsProviderName) {
|
||||
uniqueProvidersMap[p[0]] = p[1];
|
||||
} else {
|
||||
if (providerNames.length === 1) {
|
||||
uniqueProvidersMap[p[0]] = p[1];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return uniqueProvidersMap;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,170 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/* File icons in trees */
|
||||
|
||||
.file-icon-themable-tree.align-icons-and-twisties .monaco-tl-twistie:not(.force-twistie):not(.collapsible),
|
||||
.file-icon-themable-tree .align-icon-with-twisty .monaco-tl-twistie:not(.force-twistie):not(.collapsible),
|
||||
.file-icon-themable-tree.hide-arrows .monaco-tl-twistie:not(.force-twistie),
|
||||
.file-icon-themable-tree .monaco-tl-twistie.force-no-twistie {
|
||||
background-image: none !important;
|
||||
width: 0 !important;
|
||||
padding-right: 0 !important;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
/* Misc */
|
||||
|
||||
.monaco-workbench .tree-explorer-viewlet-tree-view {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.monaco-workbench .tree-explorer-viewlet-tree-view .message {
|
||||
display: flex;
|
||||
padding: 4px 12px 4px 18px;
|
||||
user-select: text;
|
||||
-webkit-user-select: text;
|
||||
}
|
||||
|
||||
.monaco-workbench .tree-explorer-viewlet-tree-view .message p {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 0px;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
.monaco-workbench .tree-explorer-viewlet-tree-view .message ul {
|
||||
padding-left: 24px;
|
||||
}
|
||||
|
||||
.monaco-workbench .tree-explorer-viewlet-tree-view .message.hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.monaco-workbench .tree-explorer-viewlet-tree-view .customview-tree {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.monaco-workbench .tree-explorer-viewlet-tree-view .customview-tree.hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.monaco-workbench .pane > .pane-body > .welcome-view {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.monaco-workbench .pane > .pane-body:not(.welcome) > .welcome-view,
|
||||
.monaco-workbench .pane > .pane-body.welcome > :not(.welcome-view) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.monaco-workbench .pane > .pane-body > .welcome-view .monaco-button {
|
||||
max-width: 260px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.monaco-workbench .pane > .pane-body .welcome-view-content {
|
||||
padding: 0 20px 0 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.monaco-workbench .pane > .pane-body .welcome-view-content > * {
|
||||
margin-block-start: 1em;
|
||||
margin-block-end: 1em;
|
||||
margin-inline-start: 0px;
|
||||
margin-inline-end: 0px;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list-row .monaco-tl-contents.align-icon-with-twisty::before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list-row .monaco-tl-contents:not(.align-icon-with-twisty)::before {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row {
|
||||
padding-right: 12px;
|
||||
padding-left: 0px;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row .custom-view-tree-node-item {
|
||||
display: flex;
|
||||
height: 22px;
|
||||
line-height: 22px;
|
||||
flex: 1;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
flex-wrap: nowrap;
|
||||
padding-left: 3px;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row .custom-view-tree-node-item .monaco-inputbox {
|
||||
line-height: normal;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row .custom-view-tree-node-item .custom-view-tree-node-item-resourceLabel {
|
||||
flex: 1;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row .custom-view-tree-node-item > .custom-view-tree-node-item-icon {
|
||||
background-size: 16px;
|
||||
background-position: left center;
|
||||
background-repeat: no-repeat;
|
||||
padding-right: 6px;
|
||||
width: 16px;
|
||||
height: 22px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row .custom-view-tree-node-item > .custom-view-tree-node-item-icon.codicon {
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row.selected .custom-view-tree-node-item > .custom-view-tree-node-item-icon.codicon {
|
||||
color: currentColor !important;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row .custom-view-tree-node-item .custom-view-tree-node-item-resourceLabel .monaco-icon-label-container > .monaco-icon-name-container {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row .custom-view-tree-node-item .custom-view-tree-node-item-resourceLabel::after {
|
||||
padding-right: 0px;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row .custom-view-tree-node-item .actions {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .monaco-list-row:hover .custom-view-tree-node-item .actions,
|
||||
.customview-tree .monaco-list .monaco-list-row.selected .custom-view-tree-node-item .actions,
|
||||
.customview-tree .monaco-list .monaco-list-row.focused .custom-view-tree-node-item .actions {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .custom-view-tree-node-item .actions .action-label {
|
||||
width: 16px;
|
||||
height: 100%;
|
||||
background-size: 16px;
|
||||
background-position: 50% 50%;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .custom-view-tree-node-item .actions .action-label.codicon {
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.customview-tree .monaco-list .custom-view-tree-node-item .actions .action-label.codicon::before {
|
||||
vertical-align: middle;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ConnectionDialogWidget } from 'sql/workbench/services/connection/browser/connectionDialogWidget';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
|
||||
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { ITextResourcePropertiesService } from 'vs/editor/common/services/textResourceConfigurationService';
|
||||
import { IViewDescriptorService } from 'vs/workbench/common/views';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
export class TestConnectionDialogWidget extends ConnectionDialogWidget {
|
||||
constructor(
|
||||
providerDisplayNameOptions: string[],
|
||||
selectedProviderType: string,
|
||||
providerNameToDisplayNameMap: { [providerDisplayName: string]: string },
|
||||
@IInstantiationService _instantiationService: IInstantiationService,
|
||||
@IConnectionManagementService _connectionManagementService: IConnectionManagementService,
|
||||
@IContextMenuService _contextMenuService: IContextMenuService,
|
||||
@IContextViewService _contextViewService: IContextViewService,
|
||||
@IViewDescriptorService viewDescriptorService: IViewDescriptorService,
|
||||
@IThemeService themeService: IThemeService,
|
||||
@ILayoutService layoutService: ILayoutService,
|
||||
@IAdsTelemetryService telemetryService: IAdsTelemetryService,
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
@IClipboardService clipboardService: IClipboardService,
|
||||
@ILogService logService: ILogService,
|
||||
@ITextResourcePropertiesService textResourcePropertiesService: ITextResourcePropertiesService,
|
||||
@IConfigurationService configurationService: IConfigurationService
|
||||
) {
|
||||
super(providerDisplayNameOptions, selectedProviderType, providerNameToDisplayNameMap, _instantiationService, _connectionManagementService, _contextMenuService, _contextViewService, viewDescriptorService, themeService, layoutService, telemetryService, contextKeyService, clipboardService, logService, textResourcePropertiesService, configurationService);
|
||||
}
|
||||
public renderBody(container: HTMLElement) {
|
||||
super.renderBody(container);
|
||||
}
|
||||
}
|
||||
1049
src/sql/workbench/services/connection/test/browser/testTreeView.ts
Normal file
1049
src/sql/workbench/services/connection/test/browser/testTreeView.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user