Add tab coloring by server group (#383)

This commit is contained in:
Matt Irvine
2017-12-20 18:21:48 -08:00
committed by GitHub
parent 3ffafbe5bc
commit b1b3a92717
14 changed files with 152 additions and 8 deletions

View File

@@ -32,6 +32,7 @@ import { WorkspaceConfigurationTestService } from 'sqltest/stubs/workspaceConfig
import * as assert from 'assert';
import * as TypeMoq from 'typemoq';
import { IConnectionProfileGroup } from 'sql/parts/connection/common/connectionProfileGroup';
suite('SQL ConnectionManagementService tests', () => {
@@ -210,7 +211,7 @@ suite('SQL ConnectionManagementService tests', () => {
let connectionToUse = connection ? connection : connectionProfile;
return new Promise<IConnectionResult>((resolve, reject) => {
let id = connectionToUse.getOptionsKey();
let defaultUri = 'connection://' + (id ? id : connection.serverName + ':' + connection.databaseName);
let defaultUri = 'connection://' + (id ? id : connectionToUse.serverName + ':' + connectionToUse.databaseName);
connectionManagementService.onConnectionRequestSent(() => {
let info: data.ConnectionInfoSummary = {
connectionId: error ? undefined : 'id',
@@ -290,7 +291,7 @@ suite('SQL ConnectionManagementService tests', () => {
}).catch(err => {
done(err);
});
});
}, err => done(err));
});
test('connect should save profile given options with saveProfile set to true', done => {
@@ -764,4 +765,29 @@ suite('SQL ConnectionManagementService tests', () => {
}
}, err => done(err));
});
test('getTabColorForUri returns undefined when there is no connection for the given URI', () => {
let connectionManagementService = createConnectionManagementService();
let color = connectionManagementService.getTabColorForUri('invalidUri');
assert.equal(color, undefined);
});
test('getTabColorForUri returns the group color corresponding to the connection for a URI', done => {
// Set up the connection store to give back a group for the expected connection profile
configResult['enableTabColors'] = true;
let expectedColor = 'red';
connectionStore.setup(x => x.getGroupFromId(connectionProfile.groupId)).returns(() => <IConnectionProfileGroup> {
color: expectedColor
});
let uri = 'testUri';
connect(uri).then(() => {
try {
let tabColor = connectionManagementService.getTabColorForUri(uri);
assert.equal(tabColor, expectedColor);
done();
} catch (e) {
done(e);
}
}, err => done(err));
});
});

View File

@@ -18,7 +18,7 @@ import { CapabilitiesService } from 'sql/services/capabilities/capabilitiesServi
import * as data from 'data';
import { ConnectionProfile } from 'sql/parts/connection/common/connectionProfile';
import { Emitter } from 'vs/base/common/event';
import { IConnectionProfileGroup } from 'sql/parts/connection/common/connectionProfileGroup';
import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/parts/connection/common/connectionProfileGroup';
suite('SQL ConnectionStore tests', () => {
let defaultNamedProfile: IConnectionProfile;
@@ -93,7 +93,7 @@ suite('SQL ConnectionStore tests', () => {
getInstalled: () => {
return Promise.resolve([]);
}
}
};
capabilitiesService = TypeMoq.Mock.ofType(CapabilitiesService, TypeMoq.MockBehavior.Loose, extensionManagementServiceMock, {});
let capabilities: data.DataProtocolServerCapabilities[] = [];
@@ -462,4 +462,33 @@ suite('SQL ConnectionStore tests', () => {
currentList = connectionStore.getConnectionsFromMemento(mementoKey);
assert.equal(currentList.length, 3, 'Adding same connection with group /');
});
test('getGroupFromId returns undefined when there is no group with the given ID', () => {
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
let group = connectionStore.getGroupFromId('invalidId');
assert.equal(group, undefined, 'Returned group was not undefined when there was no group with the given ID');
});
test('getGroupFromId returns the group that has the given ID', () => {
// Set up the server groups with an additional group that contains a child group
let groups: IConnectionProfileGroup[] = connectionConfig.object.getAllGroups();
let parentGroupId = 'parentGroup';
let childGroupId = 'childGroup';
let parentGroup = new ConnectionProfileGroup(parentGroupId, undefined, parentGroupId, '', '');
let childGroup = new ConnectionProfileGroup(childGroupId, parentGroup, childGroupId, '', '');
groups.push(parentGroup, childGroup);
let newConnectionConfig = TypeMoq.Mock.ofType(ConnectionConfig);
newConnectionConfig.setup(x => x.getAllGroups()).returns(() => groups);
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, newConnectionConfig.object);
// If I look up the parent group using its ID, then I get back the correct group
let actualGroup = connectionStore.getGroupFromId(parentGroupId);
assert.equal(actualGroup.id, parentGroupId, 'Did not get the parent group when looking it up with its ID');
// If I look up the child group using its ID, then I get back the correct group
actualGroup = connectionStore.getGroupFromId(childGroupId);
assert.equal(actualGroup.id, childGroupId, 'Did not get the child group when looking it up with its ID');
});
});

View File

@@ -237,4 +237,8 @@ export class TestConnectionManagementService implements IConnectionManagementSer
rebuildIntelliSenseCache(uri: string): Thenable<void> {
return undefined;
}
getTabColorForUri(uri: string): string {
return undefined;
}
}