mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 17:22:45 -05:00
ServerTreeView unit tests (#11207)
* added unit tests * removed newlines
This commit is contained in:
@@ -6,15 +6,16 @@
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ServerTreeView } from 'sql/workbench/contrib/objectExplorer/browser/serverTreeView';
|
||||
import { ConnectionManagementService } from 'sql/workbench/services/connection/browser/connectionManagementService';
|
||||
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
||||
import { TestTree } from 'sql/workbench/test/treeMock';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
|
||||
import { TreeItemCollapsibleState } from 'sql/workbench/services/objectExplorer/common/treeNode';
|
||||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
import * as assert from 'assert';
|
||||
|
||||
suite('ServerTreeView onAddConnectionProfile handler tests', () => {
|
||||
|
||||
@@ -22,7 +23,7 @@ suite('ServerTreeView onAddConnectionProfile handler tests', () => {
|
||||
let mockTree: TypeMoq.Mock<ITree>;
|
||||
let mockRefreshTreeMethod: TypeMoq.Mock<Function>;
|
||||
let capabilitiesService = new TestCapabilitiesService();
|
||||
|
||||
let newProfile;
|
||||
setup(() => {
|
||||
let instantiationService = new TestInstantiationService();
|
||||
instantiationService.stub(IStorageService, new TestStorageService());
|
||||
@@ -38,7 +39,7 @@ suite('ServerTreeView onAddConnectionProfile handler tests', () => {
|
||||
);
|
||||
mockConnectionManagementService.setup(x => x.getConnectionGroups()).returns(x => []);
|
||||
mockConnectionManagementService.setup(x => x.hasRegisteredServers()).returns(() => true);
|
||||
serverTreeView = new ServerTreeView(mockConnectionManagementService.object, instantiationService, undefined, undefined, undefined, undefined, capabilitiesService);
|
||||
serverTreeView = new ServerTreeView(mockConnectionManagementService.object, instantiationService, undefined, new TestThemeService(), undefined, undefined, capabilitiesService);
|
||||
mockTree = TypeMoq.Mock.ofType(TestTree);
|
||||
(serverTreeView as any)._tree = mockTree.object;
|
||||
mockRefreshTreeMethod = TypeMoq.Mock.ofType(Function);
|
||||
@@ -46,6 +47,9 @@ suite('ServerTreeView onAddConnectionProfile handler tests', () => {
|
||||
(serverTreeView as any).refreshTree = mockRefreshTreeMethod.object;
|
||||
mockTree.setup(x => x.clearSelection());
|
||||
mockTree.setup(x => x.select(TypeMoq.It.isAny()));
|
||||
newProfile = <IConnectionProfile>{
|
||||
id: 'test_connection'
|
||||
};
|
||||
});
|
||||
|
||||
async function runAddConnectionProfileHandler(oldSelection, newProfile): Promise<void> {
|
||||
@@ -53,6 +57,81 @@ suite('ServerTreeView onAddConnectionProfile handler tests', () => {
|
||||
return (serverTreeView as any).handleAddConnectionProfile(newProfile);
|
||||
}
|
||||
|
||||
|
||||
test('layout', async () => {
|
||||
mockTree.setup(x => x.layout(TypeMoq.It.isAnyNumber()));
|
||||
serverTreeView.layout(1);
|
||||
mockTree.verify(x => x.layout(TypeMoq.It.isAnyNumber()), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
test('setVisibility', async () => {
|
||||
mockTree.setup(x => x.onVisible());
|
||||
mockTree.setup(x => x.onHidden());
|
||||
serverTreeView.setVisible(true);
|
||||
mockTree.verify(x => x.onVisible(), TypeMoq.Times.once());
|
||||
serverTreeView.setVisible(false);
|
||||
mockTree.verify(x => x.onHidden(), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
test('getSelection', async () => {
|
||||
mockTree.setup(x => x.getSelection());
|
||||
|
||||
serverTreeView.getSelection();
|
||||
mockTree.verify(x => x.getSelection(), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
test('isFocused', async () => {
|
||||
mockTree.setup(x => x.isDOMFocused());
|
||||
serverTreeView.isFocused();
|
||||
mockTree.verify(x => x.isDOMFocused(), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
test('reveal', async () => {
|
||||
mockTree.setup(x => x.reveal(TypeMoq.It.isAny()));
|
||||
serverTreeView.reveal(newProfile);
|
||||
mockTree.verify(x => x.reveal(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
test('isObjectExplorerConnectionUri', async () => {
|
||||
let connectionUriFalse = serverTreeView.isObjectExplorerConnectionUri('123');
|
||||
assert.equal(false, connectionUriFalse);
|
||||
assert.equal(true, serverTreeView.isObjectExplorerConnectionUri('connection:123'));
|
||||
});
|
||||
|
||||
test('setExpandedState', async () => {
|
||||
mockTree.setup(x => x.collapse(TypeMoq.It.isAny()));
|
||||
mockTree.setup(x => x.expand(TypeMoq.It.isAny()));
|
||||
serverTreeView.setExpandedState(newProfile, TreeItemCollapsibleState.Collapsed);
|
||||
mockTree.verify(x => x.collapse(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
serverTreeView.setExpandedState(newProfile, TreeItemCollapsibleState.Expanded);
|
||||
mockTree.verify(x => x.expand(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
test('setSelected', async () => {
|
||||
mockTree.setup(x => x.reveal(TypeMoq.It.isAny()));
|
||||
mockTree.setup(x => x.deselect(TypeMoq.It.isAny()));
|
||||
serverTreeView.setSelected(newProfile, true, true);
|
||||
mockTree.verify(x => x.clearSelection(), TypeMoq.Times.once());
|
||||
mockTree.verify(x => x.select(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
mockTree.verify(x => x.reveal(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
serverTreeView.setSelected(newProfile, false, false);
|
||||
mockTree.verify(x => x.deselect(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
test('isExpanded', async () => {
|
||||
mockTree.setup(x => x.isExpanded(TypeMoq.It.isAny()));
|
||||
serverTreeView.isExpanded(newProfile);
|
||||
mockTree.verify(x => x.isExpanded(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
test('refreshElement', async () => {
|
||||
mockTree.setup(x => x.refresh(TypeMoq.It.isAny()));
|
||||
serverTreeView.refreshElement(newProfile);
|
||||
mockTree.verify(x => x.refresh(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
|
||||
|
||||
test('onAddConnectionProfile handler selects the new profile when no profile is already selected', async () => {
|
||||
let newProfile = <IConnectionProfile>{
|
||||
id: 'test_connection'
|
||||
|
||||
Reference in New Issue
Block a user