Run with Parameters learn more link to use correct format and kernels (#15547)

* indicate to users correct format and kernels

* add test for unsupported kernel

* replace with enum
This commit is contained in:
Vasu Bhog
2021-05-25 17:39:19 -07:00
committed by GitHub
parent 399406b732
commit 730367494b
5 changed files with 99 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ 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, KernelsDropdown, msgChanging, NewNotebookAction, noKernelName, noParameterCell, noParametersInCell, RunAllCellsAction, RunParametersAction, TrustedAction } from 'sql/workbench/contrib/notebook/browser/notebookActions';
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 { NotebookEditorStub } from 'sql/workbench/contrib/notebook/test/testCommon';
import { ICellModel, INotebookModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
@@ -251,7 +251,7 @@ suite('Notebook Actions', function (): void {
assert.strictEqual(actualCmdId, NewNotebookAction.INTERNAL_NEW_NOTEBOOK_CMD_ID);
});
test('Run with Parameters Action', async function (): Promise<void> {
test('Should Run with Parameters Action', async function (): Promise<void> {
const testContents: azdata.nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Code,
@@ -273,8 +273,10 @@ suite('Notebook Actions', function (): void {
let mockNotification = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService);
mockNotification.setup(n => n.notify(TypeMoq.It.isAny()));
let quickInputService = new MockQuickInputService;
let mockNotebookModel = new NotebookModelStub(undefined, undefined, testContents);
let testLanguageInfo: azdata.nb.ILanguageInfo = {
name: 'python',
};
let mockNotebookModel = new NotebookModelStub(testLanguageInfo, undefined, testContents);
let action = new RunParametersAction('TestId', true, testUri, quickInputService, mockNotebookService.object, mockNotification.object);
const testCells = [<ICellModel>{
@@ -293,7 +295,7 @@ suite('Notebook Actions', function (): void {
assert.call(mockNotebookService.object.openNotebook(testUri, testShowOptions), 'Should Open Parameterized Notebook');
});
test('Run with Parameters Action with no parameter cell in notebook', async function (): Promise<void> {
test('Should inform user to add a parameter cell if Run with Parameters Action has no parameter cell', async function (): Promise<void> {
const testContents: azdata.nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Code,
@@ -320,8 +322,10 @@ suite('Notebook Actions', function (): void {
return undefined;
});
let quickInputService = new MockQuickInputService;
let mockNotebookModel = new NotebookModelStub(undefined, undefined, testContents);
let testLanguageInfo: azdata.nb.ILanguageInfo = {
name: 'python',
};
let mockNotebookModel = new NotebookModelStub(testLanguageInfo, undefined, testContents);
let action = new RunParametersAction('TestId', true, testUri, quickInputService, mockNotebookService.object, mockNotification.object);
mockNotebookEditor.setup(x => x.model).returns(() => mockNotebookModel);
@@ -332,7 +336,7 @@ suite('Notebook Actions', function (): void {
assert.strictEqual(actualMsg, expectedMsg);
});
test('Run with Parameters Action with empty string parameter cell in notebook', async function (): Promise<void> {
test('Should inform user to add parameters if Run with Parameters Action contains empty string parameter cell', async function (): Promise<void> {
const testContents: azdata.nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Code,
@@ -359,8 +363,10 @@ suite('Notebook Actions', function (): void {
return undefined;
});
let quickInputService = new MockQuickInputService;
let mockNotebookModel = new NotebookModelStub(undefined, undefined, testContents);
let testLanguageInfo: azdata.nb.ILanguageInfo = {
name: 'python',
};
let mockNotebookModel = new NotebookModelStub(testLanguageInfo, undefined, testContents);
let action = new RunParametersAction('TestId', true, testUri, quickInputService, mockNotebookService.object, mockNotification.object);
const testCells = [<ICellModel>{
isParameter: true,
@@ -375,7 +381,7 @@ suite('Notebook Actions', function (): void {
assert.strictEqual(actualMsg, expectedMsg);
});
test('Run with Parameters Action with empty array string parameter cell in notebook', async function (): Promise<void> {
test('Should inform user to add parameters if Run with Parameters Action contains empty array string parameter cell', async function (): Promise<void> {
const testContents: azdata.nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Code,
@@ -402,8 +408,10 @@ suite('Notebook Actions', function (): void {
return undefined;
});
let quickInputService = new MockQuickInputService;
let mockNotebookModel = new NotebookModelStub(undefined, undefined, testContents);
let testLanguageInfo: azdata.nb.ILanguageInfo = {
name: 'python',
};
let mockNotebookModel = new NotebookModelStub(testLanguageInfo, undefined, testContents);
let action = new RunParametersAction('TestId', true, testUri, quickInputService, mockNotebookService.object, mockNotification.object);
const testCells = [<ICellModel>{
@@ -419,7 +427,7 @@ suite('Notebook Actions', function (): void {
assert.strictEqual(actualMsg, expectedMsg);
});
test('Run with Parameters Action with empty parameter cell in notebook', async function (): Promise<void> {
test('Should inform user to add parameters if Run with Parameters Action contains empty parameter cell', async function (): Promise<void> {
const testContents: azdata.nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Code,
@@ -446,7 +454,10 @@ suite('Notebook Actions', function (): void {
return undefined;
});
let quickInputService = new MockQuickInputService;
let mockNotebookModel = new NotebookModelStub(undefined, undefined, testContents);
let testLanguageInfo: azdata.nb.ILanguageInfo = {
name: 'python',
};
let mockNotebookModel = new NotebookModelStub(testLanguageInfo, undefined, testContents);
let action = new RunParametersAction('TestId', true, testUri, quickInputService, mockNotebookService.object, mockNotification.object);
@@ -463,6 +474,51 @@ suite('Notebook Actions', function (): void {
assert.strictEqual(actualMsg, expectedMsg);
});
test('Should inform user kernel is not supported if Run with Parameters Action is run with unsupported kernels', async function (): Promise<void> {
// Kernels that are supported (Python, PySpark, PowerShell)
const testContents: azdata.nb.INotebookContents = {
cells: [{
cell_type: CellTypes.Code,
source: [],
metadata: { language: 'sql' },
execution_count: 1
}],
metadata: {
kernelspec: {
name: 'sql',
language: 'sql',
display_name: 'SQL'
}
},
nbformat: 4,
nbformat_minor: 5
};
let expectedMsg: string = kernelNotSupported;
let actualMsg: string;
let mockNotification = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService);
mockNotification.setup(n => n.notify(TypeMoq.It.isAny())).returns(notification => {
actualMsg = notification.message;
return undefined;
});
let quickInputService = new MockQuickInputService;
let testLanguageInfo: azdata.nb.ILanguageInfo = {
name: 'sql',
};
let mockNotebookModel = new NotebookModelStub(testLanguageInfo, undefined, testContents);
let action = new RunParametersAction('TestId', true, testUri, quickInputService, mockNotebookService.object, mockNotification.object);
mockNotebookEditor.setup(x => x.model).returns(() => mockNotebookModel);
// Run Parameters Action
await action.run(testUri);
assert.strictEqual(actualMsg, expectedMsg);
});
suite('Kernels dropdown', async () => {
let kernelsDropdown: KernelsDropdown;
let contextViewProvider: ContextViewProviderStub;