mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-28 07:40:30 -04:00
Added multiple location option to package management dialog (#9790)
* Added multiple location option to package management dialog
This commit is contained in:
@@ -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