Add more notebook extension tests (#11143)

* more tests

* More tests

* More tests

* Add prompt tests
This commit is contained in:
Chris LaFreniere
2020-06-30 11:01:51 -07:00
committed by GitHub
parent a32f42d475
commit a8a7559229
18 changed files with 295 additions and 101 deletions

View File

@@ -3,6 +3,7 @@
* 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 should from 'should';
import * as TypeMoq from 'typemoq';
@@ -12,28 +13,34 @@ import { AppContext } from '../../common/appContext';
import { JupyterController } from '../../jupyter/jupyterController';
import { LocalPipPackageManageProvider } from '../../jupyter/localPipPackageManageProvider';
import { MockExtensionContext } from '../common/stubs';
import { NotebookUtils } from '../../common/notebookUtils';
describe('JupyterController tests', function () {
describe('Jupyter Controller', function () {
let mockExtensionContext: vscode.ExtensionContext;
let appContext: AppContext;
let controller: JupyterController;
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
let connection: azdata.connection.ConnectionProfile;
this.beforeAll(() => {
mockExtensionContext = new MockExtensionContext();
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
appContext = new AppContext(mockExtensionContext, mockApiWrapper.object);
connection = new azdata.connection.ConnectionProfile();
});
this.beforeEach(() => {
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
mockApiWrapper.setup(x => x.getCurrentConnection()).returns(() => { return Promise.resolve(connection); });
appContext = new AppContext(mockExtensionContext, mockApiWrapper.object);
controller = new JupyterController(appContext);
});
it('should activate new JupyterController successfully', async () => {
should(controller.extensionContext).deepEqual(appContext.extensionContext, 'Extension context should be passed through');
should(controller.jupyterInstallation).equal(undefined, 'JupyterInstallation should be undefined before controller activation');
await should(controller.activate()).not.be.rejected();
// On activation, local pip and local conda package providers should exist
should(controller.packageManageProviders.size).equal(2, 'Local pip and conda package providers should be default providers');
should(controller.jupyterInstallation.extensionPath).equal(appContext.extensionContext.extensionPath, 'JupyterInstallation extension path should match appContext extension path');
});
it('should create new packageManageProvider successfully', async () => {
@@ -50,4 +57,43 @@ describe('JupyterController tests', function () {
should.throws(() => controller.registerPackageManager('provider1', mockProvider.object));
should(controller.packageManageProviders.size).equal(1, 'Package manage providers should still equal 1');
});
it('should should get defaultConnection() successfully', async () => {
let defaultConnection = await controller.getDefaultConnection();
should(defaultConnection).deepEqual(connection, 'getDefaultConnection() did not return expected result');
});
it('should show error message for doManagePackages before activation', async () => {
await controller.doManagePackages();
mockApiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
});
it('should not show error message for doManagePackages after activation', async () => {
await controller.activate();
await controller.doManagePackages();
mockApiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
});
it('Returns expected values from notebook provider', async () => {
await controller.activate();
should(controller.notebookProvider.standardKernels).deepEqual([], 'Notebook provider standard kernels should return empty array');
should(controller.notebookProvider.providerId).equal('jupyter', 'Notebook provider should be jupyter');
should(controller.notebookProvider.getNotebookManager(undefined)).be.rejected();
should(controller.notebookProvider.notebookManagerCount).equal(0);
controller.notebookProvider.handleNotebookClosed(undefined);
});
it('Returns notebook manager for real notebook editor', async () => {
await controller.activate();
let notebookUtils = new NotebookUtils(mockApiWrapper.object);
const notebookEditor = await notebookUtils.newNotebook(undefined);
let notebookManager = await controller.notebookProvider.getNotebookManager(notebookEditor.document.uri);
should(controller.notebookProvider.notebookManagerCount).equal(1);
// Session manager should not be immediately ready
should(notebookManager.sessionManager.isReady).equal(false);
// Session manager should not immediately have specs
should(notebookManager.sessionManager.specs).equal(undefined);
controller.notebookProvider.handleNotebookClosed(notebookEditor.document.uri);
});
});