Add Notebook Views dropdown (#16228)

This adds the entry point to NVs. It is currently hidden behind a feature flag, which can be enabled in the settings.
This commit is contained in:
Daniel Grajeda
2021-08-03 22:15:11 -06:00
committed by GitHub
parent da7585eb44
commit e2dd257fa9
13 changed files with 349 additions and 14 deletions

View File

@@ -7,15 +7,15 @@ import * as assert from 'assert';
import * as azdata from 'azdata';
import * as sinon from 'sinon';
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
import { AddCellAction, ClearAllOutputsAction, CollapseCellsAction, kernelNotSupported, KernelsDropdown, msgChanging, NewNotebookAction, noKernelName, noParameterCell, noParametersInCell, RunAllCellsAction, RunParametersAction, TrustedAction } from 'sql/workbench/contrib/notebook/browser/notebookActions';
import { ClientSessionStub, ContextViewProviderStub, NotebookComponentStub, NotebookModelStub, NotebookServiceStub } from 'sql/workbench/contrib/notebook/test/stubs';
import { AddCellAction, ClearAllOutputsAction, CollapseCellsAction, CreateNotebookViewAction, DashboardViewAction, kernelNotSupported, KernelsDropdown, msgChanging, NewNotebookAction, noKernelName, noParameterCell, noParametersInCell, NotebookViewAction, NotebookViewsActionProvider, RunAllCellsAction, RunParametersAction, TrustedAction } from 'sql/workbench/contrib/notebook/browser/notebookActions';
import { ClientSessionStub, ContextViewProviderStub, NotebookComponentStub, NotebookModelStub, NotebookServiceStub, NotebookViewsStub, NotebookViewStub } from 'sql/workbench/contrib/notebook/test/stubs';
import { NotebookEditorStub } from 'sql/workbench/contrib/notebook/test/testCommon';
import { ICellModel, INotebookModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
import { ICellModel, INotebookModel, ViewMode } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
import { IStandardKernelWithProvider } from 'sql/workbench/services/notebook/browser/models/notebookUtils';
import { INotebookEditor, INotebookService } from 'sql/workbench/services/notebook/browser/notebookService';
import { CellType, CellTypes } from 'sql/workbench/services/notebook/common/contracts';
import * as TypeMoq from 'typemoq';
import { Emitter } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
import { TestCommandService } from 'vs/editor/test/browser/editorTestServices';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationChangeEvent, IConfigurationOverrides, IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -26,6 +26,9 @@ import { workbenchInstantiationService } from 'vs/workbench/test/browser/workben
import { URI } from 'vs/base/common/uri';
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
import { MockQuickInputService } from 'sql/workbench/contrib/notebook/test/common/quickInputServiceMock';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { Separator } from 'vs/base/common/actions';
import { INotebookView, INotebookViews } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViews';
class TestClientSession extends ClientSessionStub {
private _errorState: boolean = false;
@@ -519,6 +522,50 @@ suite('Notebook Actions', function (): void {
assert.strictEqual(actualMsg, expectedMsg);
});
test('notebookViewsActionProvider', async () => {
const testGuid = '1';
const testName = 'Notebook-0';
const testNotebookModel: INotebookModel = <INotebookModel>{
viewMode: ViewMode.Notebook
};
const notebookEditor = new NotebookEditorStub({ model: testNotebookModel });
const mockNotification = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService);
const notebookViews = TypeMoq.Mock.ofType<INotebookViews>(NotebookViewsStub);
const notebookView = TypeMoq.Mock.ofType<INotebookView>(NotebookViewStub);
notebookView.setup(x => x.guid).returns(() => testGuid);
notebookView.setup(x => x.name).returns(() => testName);
const views: INotebookView[] = [notebookView.object];
notebookViews.setup(x => x.getViews()).returns(() => views);
notebookViews.setup(x => x.getActiveView()).returns(() => undefined);
const notebookViewAction = new NotebookViewAction('notebookView.backToNotebook', 'Editor', 'notebook-button', mockNotebookService.object);
const createNotebookViewAction = new CreateNotebookViewAction('notebookView.newView', 'Create New View', 'notebook-button notebook-button-newview', mockNotebookService.object);
const separator = new Separator();
// Create a mocked out instantiation service
const mockInstantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Strict);
mockInstantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(NotebookViewAction), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => notebookViewAction);
mockInstantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(CreateNotebookViewAction), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => createNotebookViewAction);
mockInstantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(Separator))).returns(() => separator);
const viewsContainer = document.createElement('li');
const viewsActionsProvider = new NotebookViewsActionProvider(viewsContainer, notebookViews.object, notebookEditor.modelReady, mockNotebookService.object, mockNotification.object, mockInstantiationService.object);
await Event.toPromise(viewsActionsProvider.onUpdated);
const actions = viewsActionsProvider.getActions();
// It includes all the options
assert.strictEqual(actions.filter(a => a instanceof DashboardViewAction).length, 1);
assert.strictEqual(actions.filter(a => a instanceof NotebookViewAction).length, 1);
assert.strictEqual(actions.filter(a => a instanceof CreateNotebookViewAction).length, 1);
});
suite('Kernels dropdown', async () => {
let kernelsDropdown: KernelsDropdown;
let contextViewProvider: ContextViewProviderStub;