mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 10:38:31 -05:00
Added multiple location option to package management dialog (#9790)
* Added multiple location option to package management dialog
This commit is contained in:
@@ -0,0 +1,295 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { ManagePackagesDialog } from '../../dialog/managePackages/managePackagesDialog';
|
||||
import { ManagePackagesDialogModel } from '../../dialog/managePackages/managePackagesDialogModel';
|
||||
import { IPackageManageProvider, IPackageLocation } from '../../types';
|
||||
import { LocalCondaPackageManageProvider } from '../../jupyter/localCondaPackageManageProvider';
|
||||
import { InstalledPackagesTab } from '../../dialog/managePackages/installedPackagesTab';
|
||||
import should = require('should');
|
||||
|
||||
interface TestContext {
|
||||
view: azdata.ModelView;
|
||||
onClick: vscode.EventEmitter<any>;
|
||||
dialog: TypeMoq.IMock<ManagePackagesDialog>;
|
||||
model: TypeMoq.IMock<ManagePackagesDialogModel>;
|
||||
}
|
||||
|
||||
describe('Manage Package Dialog', () => {
|
||||
|
||||
it('getLocationComponent should create text component for one location', async function (): Promise<void> {
|
||||
let testContext = createViewContext();
|
||||
let locations = [
|
||||
{
|
||||
displayName: 'dl1',
|
||||
name: 'nl1'
|
||||
}
|
||||
];
|
||||
testContext.model.setup(x => x.getLocations()).returns(() => Promise.resolve(locations));
|
||||
testContext.model.setup(x => x.changeLocation('nl1'));
|
||||
testContext.dialog.setup(x => x.changeLocation('nl1'));
|
||||
|
||||
let actual = await InstalledPackagesTab.getLocationComponent(testContext.view, testContext.dialog.object);
|
||||
should.equal('onTextChanged' in actual, true);
|
||||
testContext.dialog.verify(x => x.changeLocation('nl1'), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
it('getLocationComponent should create text component for undefined location', async function (): Promise<void> {
|
||||
let testContext = createViewContext();
|
||||
let locations: IPackageLocation[] | undefined = undefined;
|
||||
testContext.model.setup(x => x.getLocations()).returns(() => Promise.resolve(locations));
|
||||
|
||||
let actual = await InstalledPackagesTab.getLocationComponent(testContext.view, testContext.dialog.object);
|
||||
should.equal('onTextChanged' in actual, true);
|
||||
});
|
||||
|
||||
it('getLocationComponent should create drop down component for more than one location', async function (): Promise<void> {
|
||||
let testContext = createViewContext();
|
||||
let locations = [
|
||||
{
|
||||
displayName: 'dl1',
|
||||
name: 'nl1'
|
||||
},
|
||||
{
|
||||
displayName: 'dl2',
|
||||
name: 'nl2'
|
||||
}
|
||||
];
|
||||
testContext.model.setup(x => x.getLocations()).returns(() => Promise.resolve(locations));
|
||||
testContext.dialog.setup(x => x.changeLocation('nl1'));
|
||||
testContext.dialog.setup(x => x.resetPages()).returns(() => Promise.resolve());
|
||||
|
||||
let actual = await InstalledPackagesTab.getLocationComponent(testContext.view, testContext.dialog.object);
|
||||
should.equal('onValueChanged' in actual, true);
|
||||
testContext.dialog.verify(x => x.changeLocation('nl1'), TypeMoq.Times.once());
|
||||
(<azdata.DropDownComponent>actual).value = {
|
||||
displayName: 'dl2',
|
||||
name: 'nl2'
|
||||
};
|
||||
testContext.onClick.fire();
|
||||
testContext.dialog.verify(x => x.changeLocation('nl2'), TypeMoq.Times.once());
|
||||
testContext.dialog.verify(x => x.resetPages(), TypeMoq.Times.once());
|
||||
|
||||
});
|
||||
|
||||
it('getLocationComponent should show error if reset pages fails', async function (): Promise<void> {
|
||||
let testContext = createViewContext();
|
||||
let locations = [
|
||||
{
|
||||
displayName: 'dl1',
|
||||
name: 'nl1'
|
||||
},
|
||||
{
|
||||
displayName: 'dl2',
|
||||
name: 'nl2'
|
||||
}
|
||||
];
|
||||
testContext.model.setup(x => x.getLocations()).returns(() => Promise.resolve(locations));
|
||||
testContext.dialog.setup(x => x.changeLocation('nl1'));
|
||||
testContext.dialog.setup(x => x.resetPages()).throws(new Error('failed'));
|
||||
testContext.dialog.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns(() => Promise.resolve());
|
||||
|
||||
let actual = await InstalledPackagesTab.getLocationComponent(testContext.view, testContext.dialog.object);
|
||||
should.equal('onValueChanged' in actual, true);
|
||||
testContext.dialog.verify(x => x.changeLocation('nl1'), TypeMoq.Times.once());
|
||||
(<azdata.DropDownComponent>actual).value = {
|
||||
displayName: 'dl2',
|
||||
name: 'nl2'
|
||||
};
|
||||
testContext.onClick.fire();
|
||||
testContext.dialog.verify(x => x.changeLocation('nl2'), TypeMoq.Times.once());
|
||||
testContext.dialog.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
|
||||
});
|
||||
|
||||
function createViewContext(): TestContext {
|
||||
let packageManageProviders = new Map<string, IPackageManageProvider>();
|
||||
packageManageProviders.set(LocalCondaPackageManageProvider.ProviderId, new LocalCondaPackageManageProvider(undefined));
|
||||
let model = TypeMoq.Mock.ofInstance(new ManagePackagesDialogModel(undefined, packageManageProviders));
|
||||
let dialog = TypeMoq.Mock.ofInstance(new ManagePackagesDialog(model.object));
|
||||
dialog.setup(x => x.model).returns(() => model.object);
|
||||
|
||||
let onClick: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
|
||||
|
||||
let componentBase: azdata.Component = {
|
||||
id: '',
|
||||
updateProperties: () => Promise.resolve(),
|
||||
updateProperty: () => Promise.resolve(),
|
||||
updateCssStyles: undefined!,
|
||||
onValidityChanged: undefined!,
|
||||
valid: true,
|
||||
validate: undefined!,
|
||||
focus: undefined!
|
||||
};
|
||||
let button: azdata.ButtonComponent = Object.assign({}, componentBase, {
|
||||
onDidClick: onClick.event
|
||||
});
|
||||
let radioButton: azdata.RadioButtonComponent = Object.assign({}, componentBase, {
|
||||
onDidClick: onClick.event
|
||||
});
|
||||
const components: azdata.Component[] = [];
|
||||
let container = {
|
||||
clearItems: () => { },
|
||||
addItems: () => { },
|
||||
addItem: () => { },
|
||||
removeItem: () => true,
|
||||
insertItem: () => { },
|
||||
items: components,
|
||||
setLayout: () => { }
|
||||
};
|
||||
let form: azdata.FormContainer = Object.assign({}, componentBase, container, {
|
||||
});
|
||||
let flex: azdata.FlexContainer = Object.assign({}, componentBase, container, {
|
||||
});
|
||||
|
||||
let buttonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent> = {
|
||||
component: () => button,
|
||||
withProperties: () => buttonBuilder,
|
||||
withValidation: () => buttonBuilder
|
||||
};
|
||||
let radioButtonBuilder: azdata.ComponentBuilder<azdata.ButtonComponent> = {
|
||||
component: () => radioButton,
|
||||
withProperties: () => radioButtonBuilder,
|
||||
withValidation: () => radioButtonBuilder
|
||||
};
|
||||
let inputBox: () => azdata.InputBoxComponent = () => Object.assign({}, componentBase, {
|
||||
onTextChanged: undefined!,
|
||||
onEnterKeyPressed: undefined!,
|
||||
value: ''
|
||||
});
|
||||
let image: () => azdata.ImageComponent = () => Object.assign({}, componentBase, {
|
||||
|
||||
});
|
||||
let dropdown: () => azdata.DropDownComponent = () => Object.assign({}, componentBase, {
|
||||
onValueChanged: onClick.event,
|
||||
value: {
|
||||
name: '',
|
||||
displayName: ''
|
||||
},
|
||||
values: []
|
||||
});
|
||||
let declarativeTable: () => azdata.DeclarativeTableComponent = () => Object.assign({}, componentBase, {
|
||||
onDataChanged: undefined!,
|
||||
data: [],
|
||||
columns: []
|
||||
});
|
||||
|
||||
let loadingComponent: () => azdata.LoadingComponent = () => Object.assign({}, componentBase, {
|
||||
loading: false,
|
||||
component: undefined!
|
||||
});
|
||||
|
||||
let declarativeTableBuilder: azdata.ComponentBuilder<azdata.DeclarativeTableComponent> = {
|
||||
component: () => declarativeTable(),
|
||||
withProperties: () => declarativeTableBuilder,
|
||||
withValidation: () => declarativeTableBuilder
|
||||
};
|
||||
|
||||
let loadingBuilder: azdata.LoadingComponentBuilder = {
|
||||
component: () => loadingComponent(),
|
||||
withProperties: () => loadingBuilder,
|
||||
withValidation: () => loadingBuilder,
|
||||
withItem: () => loadingBuilder
|
||||
};
|
||||
|
||||
let formBuilder: azdata.FormBuilder = Object.assign({}, {
|
||||
component: () => form,
|
||||
addFormItem: () => { },
|
||||
insertFormItem: () => { },
|
||||
removeFormItem: () => true,
|
||||
addFormItems: () => { },
|
||||
withFormItems: () => formBuilder,
|
||||
withProperties: () => formBuilder,
|
||||
withValidation: () => formBuilder,
|
||||
withItems: () => formBuilder,
|
||||
withLayout: () => formBuilder
|
||||
});
|
||||
|
||||
let flexBuilder: azdata.FlexBuilder = Object.assign({}, {
|
||||
component: () => flex,
|
||||
withProperties: () => flexBuilder,
|
||||
withValidation: () => flexBuilder,
|
||||
withItems: () => flexBuilder,
|
||||
withLayout: () => flexBuilder
|
||||
});
|
||||
|
||||
let inputBoxBuilder: azdata.ComponentBuilder<azdata.InputBoxComponent> = {
|
||||
component: () => {
|
||||
let r = inputBox();
|
||||
return r;
|
||||
},
|
||||
withProperties: () => inputBoxBuilder,
|
||||
withValidation: () => inputBoxBuilder
|
||||
};
|
||||
let imageBuilder: azdata.ComponentBuilder<azdata.ImageComponent> = {
|
||||
component: () => {
|
||||
let r = image();
|
||||
return r;
|
||||
},
|
||||
withProperties: () => imageBuilder,
|
||||
withValidation: () => imageBuilder
|
||||
};
|
||||
let dropdownBuilder: azdata.ComponentBuilder<azdata.DropDownComponent> = {
|
||||
component: () => {
|
||||
let r = dropdown();
|
||||
return r;
|
||||
},
|
||||
withProperties: () => dropdownBuilder,
|
||||
withValidation: () => dropdownBuilder
|
||||
};
|
||||
|
||||
let view: azdata.ModelView = {
|
||||
onClosed: undefined!,
|
||||
connection: undefined!,
|
||||
serverInfo: undefined!,
|
||||
valid: true,
|
||||
onValidityChanged: undefined!,
|
||||
validate: undefined!,
|
||||
initializeModel: () => { return Promise.resolve(); },
|
||||
modelBuilder: {
|
||||
radioCardGroup: undefined!,
|
||||
navContainer: undefined!,
|
||||
divContainer: undefined!,
|
||||
flexContainer: () => flexBuilder,
|
||||
splitViewContainer: undefined!,
|
||||
dom: undefined!,
|
||||
card: undefined!,
|
||||
inputBox: () => inputBoxBuilder,
|
||||
checkBox: undefined!,
|
||||
radioButton: () => radioButtonBuilder,
|
||||
webView: undefined!,
|
||||
editor: undefined!,
|
||||
diffeditor: undefined!,
|
||||
text: () => inputBoxBuilder,
|
||||
image: () => imageBuilder,
|
||||
button: () => buttonBuilder,
|
||||
dropDown: () => dropdownBuilder,
|
||||
tree: undefined!,
|
||||
listBox: undefined!,
|
||||
table: undefined!,
|
||||
declarativeTable: () => declarativeTableBuilder,
|
||||
dashboardWidget: undefined!,
|
||||
dashboardWebview: undefined!,
|
||||
formContainer: () => formBuilder,
|
||||
groupContainer: undefined!,
|
||||
toolbarContainer: undefined!,
|
||||
loadingComponent: () => loadingBuilder,
|
||||
fileBrowserTree: undefined!,
|
||||
hyperlink: undefined!,
|
||||
tabbedPanel: undefined!,
|
||||
separator: undefined!
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
dialog: dialog,
|
||||
model: model,
|
||||
view: view,
|
||||
onClick: onClick,
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -50,7 +50,6 @@ describe('Manage Packages', () => {
|
||||
providers.set(provider.providerId, provider);
|
||||
|
||||
let options = {
|
||||
multiLocations: true,
|
||||
defaultLocation: 'invalid location'
|
||||
};
|
||||
let model = new ManagePackagesDialogModel(jupyterServerInstallation, providers, options);
|
||||
@@ -64,29 +63,12 @@ describe('Manage Packages', () => {
|
||||
providers.set(provider.providerId, provider);
|
||||
|
||||
let options = {
|
||||
multiLocations: true,
|
||||
defaultProviderId: 'invalid provider'
|
||||
};
|
||||
let model = new ManagePackagesDialogModel(jupyterServerInstallation, providers, options);
|
||||
await should(model.init()).rejectedWith(`Invalid default provider id '${options.defaultProviderId}`);
|
||||
});
|
||||
|
||||
/* Test disabled. Tracking issue: https://github.com/microsoft/azuredatastudio/issues/8877
|
||||
it('Init should throw exception not given valid default location for single location mode', async function (): Promise<void> {
|
||||
let testContext = createContext();
|
||||
let provider = createProvider(testContext);
|
||||
let providers = new Map<string, IPackageManageProvider>();
|
||||
providers.set(provider.providerId, provider);
|
||||
|
||||
let options = {
|
||||
multiLocations: false
|
||||
};
|
||||
let model = new ManagePackagesDialogModel(jupyterServerInstallation, providers, options);
|
||||
await should(model.init()).rejectedWith(`Default location not specified for single location mode`);
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
it('Init should set default options given undefined', async function (): Promise<void> {
|
||||
let testContext = createContext();
|
||||
let provider = createProvider(testContext);
|
||||
@@ -96,7 +78,6 @@ describe('Manage Packages', () => {
|
||||
let model = new ManagePackagesDialogModel(jupyterServerInstallation, providers, undefined);
|
||||
|
||||
await model.init();
|
||||
should.equal(model.multiLocationMode, true);
|
||||
should.equal(model.defaultLocation, provider.packageTarget.location);
|
||||
should.equal(model.defaultProviderId, provider.providerId);
|
||||
});
|
||||
@@ -119,14 +100,12 @@ describe('Manage Packages', () => {
|
||||
providers.set(testContext1.provider.providerId, createProvider(testContext1));
|
||||
providers.set(testContext2.provider.providerId, createProvider(testContext2));
|
||||
let options = {
|
||||
multiLocations: false,
|
||||
defaultLocation: testContext2.provider.packageTarget.location,
|
||||
defaultProviderId: testContext2.provider.providerId
|
||||
};
|
||||
let model = new ManagePackagesDialogModel(jupyterServerInstallation, providers, options);
|
||||
|
||||
await model.init();
|
||||
should.equal(model.multiLocationMode, false);
|
||||
should.equal(model.defaultLocation, testContext2.provider.packageTarget.location);
|
||||
should.equal(model.defaultProviderId, testContext2.provider.providerId);
|
||||
});
|
||||
@@ -195,7 +174,7 @@ describe('Manage Packages', () => {
|
||||
it('changeProvider should change current provider successfully', async function (): Promise<void> {
|
||||
let testContext1 = createContext();
|
||||
testContext1.provider.providerId = 'providerId1';
|
||||
testContext1.provider.getLocationTitle = () => Promise.resolve('location title 1');
|
||||
testContext1.provider.getLocations = () => Promise.resolve([{displayName: 'location title 1', name: 'location1'}]);
|
||||
testContext1.provider.packageTarget = {
|
||||
location: 'location1',
|
||||
packageType: 'package-type1'
|
||||
@@ -203,7 +182,7 @@ describe('Manage Packages', () => {
|
||||
|
||||
let testContext2 = createContext();
|
||||
testContext2.provider.providerId = 'providerId2';
|
||||
testContext2.provider.getLocationTitle = () => Promise.resolve('location title 2');
|
||||
testContext2.provider.getLocations = () => Promise.resolve([{displayName: 'location title 2', name: 'location2'}]);
|
||||
testContext2.provider.packageTarget = {
|
||||
location: 'location2',
|
||||
packageType: 'package-type2'
|
||||
@@ -217,7 +196,7 @@ describe('Manage Packages', () => {
|
||||
|
||||
await model.init();
|
||||
model.changeProvider('providerId2');
|
||||
should.deepEqual(await model.getLocationTitle(), 'location title 2');
|
||||
should.deepEqual(await model.getLocations(), [{displayName: 'location title 2', name: 'location2'}]);
|
||||
});
|
||||
|
||||
it('changeProvider should throw exception given invalid provider', async function (): Promise<void> {
|
||||
@@ -283,7 +262,7 @@ describe('Manage Packages', () => {
|
||||
|
||||
let testContext2 = createContext();
|
||||
testContext2.provider.providerId = 'providerId2';
|
||||
testContext2.provider.getLocationTitle = () => Promise.resolve('location title 2');
|
||||
testContext2.provider.getLocations = () => Promise.resolve([{displayName: 'location title 2', name: 'location2'}]);
|
||||
testContext2.provider.packageTarget = {
|
||||
location: 'location2',
|
||||
packageType: 'package-type2'
|
||||
@@ -301,6 +280,12 @@ describe('Manage Packages', () => {
|
||||
testContext2.provider.listPackages = () => {
|
||||
return Promise.resolve(packages);
|
||||
};
|
||||
testContext1.provider.listPackages = () => {
|
||||
return Promise.resolve([{
|
||||
name: 'p3',
|
||||
version: '1.1.1.3'
|
||||
}]);
|
||||
};
|
||||
|
||||
let providers = new Map<string, IPackageManageProvider>();
|
||||
providers.set(testContext1.provider.providerId, createProvider(testContext1));
|
||||
@@ -315,7 +300,50 @@ describe('Manage Packages', () => {
|
||||
await should(model.installPackages(packages)).resolved();
|
||||
await should(model.uninstallPackages(packages)).resolved();
|
||||
await should(model.getPackageOverview('p1')).resolved();
|
||||
await should(model.getLocationTitle()).resolvedWith('location title 2');
|
||||
await should(model.getLocations()).resolvedWith([{displayName: 'location title 2', name: 'location2'}]);
|
||||
});
|
||||
|
||||
it('listPackages should return packages for current location', async function (): Promise<void> {
|
||||
let testContext = createContext();
|
||||
testContext.provider.providerId = 'providerId1';
|
||||
testContext.provider.packageTarget = {
|
||||
location: 'location1',
|
||||
packageType: 'package-type1'
|
||||
};
|
||||
|
||||
let packages1 = [
|
||||
{
|
||||
name: 'p1',
|
||||
version: '1.1.1.1'
|
||||
},
|
||||
{
|
||||
name: 'p2',
|
||||
version: '1.1.1.2'
|
||||
}
|
||||
];
|
||||
let packages2 = [{
|
||||
name: 'p3',
|
||||
version: '1.1.1.3'
|
||||
}];
|
||||
testContext.provider.listPackages = (location) => {
|
||||
if (location === 'location1') {
|
||||
return Promise.resolve(packages1);
|
||||
} else {
|
||||
return Promise.resolve(packages2);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
let providers = new Map<string, IPackageManageProvider>();
|
||||
providers.set(testContext.provider.providerId, createProvider(testContext));
|
||||
|
||||
let model = new ManagePackagesDialogModel(jupyterServerInstallation, providers, undefined);
|
||||
|
||||
await model.init();
|
||||
model.changeProvider('providerId1');
|
||||
model.changeLocation('location2');
|
||||
|
||||
await should(model.listPackages()).resolvedWith(packages2);
|
||||
});
|
||||
|
||||
function createContext(): TestContext {
|
||||
@@ -327,7 +355,7 @@ describe('Manage Packages', () => {
|
||||
packageType: 'package-type'
|
||||
},
|
||||
canUseProvider: () => { return Promise.resolve(true); },
|
||||
getLocationTitle: () => { return Promise.resolve('location-title'); },
|
||||
getLocations: () => { return Promise.resolve([{displayName: 'location-title', name: 'location'}]); },
|
||||
installPackages:() => { return Promise.resolve(); },
|
||||
uninstallPackages: (packages: IPackageDetails[]) => { return Promise.resolve(); },
|
||||
listPackages: () => { return Promise.resolve([]); },
|
||||
@@ -339,10 +367,10 @@ describe('Manage Packages', () => {
|
||||
function createProvider(testContext: TestContext): IPackageManageProvider {
|
||||
let mockProvider = TypeMoq.Mock.ofType(LocalPipPackageManageProvider);
|
||||
mockProvider.setup(x => x.canUseProvider()).returns(() => testContext.provider.canUseProvider());
|
||||
mockProvider.setup(x => x.getLocationTitle()).returns(() => testContext.provider.getLocationTitle());
|
||||
mockProvider.setup(x => x.installPackages(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((packages, useMinVersion) => testContext.provider.installPackages(packages, useMinVersion));
|
||||
mockProvider.setup(x => x.uninstallPackages(TypeMoq.It.isAny())).returns((packages) => testContext.provider.uninstallPackages(packages));
|
||||
mockProvider.setup(x => x.listPackages()).returns(() => testContext.provider.listPackages());
|
||||
mockProvider.setup(x => x.getLocations()).returns(() => testContext.provider.getLocations());
|
||||
mockProvider.setup(x => x.installPackages(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((packages, useMinVersion) => testContext.provider.installPackages(packages, useMinVersion));
|
||||
mockProvider.setup(x => x.uninstallPackages(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((packages) => testContext.provider.uninstallPackages(packages));
|
||||
mockProvider.setup(x => x.listPackages(TypeMoq.It.isAny())).returns(() => testContext.provider.listPackages());
|
||||
mockProvider.setup(x => x.getPackageOverview(TypeMoq.It.isAny())).returns((name) => testContext.provider.getPackageOverview(name));
|
||||
mockProvider.setup(x => x.packageTarget).returns(() => testContext.provider.packageTarget);
|
||||
mockProvider.setup(x => x.providerId).returns(() => testContext.provider.providerId);
|
||||
|
||||
Reference in New Issue
Block a user