Put back code to refresh tree when capabilities provider gets new capabilities (#4475)

This commit is contained in:
Matt Irvine
2019-03-13 17:41:29 -07:00
committed by GitHub
parent e59d5a766f
commit 82ce1ace28
4 changed files with 26 additions and 6 deletions

View File

@@ -32,6 +32,7 @@ import { TreeNode, TreeItemCollapsibleState } from 'sql/parts/objectExplorer/com
import { SERVER_GROUP_CONFIG, SERVER_GROUP_AUTOEXPAND_CONFIG } from 'sql/parts/objectExplorer/serverGroupDialog/serverGroup.contribution';
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
import { ServerTreeActionProvider } from 'sql/parts/objectExplorer/viewlet/serverTreeActionProvider';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
const $ = builder.$;
@@ -54,7 +55,8 @@ export class ServerTreeView {
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
@IThemeService private _themeService: IThemeService,
@IErrorMessageService private _errorMessageService: IErrorMessageService,
@IConfigurationService private _configurationService: IConfigurationService
@IConfigurationService private _configurationService: IConfigurationService,
@ICapabilitiesService capabilitiesService: ICapabilitiesService
) {
this._activeConnectionsFilterAction = this._instantiationService.createInstance(
ActiveConnectionsFilterAction,
@@ -64,6 +66,12 @@ export class ServerTreeView {
this._treeSelectionHandler = this._instantiationService.createInstance(TreeSelectionHandler);
this._onSelectionOrFocusChange = new Emitter();
this._actionProvider = this._instantiationService.createInstance(ServerTreeActionProvider);
capabilitiesService.onCapabilitiesRegistered(() => {
if (this._connectionManagementService.hasRegisteredServers()) {
this.refreshTree();
this._treeSelectionHandler.onTreeActionStateChange(false);
}
});
}
/**

View File

@@ -205,7 +205,7 @@ suite('SQL Connection Tree Action tests', () => {
return new TPromise((resolve) => resolve({}));
});
let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined);
let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined, undefined, capabilitiesService);
serverTreeView.setup(x => x.showFilteredTree(TypeMoq.It.isAnyString()));
serverTreeView.setup(x => x.refreshTree());
let connectionTreeAction: ActiveConnectionsFilterAction = new ActiveConnectionsFilterAction(ActiveConnectionsFilterAction.ID, ActiveConnectionsFilterAction.LABEL, serverTreeView.object, connectionManagementService.object);
@@ -222,7 +222,7 @@ suite('SQL Connection Tree Action tests', () => {
return new TPromise((resolve) => resolve({}));
});
let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined);
let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined, undefined, capabilitiesService);
serverTreeView.setup(x => x.showFilteredTree(TypeMoq.It.isAnyString()));
serverTreeView.setup(x => x.refreshTree());
let connectionTreeAction: ActiveConnectionsFilterAction = new ActiveConnectionsFilterAction(ActiveConnectionsFilterAction.ID, ActiveConnectionsFilterAction.LABEL, serverTreeView.object, connectionManagementService.object);
@@ -240,7 +240,7 @@ suite('SQL Connection Tree Action tests', () => {
return new TPromise((resolve) => resolve({}));
});
let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined);
let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined, undefined, capabilitiesService);
serverTreeView.setup(x => x.showFilteredTree(TypeMoq.It.isAnyString()));
serverTreeView.setup(x => x.refreshTree());
let connectionTreeAction: RecentConnectionsFilterAction = new RecentConnectionsFilterAction(RecentConnectionsFilterAction.ID, RecentConnectionsFilterAction.LABEL, serverTreeView.object, connectionManagementService.object);
@@ -257,7 +257,7 @@ suite('SQL Connection Tree Action tests', () => {
return new TPromise((resolve) => resolve({}));
});
let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined);
let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined, undefined, capabilitiesService);
serverTreeView.setup(x => x.showFilteredTree(TypeMoq.It.isAnyString()));
serverTreeView.setup(x => x.refreshTree());
let connectionTreeAction: RecentConnectionsFilterAction = new RecentConnectionsFilterAction(RecentConnectionsFilterAction.ID, RecentConnectionsFilterAction.LABEL, serverTreeView.object, connectionManagementService.object);

View File

@@ -14,18 +14,21 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/
import { TestStorageService } from 'vs/workbench/test/workbenchTestServices';
import * as TypeMoq from 'typemoq';
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
suite('ServerTreeView onAddConnectionProfile handler tests', () => {
let serverTreeView: ServerTreeView;
let mockTree: TypeMoq.Mock<Tree>;
let mockRefreshTreeMethod: TypeMoq.Mock<Function>;
let capabilitiesService = new CapabilitiesTestService();
setup(() => {
let instantiationService = new TestInstantiationService();
let mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict, {}, {}, new TestStorageService());
mockConnectionManagementService.setup(x => x.getConnectionGroups()).returns(x => []);
serverTreeView = new ServerTreeView(mockConnectionManagementService.object, instantiationService, undefined, undefined, undefined, undefined);
mockConnectionManagementService.setup(x => x.hasRegisteredServers()).returns(() => true);
serverTreeView = new ServerTreeView(mockConnectionManagementService.object, instantiationService, undefined, undefined, undefined, undefined, capabilitiesService);
let tree = <Tree>{
clearSelection() { },
getSelection() { },
@@ -91,4 +94,9 @@ suite('ServerTreeView onAddConnectionProfile handler tests', () => {
mockTree.verify(x => x.clearSelection(), TypeMoq.Times.never());
mockTree.verify(x => x.select(TypeMoq.It.isAny()), TypeMoq.Times.never());
});
test('The tree refreshes when new capabilities are registered', () => {
capabilitiesService.fireCapabilitiesRegistered(undefined);
mockRefreshTreeMethod.verify(x => x(), TypeMoq.Times.once());
});
});

View File

@@ -138,6 +138,10 @@ export class CapabilitiesTestService implements ICapabilitiesService {
return Promise.resolve(null);
}
public fireCapabilitiesRegistered(providerFeatures: ProviderFeatures): void {
this._onCapabilitiesRegistered.fire(providerFeatures);
}
private _onCapabilitiesRegistered = new Emitter<ProviderFeatures>();
public readonly onCapabilitiesRegistered = this._onCapabilitiesRegistered.event;
}